Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add block bindings API basis and metadata source #56867

Closed
Closed
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4100933
Add the basis of the Block Bindings API
SantosGuillamot Nov 29, 2023
edee28a
Add the first PHP logic of the `metadata` source
SantosGuillamot Nov 29, 2023
01189c7
Update metadata folder structure
SantosGuillamot Nov 30, 2023
5e38246
Add initial version of the block bindings editor UI
SantosGuillamot Nov 30, 2023
35d03dd
Filter to add the bindings attribute automatically
SantosGuillamot Nov 30, 2023
a19009c
Logic to handle different attributes in the editor
SantosGuillamot Nov 30, 2023
87e333d
Fetch metadata from REST API correctly
SantosGuillamot Nov 30, 2023
081ed5c
Use const instead of let
SantosGuillamot Nov 30, 2023
ecd1377
Move bindings inside metadata attribute
SantosGuillamot Dec 1, 2023
7543606
Use getEntityRecord to fetch the REST API
SantosGuillamot Dec 1, 2023
1017d4d
Merge branch `trunk` into `add/block-bindings-api-basis-and-metadata-…
SantosGuillamot Dec 1, 2023
8096402
Add helper to update bindings in the editor
SantosGuillamot Dec 1, 2023
5d5c68c
Use editor helper in metadata source
SantosGuillamot Dec 1, 2023
24ff0d2
Adapt pattern source PHP side
SantosGuillamot Dec 1, 2023
6c7fe63
Adapt pattern source editor side
SantosGuillamot Dec 1, 2023
6176f15
Change bindings format to be an object
SantosGuillamot Dec 3, 2023
feaf22d
Fix selected metadata attribute
SantosGuillamot Dec 3, 2023
4689e76
Slightly modify the bindings property syntax
SantosGuillamot Dec 3, 2023
f6bc2c0
Add support for heading and button blocks
SantosGuillamot Dec 4, 2023
3590330
Add post and site data
SantosGuillamot Dec 4, 2023
5b5546f
Support for button and heading selectors
SantosGuillamot Dec 18, 2023
01d834b
Change bindings syntax to use name and attributes
SantosGuillamot Dec 18, 2023
d215035
Add extensibility to the Block Bindings UI in the editor
SantosGuillamot Dec 18, 2023
159cb0a
Add post-data and site-data sources in the editor
SantosGuillamot Dec 18, 2023
1178ba8
Add core sources in PHP
SantosGuillamot Dec 18, 2023
006872f
Abstract block bindings UI
SantosGuillamot Dec 19, 2023
cc59e1b
Remove extra dependency
SantosGuillamot Dec 19, 2023
4f651c2
Modify `register_block_bindings_source` syntax
SantosGuillamot Dec 20, 2023
7dd4368
Change block bindings experiment name
SantosGuillamot Dec 20, 2023
62a8bc1
Remove old UI
SantosGuillamot Dec 20, 2023
b95ac5e
Change variables names
SantosGuillamot Dec 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Slightly modify the bindings property syntax
  • Loading branch information
SantosGuillamot committed Dec 3, 2023
commit 4689e76f5bf0a2479b1a81d1147fbd9719c08688
17 changes: 11 additions & 6 deletions lib/experimental/blocks.php
Original file line number Diff line number Diff line change
@@ -106,16 +106,21 @@ function process_block_bindings( $block_content, $block, $block_instance ) {
return $block_content;
}

// TODO: Review the bindings syntax.
// Assuming the following format for the bindings property of the "metadata" attribute:
//
// "bindings": {
// "title": {
// "source_id": "metadata",
// "source_params": { "value": "text_custom_field" }
// "source": {
// "id": "metadata",
// "params": { "value": "text_custom_field" }
// }
// },
// "url": {
// "source_id": "metadata",
// "source_params": { "value": "url_custom_field" }
// "source": {
// "id": "metadata",
// "params": { "value": "text_custom_field" }
// }
// }
// },
// .
@@ -133,10 +138,10 @@ function process_block_bindings( $block_content, $block, $block_instance ) {
// Get the value based on the source.
// We might want to move this to its own function if it gets more complex.
// We pass $block_content, $block, $block_instance to the source callback in case sources want to use them.
if ( ! isset( $block_bindings_sources[ $binding_source['source_id'] ]['apply_source'] ) ) {
if ( ! isset( $block_bindings_sources[ $binding_source['source']['id'] ]['apply_source'] ) ) {
return $block_content;
}
$source_value = $block_bindings_sources[ $binding_source['source_id'] ]['apply_source']( $binding_source['source_params'], $block_content, $block, $block_instance );
$source_value = $block_bindings_sources[ $binding_source['source']['id'] ]['apply_source']( $binding_source['source']['params'], $block_content, $block, $block_instance );
if ( false === $source_value ) {
return $block_content;
}
18 changes: 11 additions & 7 deletions packages/block-editor/src/utils/update-bindings.js
Original file line number Diff line number Diff line change
@@ -19,12 +19,16 @@ export const updateBlockBindingsAttribute = (
//
// "bindings": {
// "title": {
// "source_id": "metadata",
// "source_params": { "value": "text_custom_field" }
// "source": {
// "id": "metadata",
// "params": { "value": "text_custom_field" }
// }
// },
// "url": {
// "source_id": "metadata",
// "source_params": { "value": "url_custom_field" }
// "source": {
// "id": "metadata",
// "params": { "value": "text_custom_field" }
// }
// }
// },
// .
@@ -54,9 +58,9 @@ export const updateBlockBindingsAttribute = (
? metadataAttribute.bindings
: {};

bindingsProperty[ updatingAttribute ] = {};
bindingsProperty[ updatingAttribute ].source_id = sourceName;
bindingsProperty[ updatingAttribute ].source_params = sourceParams;
bindingsProperty[ updatingAttribute ] = {
source: { id: sourceName, params: sourceParams },
};

metadataAttribute.bindings = bindingsProperty;
// TODO: Decide if we want to include the setAttributes call here.
4 changes: 2 additions & 2 deletions packages/block-library/src/block/edit.js
Original file line number Diff line number Diff line change
@@ -41,14 +41,14 @@ function isPartiallySynced( block ) {
!! getBlockSupport( block.name, '__experimentalConnections', false ) &&
!! block.attributes.metadata?.bindings &&
Object.values( block.attributes.metadata.bindings ).some(
( binding ) => binding.source_id === 'pattern_attributes'
( binding ) => binding.source.id === 'pattern_attributes'
)
);
}
function getPartiallySyncedAttributes( block ) {
return Object.entries( block.attributes.metadata.bindings )
.filter(
( [ , binding ] ) => binding.source_id === 'pattern_attributes'
( [ , binding ] ) => binding.source.id === 'pattern_attributes'
)
.map( ( [ attributeKey ] ) => attributeKey );
}
4 changes: 2 additions & 2 deletions packages/editor/src/components/block-bindings/metadata.js
Original file line number Diff line number Diff line change
@@ -95,9 +95,9 @@ export default function MetadataSourceUI( props ) {
onClick={ () => selectItem( item ) }
className={
attributes.metadata?.bindings?.[ currentAttribute ]
?.source_id === 'metadata' &&
?.source?.id === 'metadata' &&
attributes.metadata?.bindings?.[ currentAttribute ]
?.source_params.value === item.key
?.source?.params?.value === item.key
? 'selected-meta-field'
: ''
}
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@ function PartialSyncingControls( { name, attributes, setAttributes } ) {
checked={
attributes?.metadata?.bindings?.[
attributeName
]?.source_id === 'pattern_attributes'
]?.source?.id === 'pattern_attributes'
}
onChange={ ( isChecked ) => {
// TODO: REVIEW WHY THE CHECKED IS NOT UPDATED.