From 565e773e3e6103ad9cb875d96a64b7ecfd692548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Thu, 18 Nov 2021 11:26:36 +0100 Subject: [PATCH 1/2] Rollback navigation areas --- lib/blocks.php | 2 - ...rest-block-navigation-areas-controller.php | 285 ------------------ lib/full-site-editing/edit-site-page.php | 35 +-- lib/load.php | 3 - lib/navigation.php | 158 ---------- lib/rest-api.php | 9 - packages/block-library/src/index.js | 2 - .../src/navigation-area/block.json | 23 -- .../block-library/src/navigation-area/edit.js | 105 ------- .../src/navigation-area/index.js | 26 -- .../src/navigation-area/index.php | 21 -- .../src/navigation-area/inner-blocks.js | 24 -- .../block-library/src/navigation-area/save.js | 8 - .../block-library/src/navigation/block.json | 1 - .../src/navigation/edit/index.js | 35 +-- .../block-library/src/navigation/index.php | 8 - packages/core-data/src/entities.js | 10 - .../blocks/core__navigation-area.html | 1 - .../blocks/core__navigation-area.json | 12 - .../blocks/core__navigation-area.parsed.json | 11 - .../core__navigation-area.serialized.html | 1 - 21 files changed, 21 insertions(+), 759 deletions(-) delete mode 100644 lib/class-wp-rest-block-navigation-areas-controller.php delete mode 100644 packages/block-library/src/navigation-area/block.json delete mode 100644 packages/block-library/src/navigation-area/edit.js delete mode 100644 packages/block-library/src/navigation-area/index.js delete mode 100644 packages/block-library/src/navigation-area/index.php delete mode 100644 packages/block-library/src/navigation-area/inner-blocks.js delete mode 100644 packages/block-library/src/navigation-area/save.js delete mode 100644 test/integration/fixtures/blocks/core__navigation-area.html delete mode 100644 test/integration/fixtures/blocks/core__navigation-area.json delete mode 100644 test/integration/fixtures/blocks/core__navigation-area.parsed.json delete mode 100644 test/integration/fixtures/blocks/core__navigation-area.serialized.html diff --git a/lib/blocks.php b/lib/blocks.php index 4fa8b5027b0a2b..fa1adfdf50edb3 100644 --- a/lib/blocks.php +++ b/lib/blocks.php @@ -33,7 +33,6 @@ function gutenberg_reregister_core_block_types() { 'media-text', 'missing', 'more', - 'navigation-area', 'navigation-link', 'navigation-submenu', 'nextpage', @@ -72,7 +71,6 @@ function gutenberg_reregister_core_block_types() { 'latest-posts.php' => 'core/latest-posts', 'loginout.php' => 'core/loginout', 'navigation.php' => 'core/navigation', - 'navigation-area.php' => 'core/navigation-area', 'navigation-link.php' => 'core/navigation-link', 'navigation-submenu.php' => 'core/navigation-submenu', 'page-list.php' => 'core/page-list', diff --git a/lib/class-wp-rest-block-navigation-areas-controller.php b/lib/class-wp-rest-block-navigation-areas-controller.php deleted file mode 100644 index 1a6603b6a937bf..00000000000000 --- a/lib/class-wp-rest-block-navigation-areas-controller.php +++ /dev/null @@ -1,285 +0,0 @@ -namespace = 'wp/v2'; - $this->rest_base = 'block-navigation-areas'; - } - - /** - * Registers the routes for the objects of the controller. - * - * @see register_rest_route() - */ - public function register_routes() { - register_rest_route( - $this->namespace, - '/' . $this->rest_base, - array( - array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_items' ), - 'permission_callback' => array( $this, 'get_items_permissions_check' ), - 'args' => $this->get_collection_params(), - ), - 'schema' => array( $this, 'get_public_item_schema' ), - 'allow_batch' => array( 'v1' => true ), - ) - ); - - register_rest_route( - $this->namespace, - '/' . $this->rest_base . '/(?P[\w-]+)', - array( - 'args' => array( - 'area' => array( - 'description' => __( 'An alphanumeric identifier for the navigation area.', 'gutenberg' ), - 'type' => 'string', - ), - ), - array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_item' ), - 'permission_callback' => array( $this, 'get_item_permissions_check' ), - 'args' => array( - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), - ), - ), - array( - 'methods' => WP_REST_Server::EDITABLE, - 'callback' => array( $this, 'update_item' ), - 'permission_callback' => array( $this, 'update_item_permissions_check' ), - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), - ), - 'schema' => array( $this, 'get_public_item_schema' ), - ) - ); - } - - /** - * Checks whether a given request has permission to read navigation areas. - * - * @param WP_REST_Request $request Full details about the request. - * - * @return WP_Error|bool True if the request has read access, WP_Error object otherwise. - */ - public function get_items_permissions_check( $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable - if ( ! current_user_can( 'edit_theme_options' ) ) { - return new WP_Error( - 'rest_cannot_view', - __( 'Sorry, you are not allowed to view navigation areas.', 'gutenberg' ), - array( 'status' => rest_authorization_required_code() ) - ); - } - - return true; - } - - /** - * Retrieves all navigation areas, depending on user context. - * - * @param WP_REST_Request $request Full details about the request. - * - * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure. - */ - public function get_items( $request ) { - $data = array(); - foreach ( gutenberg_get_navigation_areas() as $name => $description ) { - $area = $this->get_navigation_area_object( $name ); - $area = $this->prepare_item_for_response( $area, $request ); - $data[ $name ] = $this->prepare_response_for_collection( $area ); - } - return rest_ensure_response( $data ); - } - - /** - * Checks if a given request has access to read a navigation area. - * - * @param WP_REST_Request $request Full details about the request. - * - * @return WP_Error|bool True if the request has read access for the item, WP_Error object otherwise. - */ - public function get_item_permissions_check( $request ) { - if ( ! current_user_can( 'edit_theme_options' ) ) { - return new WP_Error( - 'rest_cannot_view', - __( 'Sorry, you are not allowed to view navigation areas.', 'gutenberg' ), - array( 'status' => rest_authorization_required_code() ) - ); - } - if ( ! array_key_exists( $request['area'], gutenberg_get_navigation_areas() ) ) { - return new WP_Error( 'rest_navigation_area_invalid', __( 'Invalid navigation area.', 'gutenberg' ), array( 'status' => 404 ) ); - } - - return true; - } - - /** - * Checks if a request has access to update the specified term. - * - * @param WP_REST_Request $request Full details about the request. - * - * @return bool|WP_Error True if the request has access to update the item, false or WP_Error object otherwise. - */ - public function update_item_permissions_check( $request ) { - return $this->get_item_permissions_check( $request ); - } - - /** - * Retrieves a specific navigation area. - * - * @param WP_REST_Request $request Full details about the request. - * - * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure. - */ - public function get_item( $request ) { - $name = $request['area']; - $area = $this->get_navigation_area_object( $name ); - $data = $this->prepare_item_for_response( $area, $request ); - - return rest_ensure_response( $data ); - } - - /** - * Updates a specific navigation area. - * - * @param WP_REST_Request $request Full details about the request. - * - * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure. - */ - public function update_item( $request ) { - $name = $request['area']; - - $mapping = gutenberg_get_navigation_areas_menus(); - $mapping[ $name ] = $request['navigation']; - update_option( 'wp_navigation_areas', $mapping ); - - $area = $this->get_navigation_area_object( $name ); - $data = $this->prepare_item_for_response( $area, $request ); - return rest_ensure_response( $data ); - } - - /** - * Converts navigation area name to a convenient object that this endpoint can reason about. - * - * @param string $name Navigation area name. - * @return stdClass An object representation of the navigation area. - */ - private function get_navigation_area_object( $name ) { - $available_areas = gutenberg_get_navigation_areas(); - $mapping = gutenberg_get_navigation_areas_menus(); - $area = new stdClass(); - $area->name = $name; - $area->navigation = ! empty( $mapping[ $name ] ) ? $mapping[ $name ] : null; - $area->description = $available_areas[ $name ]; - return $area; - } - - /** - * Prepares a navigation area object for serialization. - * - * @param stdClass $area Post status data. - * @param WP_REST_Request $request Full details about the request. - * - * @return WP_REST_Response Post status data. - */ - public function prepare_item_for_response( $area, $request ) { - $areas = gutenberg_get_navigation_areas(); - $navigation = ( isset( $areas[ $area->name ] ) ) ? $area->navigation : 0; - - $fields = $this->get_fields_for_response( $request ); - $data = array(); - - if ( rest_is_field_included( 'name', $fields ) ) { - $data['name'] = $area->name; - } - - if ( rest_is_field_included( 'description', $fields ) ) { - $data['description'] = $area->description; - } - - if ( rest_is_field_included( 'navigation', $fields ) ) { - $data['navigation'] = (int) $navigation; - } - - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; - $data = $this->add_additional_fields_to_object( $data, $request ); - $data = $this->filter_response_by_context( $data, $context ); - - $response = rest_ensure_response( $data ); - - /** - * Filters a navigation area returned from the REST API. - * - * Allows modification of the navigation area data right before it is - * returned. - * - * @param WP_REST_Response $response The response object. - * @param object $area The original status object. - * @param WP_REST_Request $request Request used to generate the response. - */ - return apply_filters( 'rest_prepare_navigation_area', $response, $area, $request ); - } - - /** - * Retrieves the navigation area's schema, conforming to JSON Schema. - * - * @return array Item schema data. - */ - public function get_item_schema() { - $schema = array( - '$schema' => 'http://json-schema.org/draft-04/schema#', - 'title' => 'navigation-area', - 'type' => 'object', - 'properties' => array( - 'name' => array( - 'description' => __( 'The name of the navigation area.', 'gutenberg' ), - 'type' => 'string', - 'context' => array( 'embed', 'view', 'edit' ), - 'readonly' => true, - ), - 'description' => array( - 'description' => __( 'The description of the navigation area.', 'gutenberg' ), - 'type' => 'string', - 'context' => array( 'embed', 'view', 'edit' ), - 'readonly' => true, - ), - 'navigation' => array( - 'description' => __( 'The ID of the assigned navigation.', 'gutenberg' ), - 'type' => 'integer', - 'context' => array( 'embed', 'view', 'edit' ), - 'readonly' => true, - ), - ), - ); - - return $this->add_additional_fields_schema( $schema ); - } - - /** - * Retrieves the query params for collections. - * - * @return array Collection parameters. - */ - public function get_collection_params() { - return array( - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), - ); - } - -} diff --git a/lib/full-site-editing/edit-site-page.php b/lib/full-site-editing/edit-site-page.php index eb1020fda98bbc..0b3b31391dd90a 100644 --- a/lib/full-site-editing/edit-site-page.php +++ b/lib/full-site-editing/edit-site-page.php @@ -115,25 +115,22 @@ static function( $classes ) { 'edit_site_editor', 'edit-site', array( - 'preload_paths' => array_merge( - gutenberg_get_navigation_areas_paths_to_preload(), - array( - array( '/wp/v2/media', 'OPTIONS' ), - '/', - '/wp/v2/types?context=edit', - '/wp/v2/taxonomies?context=edit', - '/wp/v2/pages?context=edit', - '/wp/v2/categories?context=edit', - '/wp/v2/posts?context=edit', - '/wp/v2/tags?context=edit', - '/wp/v2/templates?context=edit', - '/wp/v2/template-parts?context=edit', - '/wp/v2/settings', - '/wp/v2/themes?context=edit&status=active', - '/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', - ) + 'preload_paths' => array( + array( '/wp/v2/media', 'OPTIONS' ), + '/', + '/wp/v2/types?context=edit', + '/wp/v2/taxonomies?context=edit', + '/wp/v2/pages?context=edit', + '/wp/v2/categories?context=edit', + '/wp/v2/posts?context=edit', + '/wp/v2/tags?context=edit', + '/wp/v2/templates?context=edit', + '/wp/v2/template-parts?context=edit', + '/wp/v2/settings', + '/wp/v2/themes?context=edit&status=active', + '/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', ), 'initializer_name' => 'initialize', 'editor_settings' => $settings, diff --git a/lib/load.php b/lib/load.php index d2cb603bb3f4ce..9f57672de7f0a9 100644 --- a/lib/load.php +++ b/lib/load.php @@ -50,9 +50,6 @@ function gutenberg_is_experiment_enabled( $name ) { if ( ! class_exists( 'WP_REST_Menu_Items_Controller' ) ) { require_once __DIR__ . '/class-wp-rest-menu-items-controller.php'; } - if ( ! class_exists( 'WP_REST_Block_Navigation_Areas_Controller' ) ) { - require_once __DIR__ . '/class-wp-rest-block-navigation-areas-controller.php'; - } if ( ! class_exists( 'WP_REST_Menu_Locations_Controller' ) ) { require_once __DIR__ . '/class-wp-rest-menu-locations-controller.php'; } diff --git a/lib/navigation.php b/lib/navigation.php index 816e2582b88409..8413782681b01e 100644 --- a/lib/navigation.php +++ b/lib/navigation.php @@ -146,164 +146,6 @@ function gutenberg_rename_navigation_post_type_admin_menu_entry() { add_action( 'admin_menu', 'gutenberg_rename_navigation_post_type_admin_menu_entry' ); -/** - * Registers the navigation areas supported by the current theme. The expected - * shape of the argument is: - * array( - * 'primary' => 'Primary', - * 'secondary' => 'Secondary', - * 'tertiary' => 'Tertiary', - * ) - * - * @param array $new_areas Supported navigation areas. - */ -function gutenberg_register_navigation_areas( $new_areas ) { - global $gutenberg_navigation_areas; - $gutenberg_navigation_areas = $new_areas; -} - -// Register the default navigation areas. -gutenberg_register_navigation_areas( - array( - 'primary' => 'Primary', - 'secondary' => 'Secondary', - 'tertiary' => 'Tertiary', - ) -); - -/** - * Returns the available navigation areas. - * - * @return array Registered navigation areas. - */ -function gutenberg_get_navigation_areas() { - global $gutenberg_navigation_areas; - return $gutenberg_navigation_areas; -} - -/** - * Returns the API paths to preload to make the navigation area block load fast. - * - * @return array A list of paths. - */ -function gutenberg_get_navigation_areas_paths_to_preload() { - $areas = gutenberg_get_navigation_areas_menus(); - $active_areas = array_intersect_key( $areas, gutenberg_get_navigation_areas() ); - $paths = array( - '/wp/v2/block-navigation-areas?context=edit', - ); - foreach ( $active_areas as $post_id ) { - if ( 0 !== $post_id ) { - $paths[] = "/wp/v2/navigation/$post_id?context=edit"; - } - } - return $paths; -} - -/** - * Migrates classic menus to a block-based navigation post on theme switch. - * Assigns the created navigation post to the corresponding navigation area. - * - * @param string $new_name Name of the new theme. - * @param WP_Theme $new_theme New theme. - * @param WP_Theme $old_theme Old theme. - * @see switch_theme WordPress action. - */ -function gutenberg_migrate_menu_to_navigation_post( $new_name, $new_theme, $old_theme ) { - // Do nothing when switching to a theme that does not support site editor. - if ( ! gutenberg_experimental_is_site_editor_available() ) { - return; - } - - // get_nav_menu_locations() calls get_theme_mod() which depends on the stylesheet option. - // At the same time, switch_theme runs only after the stylesheet option was updated to $new_theme. - // To retrieve theme mods of the old theme, the getter is hooked to get_option( 'stylesheet' ) so that we - // get the old theme, which causes the get_nav_menu_locations to get the locations of the old theme. - $get_old_theme_stylesheet = function() use ( $old_theme ) { - return $old_theme->get_stylesheet(); - }; - add_filter( 'option_stylesheet', $get_old_theme_stylesheet ); - - $locations = get_nav_menu_locations(); - $area_mapping = gutenberg_get_navigation_areas_menus(); - - foreach ( $locations as $location_name => $menu_id ) { - // Get the menu from the location, skipping if there is no - // menu or there was an error. - $menu = wp_get_nav_menu_object( $menu_id ); - if ( ! $menu || is_wp_error( $menu ) ) { - continue; - } - - $menu_items = gutenberg_get_menu_items_at_location( $location_name ); - if ( empty( $menu_items ) ) { - continue; - } - - $post_name = 'classic_menu_' . $menu_id; - $post_status = 'publish'; - - // Get or create to avoid creating too many wp_navigation posts. - $query = new WP_Query; - $matching_posts = $query->query( - array( - 'name' => $post_name, - 'post_status' => $post_status, - 'post_type' => 'wp_navigation', - 'posts_per_page' => 1, - ) - ); - - if ( count( $matching_posts ) ) { - $navigation_post_id = $matching_posts[0]->ID; - } else { - $menu_items_by_parent_id = gutenberg_sort_menu_items_by_parent_id( $menu_items ); - $parsed_blocks = gutenberg_parse_blocks_from_menu_items( $menu_items_by_parent_id[0], $menu_items_by_parent_id ); - $post_data = array( - 'post_type' => 'wp_navigation', - 'post_title' => sprintf( - /* translators: %s: the name of the menu, e.g. "Main Menu". */ - __( 'Classic menu: %s', 'gutenberg' ), - $menu->name - ), - 'post_name' => $post_name, - 'post_content' => serialize_blocks( $parsed_blocks ), - 'post_status' => $post_status, - ); - $navigation_post_id = wp_insert_post( $post_data, true ); - // If wp_insert_post fails *at any time*, then bale out of the entire - // migration attempt returning the WP_Error object. - if ( is_wp_error( $navigation_post_id ) ) { - return $navigation_post_id; - } - } - - $area_mapping[ $location_name ] = $navigation_post_id; - } - remove_filter( 'option_stylesheet', $get_old_theme_stylesheet ); - - update_option( 'wp_navigation_areas', $area_mapping ); -} - -add_action( 'switch_theme', 'gutenberg_migrate_menu_to_navigation_post', 99, 3 ); - -/** - * Retrieves navigation areas. - * - * @return array Navigation areas. - */ -function gutenberg_get_navigation_areas_menus() { - $areas = get_option( 'wp_navigation_areas', array() ); - if ( ! $areas ) { - // Original key used `fse` prefix but Core options should use `wp`. - // We fallback to the legacy option to catch sites with values in the - // original location. - $legacy_option_key = 'fse_navigation_areas'; - $areas = get_option( $legacy_option_key, array() ); - } - return $areas; -} - // The functions below are copied over from packages/block-library/src/navigation/index.php // Let's figure out a better way of managing these global PHP dependencies. diff --git a/lib/rest-api.php b/lib/rest-api.php index 49f82e2eb4b0e1..845a92336f4ae4 100644 --- a/lib/rest-api.php +++ b/lib/rest-api.php @@ -40,15 +40,6 @@ function gutenberg_register_rest_menu_location() { } add_action( 'rest_api_init', 'gutenberg_register_rest_menu_location' ); -/** - * Registers the navigation areas REST API routes. - */ -function gutenberg_register_rest_navigation_areas() { - $navigation_areas = new WP_REST_Block_Navigation_Areas_Controller(); - $navigation_areas->register_routes(); -} -add_action( 'rest_api_init', 'gutenberg_register_rest_navigation_areas' ); - /** * Registers the customizer nonces REST API routes. */ diff --git a/packages/block-library/src/index.js b/packages/block-library/src/index.js index 8a99d23811ac06..9fa3974ee275cc 100644 --- a/packages/block-library/src/index.js +++ b/packages/block-library/src/index.js @@ -47,7 +47,6 @@ import * as mediaText from './media-text'; import * as missing from './missing'; import * as more from './more'; import * as navigation from './navigation'; -import * as navigationArea from './navigation-area'; import * as navigationLink from './navigation-link'; import * as navigationSubmenu from './navigation-submenu'; import * as nextpage from './nextpage'; @@ -154,7 +153,6 @@ export const __experimentalGetCoreBlocks = () => [ missing, more, navigation, - navigationArea, navigationLink, navigationSubmenu, nextpage, diff --git a/packages/block-library/src/navigation-area/block.json b/packages/block-library/src/navigation-area/block.json deleted file mode 100644 index ce80174a0941f7..00000000000000 --- a/packages/block-library/src/navigation-area/block.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "$schema": "https://schemas.wp.org/trunk/block.json", - "apiVersion": 2, - "name": "core/navigation-area", - "title": "Navigation Area", - "category": "theme", - "description": "Define a navigation area for your theme. The navigation block associated with this area will be automatically displayed.", - "keywords": [ "menu", "navigation", "links", "location" ], - "textdomain": "default", - "attributes": { - "area": { - "type": "string", - "default": "primary" - } - }, - "providesContext": { - "navigationArea": "area" - }, - "supports": { - "html": false, - "inserter": true - } -} diff --git a/packages/block-library/src/navigation-area/edit.js b/packages/block-library/src/navigation-area/edit.js deleted file mode 100644 index 97b65d2d1f8b2a..00000000000000 --- a/packages/block-library/src/navigation-area/edit.js +++ /dev/null @@ -1,105 +0,0 @@ -/** - * WordPress dependencies - */ -import { __, _x } from '@wordpress/i18n'; -import { store as coreStore } from '@wordpress/core-data'; -import { - MenuGroup, - MenuItemsChoice, - PanelBody, - SelectControl, - ToolbarDropdownMenu, - ToolbarGroup, -} from '@wordpress/components'; -import { useMemo } from '@wordpress/element'; -import { BlockControls, InspectorControls } from '@wordpress/block-editor'; -import { useSelect } from '@wordpress/data'; - -/** - * Internal dependencies - */ -import InnerBlocks from './inner-blocks'; -import PlaceholderPreview from '../navigation/edit/placeholder/placeholder-preview'; - -function NavigationAreaBlock( { attributes, setAttributes } ) { - const { area } = attributes; - - const { navigationAreas, hasResolvedNavigationAreas } = useSelect( - ( select ) => { - const { getEntityRecords, hasFinishedResolution } = select( - coreStore - ); - return { - navigationAreas: getEntityRecords( 'root', 'navigationArea' ), - hasResolvedNavigationAreas: hasFinishedResolution( - 'getEntityRecords', - [ 'root', 'navigationArea' ] - ), - }; - } - ); - const navigationMenuId = navigationAreas?.length - ? navigationAreas[ area ] - : undefined; - - const choices = useMemo( - () => - navigationAreas?.map( ( { name, description } ) => ( { - label: description, - value: name, - } ) ), - [ navigationAreas ] - ); - - return ( - <> - - - - { ( { onClose } ) => ( - - { - setAttributes( { area: selectedArea } ); - onClose(); - } } - choices={ choices } - /> - - ) } - - - - - - - setAttributes( { - area: value, - } ) - } - options={ choices } - /> - - - { ! hasResolvedNavigationAreas && } - { - // Render inner blocks only when navigationMenuId is known so - // that inner blocks template is correct from the start. - hasResolvedNavigationAreas && ( - - ) - } - - ); -} - -export default NavigationAreaBlock; diff --git a/packages/block-library/src/navigation-area/index.js b/packages/block-library/src/navigation-area/index.js deleted file mode 100644 index c848d3d7c06129..00000000000000 --- a/packages/block-library/src/navigation-area/index.js +++ /dev/null @@ -1,26 +0,0 @@ -/** - * WordPress dependencies - */ -import { symbolFilled as icon } from '@wordpress/icons'; - -/** - * Internal dependencies - */ -import edit from './edit'; -import metadata from './block.json'; -import save from './save'; - -const { name } = metadata; - -export { metadata, name }; - -export const settings = { - icon, - example: { - attributes: { - area: 'primary', - }, - }, - edit, - save, -}; diff --git a/packages/block-library/src/navigation-area/index.php b/packages/block-library/src/navigation-area/index.php deleted file mode 100644 index e8fdc84bbef294..00000000000000 --- a/packages/block-library/src/navigation-area/index.php +++ /dev/null @@ -1,21 +0,0 @@ - array( - 'navigationArea' => 'area', - ), - ) - ); -} -add_action( 'init', 'register_block_core_navigation_area' ); diff --git a/packages/block-library/src/navigation-area/inner-blocks.js b/packages/block-library/src/navigation-area/inner-blocks.js deleted file mode 100644 index d123b93f9ed39d..00000000000000 --- a/packages/block-library/src/navigation-area/inner-blocks.js +++ /dev/null @@ -1,24 +0,0 @@ -/** - * WordPress dependencies - */ -import { useMemo } from '@wordpress/element'; -import { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor'; - -const ALLOWED_BLOCKS = [ 'core/navigation' ]; - -export default function NavigationAreaInnerBlocks( { navigationMenuId } ) { - const template = useMemo( - () => [ [ 'core/navigation', { navigationMenuId } ] ], - [ navigationMenuId ] - ); - - const blockProps = useBlockProps(); - const innerBlocksProps = useInnerBlocksProps( blockProps, { - orientation: 'horizontal', - renderAppender: false, - template, - templateLock: 'all', - allowedBlocks: ALLOWED_BLOCKS, - } ); - return
; -} diff --git a/packages/block-library/src/navigation-area/save.js b/packages/block-library/src/navigation-area/save.js deleted file mode 100644 index 17571d8f30d2de..00000000000000 --- a/packages/block-library/src/navigation-area/save.js +++ /dev/null @@ -1,8 +0,0 @@ -/** - * WordPress dependencies - */ -import { InnerBlocks } from '@wordpress/block-editor'; - -export default function save() { - return ; -} diff --git a/packages/block-library/src/navigation/block.json b/packages/block-library/src/navigation/block.json index 003da92bc49765..54e7f90545df03 100644 --- a/packages/block-library/src/navigation/block.json +++ b/packages/block-library/src/navigation/block.json @@ -57,7 +57,6 @@ "type": "string" } }, - "usesContext": [ "navigationArea" ], "providesContext": { "textColor": "textColor", "customTextColor": "customTextColor", diff --git a/packages/block-library/src/navigation/edit/index.js b/packages/block-library/src/navigation/edit/index.js index be6f58e1ea875e..44335b18369b1e 100644 --- a/packages/block-library/src/navigation/edit/index.js +++ b/packages/block-library/src/navigation/edit/index.js @@ -93,7 +93,6 @@ function Navigation( { setOverlayBackgroundColor, overlayTextColor, setOverlayTextColor, - context: { navigationArea }, // These props are used by the navigation editor to override specific // navigation block settings. @@ -109,28 +108,10 @@ function Navigation( { layout: { justifyContent, orientation = 'horizontal' } = {}, } = attributes; - const [ areaMenu, setAreaMenu ] = useEntityProp( - 'root', - 'navigationArea', - 'navigation', - navigationArea - ); - - const navigationAreaMenu = areaMenu === 0 ? undefined : areaMenu; - - const navigationMenuId = navigationArea - ? navigationAreaMenu - : attributes.navigationMenuId; - - const setNavigationMenuId = useCallback( - ( postId ) => { - setAttributes( { navigationMenuId: postId } ); - if ( navigationArea ) { - setAreaMenu( postId ); - } - }, - [ navigationArea ] - ); + const navigationMenuId = attributes.navigationMenuId; + const setNavigationMenuId = useCallback( ( postId ) => { + setAttributes( { navigationMenuId: postId } ); + }, [] ); const [ hasAlreadyRendered, RecursionProvider ] = useNoRecursiveRenders( `navigationMenu/${ navigationMenuId }` @@ -160,7 +141,7 @@ function Navigation( { setHasSavedUnsavedInnerBlocks, ] = useState( false ); - const isWithinUnassignedArea = navigationArea && ! navigationMenuId; + const isWithinUnassignedArea = ! navigationMenuId; const [ isPlaceholderShown, setIsPlaceholderShown ] = useState( ! hasExistingNavItems || isWithinUnassignedArea @@ -356,9 +337,6 @@ function Navigation( { onClose(); } } onCreateNew={ () => { - if ( navigationArea ) { - setAreaMenu( 0 ); - } setAttributes( { navigationMenuId: undefined, } ); @@ -482,9 +460,6 @@ function Navigation( { { replaceInnerBlocks( clientId, [] ); - if ( navigationArea ) { - setAreaMenu( 0 ); - } setAttributes( { navigationMenuId: undefined, } ); diff --git a/packages/block-library/src/navigation/index.php b/packages/block-library/src/navigation/index.php index e3848190c6e786..71c999e4a53a69 100644 --- a/packages/block-library/src/navigation/index.php +++ b/packages/block-library/src/navigation/index.php @@ -183,14 +183,6 @@ function render_block_core_navigation( $attributes, $content, $block ) { $inner_blocks = new WP_Block_List( $parsed_blocks, $attributes ); } - if ( ! empty( $block->context['navigationArea'] ) ) { - $area = $block->context['navigationArea']; - $mapping = get_option( 'wp_navigation_areas', array() ); - if ( ! empty( $mapping[ $area ] ) ) { - $attributes['navigationMenuId'] = $mapping[ $area ]; - } - } - // Load inner blocks from the navigation post. if ( array_key_exists( 'navigationMenuId', $attributes ) ) { $navigation_post = get_post( $attributes['navigationMenuId'] ); diff --git a/packages/core-data/src/entities.js b/packages/core-data/src/entities.js index 87ae920dba6b6b..adbdd8157d65cf 100644 --- a/packages/core-data/src/entities.js +++ b/packages/core-data/src/entities.js @@ -127,16 +127,6 @@ export const defaultEntities = [ label: __( 'Menu Location' ), key: 'name', }, - { - name: 'navigationArea', - kind: 'root', - baseURL: '/wp/v2/block-navigation-areas', - baseURLParams: { context: 'edit' }, - plural: 'navigationAreas', - label: __( 'Navigation Area' ), - key: 'name', - getTitle: ( record ) => record?.description, - }, { label: __( 'Global Styles' ), name: 'globalStyles', diff --git a/test/integration/fixtures/blocks/core__navigation-area.html b/test/integration/fixtures/blocks/core__navigation-area.html deleted file mode 100644 index 34145ae3ebe319..00000000000000 --- a/test/integration/fixtures/blocks/core__navigation-area.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/integration/fixtures/blocks/core__navigation-area.json b/test/integration/fixtures/blocks/core__navigation-area.json deleted file mode 100644 index 85c39031aff48d..00000000000000 --- a/test/integration/fixtures/blocks/core__navigation-area.json +++ /dev/null @@ -1,12 +0,0 @@ -[ - { - "clientId": "_clientId_0", - "name": "core/navigation-area", - "isValid": true, - "attributes": { - "area": "secondary" - }, - "innerBlocks": [], - "originalContent": "" - } -] diff --git a/test/integration/fixtures/blocks/core__navigation-area.parsed.json b/test/integration/fixtures/blocks/core__navigation-area.parsed.json deleted file mode 100644 index a5882f26b157ba..00000000000000 --- a/test/integration/fixtures/blocks/core__navigation-area.parsed.json +++ /dev/null @@ -1,11 +0,0 @@ -[ - { - "blockName": "core/navigation-area", - "attrs": { - "area": "secondary" - }, - "innerBlocks": [], - "innerHTML": "", - "innerContent": [] - } -] diff --git a/test/integration/fixtures/blocks/core__navigation-area.serialized.html b/test/integration/fixtures/blocks/core__navigation-area.serialized.html deleted file mode 100644 index 34145ae3ebe319..00000000000000 --- a/test/integration/fixtures/blocks/core__navigation-area.serialized.html +++ /dev/null @@ -1 +0,0 @@ - From 8e2939b09730f569c724bf0ae31633f4281ee778 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Thu, 18 Nov 2021 11:50:32 +0100 Subject: [PATCH 2/2] Remove unused import --- packages/block-library/src/navigation/edit/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/navigation/edit/index.js b/packages/block-library/src/navigation/edit/index.js index 44335b18369b1e..040f8e5761b6c2 100644 --- a/packages/block-library/src/navigation/edit/index.js +++ b/packages/block-library/src/navigation/edit/index.js @@ -25,7 +25,7 @@ import { getColorClassName, Warning, } from '@wordpress/block-editor'; -import { EntityProvider, useEntityProp } from '@wordpress/core-data'; +import { EntityProvider } from '@wordpress/core-data'; import { useDispatch, useSelect } from '@wordpress/data'; import { PanelBody,