Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update googlemap virtual field to support the new block editor #31

Open
bobbingwide opened this issue Apr 9, 2018 · 1 comment
Open
Assignees
Labels
enhancement Gutenberg Enhancement to support the new block editor Priority A High priority work

Comments

@bobbingwide
Copy link
Owner

The googlemap virtual field uses Google Maps JavaScript to display a Map.
It doesn't work in the Fields meta box displayed in the new block editor.

Expected output - Classic editor

When displayed using the Classic editor the Google Maps Map is correctly displayed

Actual output - Block editor

When the field is displayed in a meta box controlled by the new block editor the field is not displayed.
The following message appears in the console log

post.php?post=962&action=edit:505 Uncaught ReferenceError: google is not defined
    at initialize1 (post.php?post=962&action=edit:505)
initialize1 @ post.php?post=962&action=edit:505
load (async)
(anonymous) @ post.php?post=962&action=edit:505

Explanation

The bw_fields_get_google_map function uses the Google Maps logic developed for the [bw_show_googlemap] shortcode.

oik_require( "shortcodes/oik-googlemap.php" );
$google_map = bw_googlemap_v3( get_the_title( $ID )
							, $lat
							, $long
							, $post_code
							, "100%"
							, "400px"
							);

The block editor expands the content during REST API processing. This causes the logic to increment a counter which is used to determine whether or not the Google initialisation code is required.
We need to ensure that the meta box enqueues the script.

Proposed solution

Insert the following line between the oik_require and bw_googlemap_v3 calls.

bw_gmap_map( null );
@bobbingwide bobbingwide added enhancement Gutenberg Enhancement to support the new block editor Priority A High priority work labels Apr 9, 2018
@bobbingwide bobbingwide self-assigned this Apr 9, 2018
@bobbingwide
Copy link
Owner Author

With the fix applied, this is what the meta box should look like in the block editor.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Gutenberg Enhancement to support the new block editor Priority A High priority work
Projects
None yet
Development

No branches or pull requests

1 participant