Editor: Add Navigation Area infrastructure

Copies Navigation Area infrastrucutre from lib/navigation.php in Gutenberg. This
allows a Navigation block to be associated with a particular area which persists
when switching theme.

Props antonvlasenko, mamaduka, spacedmonkey.
See #54337.


git-svn-id: https://develop.svn.wordpress.org/trunk@52145 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Robert Anderson
2021-11-12 03:53:18 +00:00
parent ff04bb0017
commit 74df751e48
6 changed files with 293 additions and 7 deletions

View File

@@ -2447,3 +2447,63 @@ function the_block_editor_meta_box_post_form_hidden_fields( $post ) {
*/
do_action( 'block_editor_meta_box_hidden_fields', $post );
}
/**
* Disable block editor for wp_navigation type posts so they can be managed via the UI.
*
* @since 5.9.0
* @access private
*
* @param bool $value Whether the CPT supports block editor or not.
* @param string $post_type Post type.
*
* @return bool
*/
function _disable_block_editor_for_navigation_post_type( $value, $post_type ) {
if ( 'wp_navigation' === $post_type ) {
return false;
}
return $value;
}
/**
* This callback disables the content editor for wp_navigation type posts.
* Content editor cannot handle wp_navigation type posts correctly.
* We cannot disable the "editor" feature in the wp_navigation's CPT definition
* because it disables the ability to save navigation blocks via REST API.
*
* @since 5.9.0
* @access private
*
* @param WP_Post $post An instance of WP_Post class.
*/
function _disable_content_editor_for_navigation_post_type( $post ) {
$post_type = get_post_type( $post );
if ( 'wp_navigation' !== $post_type ) {
return;
}
remove_post_type_support( $post_type, 'editor' );
}
/**
* This callback enables content editor for wp_navigation type posts.
* We need to enable it back because we disable it to hide
* the content editor for wp_navigation type posts.
*
* @since 5.9.0
* @access private
*
* @see _disable_content_editor_for_navigation_post_type
*
* @param WP_Post $post An instance of WP_Post class.
*/
function _enable_content_editor_for_navigation_post_type( $post ) {
$post_type = get_post_type( $post );
if ( 'wp_navigation' !== $post_type ) {
return;
}
add_post_type_support( $post_type, 'editor' );
}

View File

@@ -59,7 +59,17 @@ $preload_paths = array(
'/wp/v2/global-styles/' . $active_global_styles_id . '?context=edit',
'/wp/v2/global-styles/' . $active_global_styles_id,
'/wp/v2/themes/' . $active_theme . '/global-styles',
'/wp/v2/block-navigation-areas?context=edit',
);
$areas = get_option( 'fse_navigation_areas', array() );
$active_areas = array_intersect_key( $areas, get_navigation_areas() );
foreach ( $active_areas as $post_id ) {
if ( $post_id ) {
$preload_paths[] = add_query_args( 'context', 'edit', rest_get_route_for_post( $post_id ) );
}
}
block_editor_rest_api_preload( $preload_paths, $block_editor_context );
$editor_settings = get_block_editor_settings(