From c2025aff1b3b4f38ea99197a68e3fb6addba0d26 Mon Sep 17 00:00:00 2001 From: Aki Hamano Date: Sun, 5 Oct 2025 17:50:08 +0900 Subject: [PATCH] Revert "Use block bindings to dynamically fetch the URL for Navigation Link in the editor and on front end (#71630)" This reverts commit 2d6e4cc6b161ebf553287fb2b4b1432d199fc47f. --- backport-changelog/6.9/10141.md | 3 - lib/compat/wordpress-6.9/block-bindings.php | 20 +- .../wordpress-6.9/entity-block-bindings.php | 106 ------- lib/load.php | 1 - .../src/components/link-control/index.js | 125 ++------- .../components/link-control/search-input.js | 4 +- .../src/components/link-control/style.scss | 9 - .../src/components/link-control/test/index.js | 258 ------------------ .../src/components/url-input/index.js | 12 +- .../block-library/src/navigation-link/edit.js | 35 +-- .../src/navigation-link/link-ui/index.js | 8 +- .../src/navigation-link/shared/controls.js | 106 +------ .../src/navigation-link/shared/index.js | 1 - .../navigation-link/shared/test/controls.js | 117 -------- .../shared/test/use-entity-binding.js | 133 --------- .../shared/use-entity-binding.js | 49 ---- .../src/navigation-submenu/edit.js | 21 +- packages/editor/src/bindings/api.js | 2 - packages/editor/src/bindings/entity.js | 89 ------ .../specs/editor/blocks/navigation.spec.js | 166 ----------- 20 files changed, 47 insertions(+), 1218 deletions(-) delete mode 100644 backport-changelog/6.9/10141.md delete mode 100644 lib/compat/wordpress-6.9/entity-block-bindings.php delete mode 100644 packages/block-library/src/navigation-link/shared/test/use-entity-binding.js delete mode 100644 packages/block-library/src/navigation-link/shared/use-entity-binding.js delete mode 100644 packages/editor/src/bindings/entity.js diff --git a/backport-changelog/6.9/10141.md b/backport-changelog/6.9/10141.md deleted file mode 100644 index 6c1104eedaa843..00000000000000 --- a/backport-changelog/6.9/10141.md +++ /dev/null @@ -1,3 +0,0 @@ -https://github.com/WordPress/wordpress-develop/pull/10141 - -* https://github.com/WordPress/gutenberg/pull/71630 diff --git a/lib/compat/wordpress-6.9/block-bindings.php b/lib/compat/wordpress-6.9/block-bindings.php index 3a4ae22939d946..ff78a2cac40bc8 100644 --- a/lib/compat/wordpress-6.9/block-bindings.php +++ b/lib/compat/wordpress-6.9/block-bindings.php @@ -112,12 +112,10 @@ function gutenberg_block_bindings_render_block( $block_content, $block, $instanc function gutenberg_get_block_bindings_supported_attributes( $block_type ) { // List of block attributes supported by Block Bindings in WP 6.8. $block_bindings_supported_attributes_6_8 = array( - 'core/paragraph' => array( 'content' ), - 'core/heading' => array( 'content' ), - 'core/image' => array( 'id', 'url', 'title', 'alt' ), - 'core/button' => array( 'url', 'text', 'linkTarget', 'rel' ), - 'core/navigation-link' => array( 'url' ), - 'core/navigation-submenu' => array( 'url' ), + 'core/paragraph' => array( 'content' ), + 'core/heading' => array( 'content' ), + 'core/image' => array( 'id', 'url', 'title', 'alt' ), + 'core/button' => array( 'url', 'text', 'linkTarget', 'rel' ), ); $supported_block_attributes = @@ -203,12 +201,10 @@ function gutenberg_process_block_bindings( $instance ) { // List of block attributes supported by Block Bindings in WP 6.8. $block_bindings_supported_attributes_6_8 = array( - 'core/paragraph' => array( 'content' ), - 'core/heading' => array( 'content' ), - 'core/image' => array( 'id', 'url', 'title', 'alt' ), - 'core/button' => array( 'url', 'text', 'linkTarget', 'rel' ), - 'core/navigation-link' => array( 'url' ), - 'core/navigation-submenu' => array( 'url' ), + 'core/paragraph' => array( 'content' ), + 'core/heading' => array( 'content' ), + 'core/image' => array( 'id', 'url', 'title', 'alt' ), + 'core/button' => array( 'url', 'text', 'linkTarget', 'rel' ), ); $supported_block_attributes = gutenberg_get_block_bindings_supported_attributes( $block_type ); diff --git a/lib/compat/wordpress-6.9/entity-block-bindings.php b/lib/compat/wordpress-6.9/entity-block-bindings.php deleted file mode 100644 index bdd949976e7a88..00000000000000 --- a/lib/compat/wordpress-6.9/entity-block-bindings.php +++ /dev/null @@ -1,106 +0,0 @@ - "url" ). - * @param WP_Block $block_instance The block instance. - * @return mixed The value computed for the source. - */ -function gutenberg_block_bindings_entity_get_value( array $source_args, $block_instance ) { - // Get the key from source args - no key means invalid binding - if ( empty( $source_args['key'] ) ) { - return null; - } - - $key = $source_args['key']; - - // For now, only support 'url' key - if ( 'url' !== $key ) { - return null; - } - - // Read entity data from block attributes - $entity_id = $block_instance->attributes['id'] ?? null; - $type = $block_instance->attributes['type'] ?? ''; - $kind = $block_instance->attributes['kind'] ?? ''; - - if ( empty( $entity_id ) ) { - return null; - } - - try { - // Handle post types - if ( 'post-type' === $kind ) { - $post = get_post( $entity_id ); - if ( ! $post ) { - return null; - } - - $permalink = get_permalink( $entity_id ); - if ( is_wp_error( $permalink ) ) { - return null; - } - - return esc_url( $permalink ); - } - - // Handle taxonomies - if ( 'taxonomy' === $kind ) { - // Convert 'tag' back to 'post_tag' for API calls - // See update-attributes.js line 166 for the reverse conversion - $taxonomy_slug = ( 'tag' === $type ) ? 'post_tag' : $type; - $term = get_term( $entity_id, $taxonomy_slug ); - - if ( is_wp_error( $term ) || ! $term ) { - return null; - } - - $term_link = get_term_link( $term ); - if ( is_wp_error( $term_link ) ) { - return null; - } - - return esc_url( $term_link ); - } - - // Unknown entity kind - return null; - } catch ( Exception $e ) { - return null; - } -} - -/** - * Registers Entity source in the block bindings registry. - * - * @since 6.9.0 - * @access private - */ -function gutenberg_register_block_bindings_entity_source() { - if ( get_block_bindings_source( 'core/entity' ) ) { - // The source is already registered. - return; - } - - register_block_bindings_source( - 'core/entity', - array( - 'label' => _x( 'Entity', 'block bindings source' ), - 'get_value_callback' => 'gutenberg_block_bindings_entity_get_value', - ) - ); -} - -add_action( 'init', 'gutenberg_register_block_bindings_entity_source' ); diff --git a/lib/load.php b/lib/load.php index 83bdd73d730a83..44a459d48cedcf 100644 --- a/lib/load.php +++ b/lib/load.php @@ -45,7 +45,6 @@ function gutenberg_is_experiment_enabled( $name ) { require __DIR__ . '/compat/wordpress-6.9/block-bindings.php'; require __DIR__ . '/compat/wordpress-6.9/post-data-block-bindings.php'; require __DIR__ . '/compat/wordpress-6.9/term-data-block-bindings.php'; - require __DIR__ . '/compat/wordpress-6.9/entity-block-bindings.php'; require __DIR__ . '/compat/wordpress-6.9/rest-api.php'; require __DIR__ . '/compat/wordpress-6.9/class-gutenberg-hierarchical-sort.php'; diff --git a/packages/block-editor/src/components/link-control/index.js b/packages/block-editor/src/components/link-control/index.js index da485a8fdd2151..3d4656a59b8be7 100644 --- a/packages/block-editor/src/components/link-control/index.js +++ b/packages/block-editor/src/components/link-control/index.js @@ -14,15 +14,14 @@ import { __experimentalHStack as HStack, __experimentalInputControlSuffixWrapper as InputControlSuffixWrapper, } from '@wordpress/components'; -import { __, sprintf } from '@wordpress/i18n'; +import { __ } from '@wordpress/i18n'; import { useRef, useState, useEffect } from '@wordpress/element'; -import { useInstanceId } from '@wordpress/compose'; import { focus } from '@wordpress/dom'; import { ENTER } from '@wordpress/keycodes'; import { isShallowEqualObjects } from '@wordpress/is-shallow-equal'; import { useSelect, useDispatch } from '@wordpress/data'; import { store as preferencesStore } from '@wordpress/preferences'; -import { keyboardReturn, linkOff } from '@wordpress/icons'; +import { keyboardReturn } from '@wordpress/icons'; /** * Internal dependencies @@ -109,7 +108,6 @@ import deprecated from '@wordpress/deprecated'; * @property {boolean=} hasTextControl Whether to add a text field to the UI to update the value.title. * @property {string|Function|undefined} createSuggestionButtonText The text to use in the button that calls createSuggestion. * @property {Function} renderControlBottom Optional controls to be rendered at the bottom of the component. - * @property {boolean=} handleEntities Whether to handle entity links (links with ID). When true and a link has an ID, the input will be disabled and show an unlink button. */ const noop = () => {}; @@ -144,7 +142,6 @@ function LinkControl( { hasRichPreviews = false, hasTextControl = false, renderControlBottom = null, - handleEntities = false, } ) { if ( withCreateSuggestion === undefined && createSuggestion ) { withCreateSuggestion = true; @@ -188,7 +185,6 @@ function LinkControl( { const isMountingRef = useRef( true ); const wrapperNode = useRef(); const textInputRef = useRef(); - const searchInputRef = useRef(); const isEndingEditWithFocusRef = useRef( false ); const settingsKeys = settings.map( ( { id } ) => id ); @@ -201,13 +197,6 @@ function LinkControl( { createSetInternalSettingValueHandler, ] = useInternalValue( value ); - // Compute isEntity internally based on handleEntities prop and presence of ID - const isEntity = handleEntities && !! internalControlValue?.id; - - // Generate help text ID for accessibility association - const baseId = useInstanceId( LinkControl, 'link-control' ); - const helpTextId = isEntity ? `${ baseId }__help` : null; - const valueHasChanges = value && ! isShallowEqualObjects( internalControlValue, value ); @@ -347,29 +336,6 @@ function LinkControl( { onCancel?.(); }; - const [ shouldFocusSearchInput, setShouldFocusSearchInput ] = - useState( false ); - - const handleUnlink = () => { - // Clear the internal state to remove the ID and re-enable the field - // The user will need to submit to commit this change - const { id, ...restValue } = internalControlValue; - setInternalControlValue( { ...restValue, url: '' } ); - - // Request focus after the component re-renders with the cleared state - // We can't focus immediately because the input might still be disabled - setShouldFocusSearchInput( true ); - }; - - // Focus the search input when requested, once the component has re-rendered - // This ensures the input is enabled and ready to receive focus - useEffect( () => { - if ( shouldFocusSearchInput ) { - searchInputRef.current?.focus(); - setShouldFocusSearchInput( false ); - } - }, [ shouldFocusSearchInput ] ); - const currentUrlInputValue = propInputValue || internalControlValue?.url || ''; @@ -423,7 +389,6 @@ function LinkControl( { /> ) } + showActions ? undefined : ( + +