Skip to content

Commit

Permalink
1. Format the code.
Browse files Browse the repository at this point in the history
2. Don't use variable filter name. Pass the ditor_name as the second parameter.
  • Loading branch information
anton-vlasenko committed Oct 12, 2021
1 parent 612d17b commit 75519d9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/editor-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function gutenberg_initialize_editor( $editor_name, $editor_script_handle, $sett
*
* @param Array $preload_data Array containing the preloaded data.
*/
$preload_data = apply_filters( "{$editor_name}_preload_data", $preload_data );
$preload_data = apply_filters( 'block_editor_preload_data', $preload_data, $editor_name );

wp_add_inline_script(
'wp-api-fetch',
Expand Down
21 changes: 12 additions & 9 deletions lib/navigation-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,20 @@ function gutenberg_navigation_editor_load_block_editor_scripts_and_styles( $is_b
* This function removes menu-related data from the "common" preloading middleware and calls
* createMenuPreloadingMiddleware middleware because we need to use custom preloading logic for menus.
*
* @param Array $preload_data Array containing the preloaded data.
* @param Array $preload_data Array containing the preloaded data.
* @param string $context Current editor name.
* @return array Filtered preload data.
*/
function gutenberg_navigation_editor_preload_menus( $preload_data ) {
function gutenberg_navigation_editor_preload_menus( $preload_data, $context ) {
if ( 'navigation_editor' !== $context ) {
return $preload_data;
}

$menus_data_path = gutenberg_navigation_get_menus_endpoint();
$menus_data = empty( $preload_data[ $menus_data_path ] ) ?
array()
:
array(
$menus_data_path => $preload_data[ $menus_data_path ],
);
$menus_data = array();
if ( ! empty( $preload_data[ $menus_data_path ] ) ) {
$menus_data = array( $menus_data_path => $preload_data[ $menus_data_path ] );
}

if ( ! $menus_data ) {
return $preload_data;
Expand All @@ -177,4 +180,4 @@ function gutenberg_navigation_editor_preload_menus( $preload_data ) {
return $preload_data;
}

add_filter( 'navigation_editor_preload_data', 'gutenberg_navigation_editor_preload_menus' );
add_filter( 'block_editor_preload_data', 'gutenberg_navigation_editor_preload_menus', 10, 2 );
2 changes: 1 addition & 1 deletion phpunit/navigation-page-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function test_gutenberg_navigation_editor_preload_menus_function_returns_
$menus_endpoint => ( 'some menus' ),
);

$result = gutenberg_navigation_editor_preload_menus( $preload_data );
$result = gutenberg_navigation_editor_preload_menus( $preload_data, 'navigation_editor' );
$this->assertArrayHasKey( '/__experimental/menu-locations', $result );
$this->assertArrayHasKey( 'OPTIONS', $result );
$this->assertArrayNotHasKey( $menus_endpoint, $result );
Expand Down

0 comments on commit 75519d9

Please sign in to comment.