diff --git a/lib/compat/wordpress-6.5/block-bindings/sources/pattern.php b/lib/compat/wordpress-6.5/block-bindings/sources/pattern.php index 65ddb7278e7035..9540e329596c99 100644 --- a/lib/compat/wordpress-6.5/block-bindings/sources/pattern.php +++ b/lib/compat/wordpress-6.5/block-bindings/sources/pattern.php @@ -28,7 +28,7 @@ } }; wp_block_bindings_register_source( - 'pattern_attributes', + 'core/pattern-attributes', array( 'label' => __( 'Pattern Attributes' ), 'apply' => $pattern_source_callback, diff --git a/lib/compat/wordpress-6.5/block-bindings/sources/post-meta.php b/lib/compat/wordpress-6.5/block-bindings/sources/post-meta.php index e52b4f289ccdd3..6d8951b5660ab1 100644 --- a/lib/compat/wordpress-6.5/block-bindings/sources/post-meta.php +++ b/lib/compat/wordpress-6.5/block-bindings/sources/post-meta.php @@ -6,6 +6,10 @@ */ if ( function_exists( 'wp_block_bindings_register_source' ) ) { $post_meta_source_callback = function ( $source_attrs ) { + if ( ! isset( $source_attrs['key'] ) ) { + return null; + } + // Use the postId attribute if available if ( isset( $source_attrs['postId'] ) ) { $post_id = $source_attrs['postId']; @@ -14,10 +18,10 @@ $post_id = get_the_ID(); } - return get_post_meta( $post_id, $source_attrs['value'], true ); + return get_post_meta( $post_id, $source_attrs['key'], true ); }; wp_block_bindings_register_source( - 'post_meta', + 'core/post-meta', array( 'label' => __( 'Post Meta' ), 'apply' => $post_meta_source_callback, diff --git a/lib/compat/wordpress-6.5/blocks.php b/lib/compat/wordpress-6.5/blocks.php index e1b91364fe22e5..7888973397f6cb 100644 --- a/lib/compat/wordpress-6.5/blocks.php +++ b/lib/compat/wordpress-6.5/blocks.php @@ -76,16 +76,12 @@ function gutenberg_process_block_bindings( $block_content, $block, $block_instan * * "bindings": { * "title": { - * "source": { - * "name": "post_meta", - * "attributes": { "value": "text_custom_field" } - * } + * "source": "core/post-meta", + * "args": { "key": "text_custom_field" } * }, * "url": { - * "source": { - * "name": "post_meta", - * "attributes": { "value": "text_custom_field" } - * } + * "source": "core/post-meta", + * "args": { "key": "url_custom_field" } * } * } */ @@ -99,16 +95,16 @@ function gutenberg_process_block_bindings( $block_content, $block, $block_instan continue; } // If no source is provided, or that source is not registered, process next attribute. - if ( ! isset( $binding_source['source'] ) || ! isset( $binding_source['source']['name'] ) || ! isset( $block_bindings_sources[ $binding_source['source']['name'] ] ) ) { + if ( ! isset( $binding_source['source'] ) || ! is_string( $binding_source['source'] ) || ! isset( $block_bindings_sources[ $binding_source['source'] ] ) ) { continue; } - $source_callback = $block_bindings_sources[ $binding_source['source']['name'] ]['apply']; + $source_callback = $block_bindings_sources[ $binding_source['source'] ]['apply']; // Get the value based on the source. - if ( ! isset( $binding_source['source']['attributes'] ) ) { + if ( ! isset( $binding_source['args'] ) ) { $source_args = array(); } else { - $source_args = $binding_source['source']['attributes']; + $source_args = $binding_source['args']; } $source_value = $source_callback( $source_args, $block_instance, $binding_attribute ); // If the value is null, process next attribute. diff --git a/packages/block-editor/src/components/rich-text/index.js b/packages/block-editor/src/components/rich-text/index.js index 69b04fe4c4904e..8e7e91dc13988a 100644 --- a/packages/block-editor/src/components/rich-text/index.js +++ b/packages/block-editor/src/components/rich-text/index.js @@ -160,8 +160,7 @@ export function RichTextWrapper( if ( blockTypeAttributes?.[ attribute ]?.source === 'rich-text' && - getBlockBindingsSource( args.source.name ) - ?.lockAttributesEditing + getBlockBindingsSource( args.source )?.lockAttributesEditing ) { shouldDisableEditing = true; break; diff --git a/packages/block-editor/src/hooks/use-bindings-attributes.js b/packages/block-editor/src/hooks/use-bindings-attributes.js index 94aac654097e5d..c6c847cbddcd1c 100644 --- a/packages/block-editor/src/hooks/use-bindings-attributes.js +++ b/packages/block-editor/src/hooks/use-bindings-attributes.js @@ -44,7 +44,7 @@ const createEditFunctionWithBindingsAttribute = () => Object.entries( updatedAttributes.metadata.bindings ).forEach( ( [ attributeName, settings ] ) => { const source = getBlockBindingsSource( - settings.source.name + settings.source ); if ( source ) { @@ -52,10 +52,7 @@ const createEditFunctionWithBindingsAttribute = () => const { placeholder, useValue: [ metaValue = null ] = [], - } = source.useSource( - props, - settings.source.attributes - ); + } = source.useSource( props, settings.args ); if ( placeholder && ! metaValue ) { // If the attribute is `src` or `href`, a placeholder can't be used because it is not a valid url. diff --git a/packages/block-library/src/block/edit.js b/packages/block-library/src/block/edit.js index e29b90b5e3c5c1..8ec7275c0e9f87 100644 --- a/packages/block-library/src/block/edit.js +++ b/packages/block-library/src/block/edit.js @@ -45,14 +45,14 @@ function isPartiallySynced( block ) { ) && !! block.attributes.metadata?.bindings && Object.values( block.attributes.metadata.bindings ).some( - ( binding ) => binding.source.name === 'pattern_attributes' + ( binding ) => binding.source === 'core/pattern-attributes' ) ); } function getPartiallySyncedAttributes( block ) { return Object.entries( block.attributes.metadata.bindings ) .filter( - ( [ , binding ] ) => binding.source.name === 'pattern_attributes' + ( [ , binding ] ) => binding.source === 'core/pattern-attributes' ) .map( ( [ attributeKey ] ) => attributeKey ); } diff --git a/packages/block-library/src/button/edit.js b/packages/block-library/src/button/edit.js index 7dffdfb5c1b669..6b0e472e15a94b 100644 --- a/packages/block-library/src/button/edit.js +++ b/packages/block-library/src/button/edit.js @@ -245,9 +245,8 @@ function ButtonEdit( props ) { return { lockUrlControls: !! metadata?.bindings?.url && - getBlockBindingsSource( - metadata?.bindings?.url?.source?.name - )?.lockAttributesEditing === true, + getBlockBindingsSource( metadata?.bindings?.url?.source ) + ?.lockAttributesEditing === true, }; }, [ isSelected ] diff --git a/packages/block-library/src/image/edit.js b/packages/block-library/src/image/edit.js index 3fed0819251e65..57ff28a0128efb 100644 --- a/packages/block-library/src/image/edit.js +++ b/packages/block-library/src/image/edit.js @@ -347,9 +347,8 @@ export function ImageEdit( { return { lockUrlControls: !! metadata?.bindings?.url && - getBlockBindingsSource( - metadata?.bindings?.url?.source?.name - )?.lockAttributesEditing === true, + getBlockBindingsSource( metadata?.bindings?.url?.source ) + ?.lockAttributesEditing === true, }; }, [ isSelected ] diff --git a/packages/block-library/src/image/image.js b/packages/block-library/src/image/image.js index d6d259c428b6ea..673c95f075edf4 100644 --- a/packages/block-library/src/image/image.js +++ b/packages/block-library/src/image/image.js @@ -433,15 +433,15 @@ export default function Image( { return { lockUrlControls: !! urlBinding && - getBlockBindingsSource( urlBinding?.source?.name ) + getBlockBindingsSource( urlBinding?.source ) ?.lockAttributesEditing === true, lockAltControls: !! altBinding && - getBlockBindingsSource( altBinding?.source?.name ) + getBlockBindingsSource( altBinding?.source ) ?.lockAttributesEditing === true, lockTitleControls: !! titleBinding && - getBlockBindingsSource( titleBinding?.source?.name ) + getBlockBindingsSource( titleBinding?.source ) ?.lockAttributesEditing === true, }; }, diff --git a/packages/editor/src/bindings/post-meta.js b/packages/editor/src/bindings/post-meta.js index 17f5e1837e35e0..091491b2ed00c7 100644 --- a/packages/editor/src/bindings/post-meta.js +++ b/packages/editor/src/bindings/post-meta.js @@ -10,12 +10,12 @@ import { __ } from '@wordpress/i18n'; import { store as editorStore } from '../store'; export default { - name: 'post_meta', + name: 'core/post-meta', label: __( 'Post Meta' ), useSource( props, sourceAttributes ) { const { getCurrentPostType } = useSelect( editorStore ); const { context } = props; - const { value: metaKey } = sourceAttributes; + const { key: metaKey } = sourceAttributes; const postType = context.postType ? context.postType : getCurrentPostType(); diff --git a/packages/patterns/src/components/partial-syncing-controls.js b/packages/patterns/src/components/partial-syncing-controls.js index f5ac19bc05f3d7..0f6cde5ce7d689 100644 --- a/packages/patterns/src/components/partial-syncing-controls.js +++ b/packages/patterns/src/components/partial-syncing-controls.js @@ -19,10 +19,10 @@ function PartialSyncingControls( { name, attributes, setAttributes } ) { const syncedAttributes = PARTIAL_SYNCING_SUPPORTED_BLOCKS[ name ]; const attributeSources = Object.keys( syncedAttributes ).map( ( attributeName ) => - attributes.metadata?.bindings?.[ attributeName ]?.source?.name + attributes.metadata?.bindings?.[ attributeName ]?.source ); const isConnectedToOtherSources = attributeSources.every( - ( source ) => source && source !== 'pattern_attributes' + ( source ) => source && source !== 'core/pattern-attributes' ); // Render nothing if all supported attributes are connected to other sources. @@ -38,8 +38,8 @@ function PartialSyncingControls( { name, attributes, setAttributes } ) { if ( ! isChecked ) { for ( const attributeName of Object.keys( syncedAttributes ) ) { if ( - updatedBindings[ attributeName ]?.source?.name === - 'pattern_attributes' + updatedBindings[ attributeName ]?.source === + 'core/pattern-attributes' ) { delete updatedBindings[ attributeName ]; } @@ -59,9 +59,7 @@ function PartialSyncingControls( { name, attributes, setAttributes } ) { for ( const attributeName of Object.keys( syncedAttributes ) ) { if ( ! updatedBindings[ attributeName ] ) { updatedBindings[ attributeName ] = { - source: { - name: 'pattern_attributes', - }, + source: 'core/pattern-attributes', }; } } @@ -96,7 +94,7 @@ function PartialSyncingControls( { name, attributes, setAttributes } ) { __nextHasNoMarginBottom label={ __( 'Allow instance overrides' ) } checked={ attributeSources.some( - ( source ) => source === 'pattern_attributes' + ( source ) => source === 'core/pattern-attributes' ) } onChange={ ( isChecked ) => { updateBindings( isChecked ); diff --git a/test/e2e/specs/editor/various/pattern-overrides.spec.js b/test/e2e/specs/editor/various/pattern-overrides.spec.js index ee60091e057c02..541f2f1600ad29 100644 --- a/test/e2e/specs/editor/various/pattern-overrides.spec.js +++ b/test/e2e/specs/editor/various/pattern-overrides.spec.js @@ -92,7 +92,7 @@ test.describe( 'Pattern Overrides', () => { id: expect.any( String ), bindings: { content: { - source: { name: 'pattern_attributes' }, + source: 'core/pattern-attributes', }, }, }, @@ -222,7 +222,7 @@ test.describe( 'Pattern Overrides', () => { const paragraphId = 'paragraph-id'; const { id } = await requestUtils.createBlock( { title: 'Pattern', - content: ` + content: `

Editable

`, status: 'publish', @@ -270,7 +270,7 @@ test.describe( 'Pattern Overrides', () => { const { id } = await requestUtils.createBlock( { title: 'Pattern with overrides', content: ` -
+
`,