-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Block Bindings: Bootstrap sources defined in the server #63470
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
Changes from all commits
44d86f0
0ca3e00
758ede2
b575369
0e29fcd
f67ff90
a8fa943
8742066
429ebe7
575a2a9
9a56150
a98c45a
bde87d2
7cdf395
18f7227
a05caf6
f330a6a
c1ebd6b
33603d3
facd94e
b3b0a38
cf2a8e3
227890f
50cfa09
8389d37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| https://github.com/WordPress/wordpress-develop/pull/7020 | ||
|
|
||
| * https://github.com/WordPress/gutenberg/pull/63470 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| <?php | ||
| /** | ||
| * Temporary compatibility code for new functionalitites/changes related to block bindings APIs present in Gutenberg. | ||
| * | ||
| * @package gutenberg | ||
| */ | ||
|
|
||
| /** | ||
| * Adds the block bindings sources registered in the server to the editor settings. | ||
| * | ||
| * This allows them to be bootstrapped in the editor. | ||
| * | ||
| * @param array $settings The block editor settings from the `block_editor_settings_all` filter. | ||
| * @return array The editor settings including the block bindings sources. | ||
| */ | ||
| function gutenberg_add_server_block_bindings_sources_to_editor_settings( $editor_settings ) { | ||
| // Check if the sources are already exposed in the editor settings. | ||
| if ( isset( $editor_settings['blockBindingsSources'] ) ) { | ||
| return $editor_settings; | ||
| } | ||
|
|
||
| $registered_block_bindings_sources = get_all_registered_block_bindings_sources(); | ||
| if ( ! empty( $registered_block_bindings_sources ) ) { | ||
| // Initialize array. | ||
| $editor_settings['blockBindingsSources'] = array(); | ||
| foreach ( $registered_block_bindings_sources as $source_name => $source_properties ) { | ||
| // Add source with the label to editor settings. | ||
| $editor_settings['blockBindingsSources'][ $source_name ] = array( | ||
| 'label' => $source_properties->label, | ||
| ); | ||
| // Add `usesContext` property if exists. | ||
| if ( ! empty( $source_properties->uses_context ) ) { | ||
| $editor_settings['blockBindingsSources'][ $source_name ]['usesContext'] = $source_properties->uses_context; | ||
| } | ||
| } | ||
| } | ||
| return $editor_settings; | ||
| } | ||
|
|
||
| add_filter( 'block_editor_settings_all', 'gutenberg_add_server_block_bindings_sources_to_editor_settings', 10 ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -377,13 +377,22 @@ export function blockBindingsSources( state = {}, action ) { | |
| return { | ||
| ...state, | ||
| [ action.name ]: { | ||
| label: action.label, | ||
| // Don't override the label if it's already set. | ||
| label: state[ action.name ]?.label || action.label, | ||
| getValues: action.getValues, | ||
| setValues: action.setValues, | ||
| getPlaceholder: action.getPlaceholder, | ||
| canUserEditValue: action.canUserEditValue, | ||
| }, | ||
| }; | ||
| case 'ADD_BOOTSTRAPPED_BLOCK_BINDINGS_SOURCE': | ||
| return { | ||
| ...state, | ||
| [ action.name ]: { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my #63470 (comment). I predict it’s the missing edge case to cover. In the case bootstrapping happens after registration, it would replace the entry with data from the server. A unit test would also help here.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense. I'll work on a follow-up pull request to cover that use case.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have started this pull request trying to address this use case: link. |
||
| label: action.label, | ||
| usesContext: action.usesContext, | ||
| }, | ||
| }; | ||
| case 'REMOVE_BLOCK_BINDINGS_SOURCE': | ||
| return omit( state, action.name ); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.