-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Remove core/entity binding in favour of post and term data bindings. Apply to Nav blocks. #72165
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
8de830e
4e4e8c1
fda4b5f
8da866f
6a67da0
2fe149f
fe31a16
5ae5757
cb5c56b
3e398c2
455bacc
1b0511f
57d6fc5
befad83
b981a70
8a47fd9
fe1289b
37cba74
92e7bfd
4c60e00
7bc97f3
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/10305 | ||
|
|
||
| * https://github.com/WordPress/gutenberg/pull/72165 |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| <?php | ||
| /** | ||
| * Term Data source for the block bindings. | ||
| * | ||
| * @since 6.9.0 | ||
| * @package gutenberg | ||
| * @subpackage Block Bindings | ||
| */ | ||
|
|
||
| /** | ||
| * Gets value for Term Data source. | ||
| * | ||
| * @since 6.9.0 | ||
| * @access private | ||
| * | ||
| * @param array $source_args Array containing source arguments used to look up the override value. | ||
| * Example: array( "key" => "name" ). | ||
| * @param WP_Block $block_instance The block instance. | ||
| * @return mixed The value computed for the source. | ||
| */ | ||
| function gutenberg_block_bindings_term_data_get_value( array $source_args, $block_instance ) { | ||
| if ( empty( $source_args['key'] ) ) { | ||
| return null; | ||
| } | ||
|
|
||
| /* | ||
| * BACKWARDS COMPATIBILITY: Hardcoded exception for navigation blocks. | ||
| * Required for WordPress 6.9+ navigation blocks. DO NOT REMOVE. | ||
| */ | ||
| $block_name = $block_instance->name ?? ''; | ||
| $is_navigation_block = in_array( | ||
| $block_name, | ||
| array( 'core/navigation-link', 'core/navigation-submenu' ), | ||
| true | ||
| ); | ||
|
|
||
| if ( $is_navigation_block ) { | ||
| // Navigation blocks: read from block attributes | ||
| $term_id = $block_instance->attributes['id'] ?? null; | ||
| $type = $block_instance->attributes['type'] ?? ''; | ||
| // Map UI shorthand to taxonomy slug when using attributes. | ||
| $taxonomy = ( 'tag' === $type ) ? 'post_tag' : $type; | ||
| } else { | ||
| // All other blocks: use context | ||
| $term_id = $block_instance->context['termId'] ?? null; | ||
| $taxonomy = $block_instance->context['taxonomy'] ?? ''; | ||
| } | ||
|
|
||
| // If we don't have required identifiers, bail early. | ||
| if ( empty( $term_id ) || empty( $taxonomy ) ) { | ||
| return null; | ||
| } | ||
|
|
||
| // Get the term data. | ||
| $term = get_term( $term_id, $taxonomy ); | ||
| if ( is_wp_error( $term ) || ! $term ) { | ||
| return null; | ||
| } | ||
|
|
||
| // Check if taxonomy exists and is publicly queryable. | ||
| $taxonomy_object = get_taxonomy( $taxonomy ); | ||
| if ( ! $taxonomy_object || ! $taxonomy_object->publicly_queryable ) { | ||
| if ( ! current_user_can( 'read' ) ) { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| switch ( $source_args['key'] ) { | ||
| case 'id': | ||
| return esc_html( (string) $term_id ); | ||
|
|
||
| case 'name': | ||
| return esc_html( $term->name ); | ||
|
|
||
| case 'link': | ||
| // Only taxonomy entities are supported by Term Data. | ||
| $term_link = get_term_link( $term ); | ||
| return is_wp_error( $term_link ) ? null : esc_url( $term_link ); | ||
|
|
||
| case 'slug': | ||
| return esc_html( $term->slug ); | ||
|
Comment on lines
+75
to
+81
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. @ockham Is there overlap here? I guess slug might be used separately from link so maybe it's ok?
Contributor
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. Sounds okay to me -- especially since we don't currently have any way to "post-process" values from block bindings sources (e.g. we can't concatenate a BB source value with a string literal). |
||
|
|
||
| case 'description': | ||
| return wp_kses_post( $term->description ); | ||
|
|
||
| case 'parent': | ||
| return esc_html( (string) $term->parent ); | ||
|
|
||
| case 'count': | ||
| return esc_html( (string) $term->count ); | ||
|
|
||
| default: | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Registers Term Data source in the block bindings registry. | ||
| * | ||
| * @since 6.9.0 | ||
| * @access private | ||
| */ | ||
| function gutenberg_register_block_bindings_term_data_source() { | ||
| if ( get_block_bindings_source( 'core/term-data' ) ) { | ||
| // The source is already registered. | ||
| return; | ||
| } | ||
|
|
||
| register_block_bindings_source( | ||
| 'core/term-data', | ||
| array( | ||
| 'label' => _x( 'Term Data', 'block bindings source' ), | ||
| 'get_value_callback' => 'gutenberg_block_bindings_term_data_get_value', | ||
| 'uses_context' => array( 'termId', 'taxonomy' ), | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| add_action( 'init', 'gutenberg_register_block_bindings_term_data_source' ); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,7 +44,7 @@ function gutenberg_is_experiment_enabled( $name ) { | |
| require __DIR__ . '/compat/wordpress-6.9/template-activate.php'; | ||
| 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/entity-block-bindings.php'; | ||
| require __DIR__ . '/compat/wordpress-6.9/term-data-block-bindings.php'; | ||
|
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. These bindings were removed in #72275 but we need them so this PR reinstates them 😓 |
||
| require __DIR__ . '/compat/wordpress-6.9/rest-api.php'; | ||
| require __DIR__ . '/compat/wordpress-6.9/class-gutenberg-hierarchical-sort.php'; | ||
| require __DIR__ . '/compat/wordpress-6.9/block-comments.php'; | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -78,10 +78,12 @@ function UnforwardedLinkUI( props, ref ) { | |||||||
| name: postType, | ||||||||
| } ); | ||||||||
|
|
||||||||
| // Check if there's a URL binding with the core/entity source | ||||||||
| // Check if there's a URL binding with the new binding sources | ||||||||
| // Only enable handleEntities when there's actually a binding present | ||||||||
| const hasUrlBinding = | ||||||||
| metadata?.bindings?.url?.source === 'core/entity' && !! id; | ||||||||
| ( metadata?.bindings?.url?.source === 'core/post-data' || | ||||||||
| metadata?.bindings?.url?.source === 'core/term-data' ) && | ||||||||
|
Comment on lines
+84
to
+85
Contributor
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. Could do
Suggested change
|
||||||||
| !! id; | ||||||||
|
|
||||||||
| // Memoize link value to avoid overriding the LinkControl's internal state. | ||||||||
| // This is a temporary fix. See https://github.com/WordPress/gutenberg/issues/50976#issuecomment-1568226407. | ||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For full clarity, could we also add an END block so we know the full section of code that should never be removed?