Feature : Button - Dynamic URL resolution#74814
Feature : Button - Dynamic URL resolution#74814Vrishabhsk wants to merge 5 commits intoWordPress:trunkfrom
Conversation
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
| linkPanel={ isLinkTag ? linkPanel : null } | ||
| /> | ||
| </InspectorControls> | ||
| <InspectorControls group="advanced"> |
There was a problem hiding this comment.
What was the reason to remove this control? Is it because there'll always be an href now?
It means users can no longer switch between <a> and <button> tags, which seems on the surface to be a regression to me.
| * - type: post type slug or taxonomy slug | ||
| * - id: entity ID | ||
| * | ||
| * @since 6.9.0 |
There was a problem hiding this comment.
I know you've been waiting for a while for reviews, thanks for your patience!
I don't know if this will make the next WordPress release, but the next version is now 7.0.0
| * @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 ) { |
There was a problem hiding this comment.
It would be good to get test coverage here, e.g.,
- Valid post-type and taxonomy URL resolution
- Non-public post denial
- Password-protected post denial
- Invalid/missing args
- Deleted entity handling (?)
| } | ||
|
|
||
| $kind = (string) $source_args['kind']; | ||
| $type = (string) $source_args['type']; |
There was a problem hiding this comment.
Should we check if the post type exists? E.g.,
if ( ! post_type_exists( $type ) ) {
return null;
}| clearEntityUrlBinding, | ||
| createEntityUrlBinding, |
There was a problem hiding this comment.
I think these (and unlink()) should be wrapped in a useCallback().
They are plain closures recreated every render, which will make the useMemo recompute here.
Either that or restructure the logic somehow.
| urlBinding?.source === 'core/term-data'; | ||
| const boundEntityArgs = isEntityUrlBinding ? urlBinding?.args : null; | ||
|
|
||
| const resolvedEntityUrl = useSelect( |
There was a problem hiding this comment.
Could this useSelect be combined with the one below? They both call getEntityRecord.
| preview, | ||
| suggestionsQuery: getSuggestionsQuery( boundType, boundKind ), | ||
| help, | ||
| onSelect: ( updatedLink ) => { |
There was a problem hiding this comment.
This callback seems very similar to LinkControl.onChange - could be extracted to a shared helper?
| @@ -150,11 +150,15 @@ export function useToolsPanelItem( | |||
| } | |||
|
|
|||
| if ( isMenuItemChecked && ! isValueSet && ! wasMenuItemChecked ) { | |||
| onSelect?.(); | |||
| if ( typeof onSelect === 'function' ) { | |||
There was a problem hiding this comment.
What's the motivation behind this change?
There's a subtle difference: optional chaining would throw on non-function truthy values (surfacing bugs), while typeof silently skips them.
I only raise it because it's a shared component used in many places. If there's a good reason, this change would be better suited to its own PR.
There was a problem hiding this comment.
We should defintely undo these changes, and move them to a separate PR (if there's a strong reason to apply them)
There was a problem hiding this comment.
Thanks for taking this on - the UI work looks great and this is a valuable feature.
The Issue
This PR creates a new core/entity binding source, but Navigation Links already use core/post-data and core/term-data for entity resolution. I think we need to align these (at least for 7.0) because:
- Maintenance: fixes/improvements shouldn't happen in two places
- Consistency: blocks linking to entities should work the same way
- Future: other blocks need one clear pattern to follow
That doesn't mean we can't normalize both button and nav towards a new entity source in future but I don't see that happening for 7.0 timelines.
Proposed Fix
1. Store entity data in metadata
Button doesn't have id/kind/type attributes, so store them alongside the bindings:
metadata: {
bindings: {
url: {
source: kind === 'taxonomy' ? 'core/term-data' : 'core/post-data',
args: { field: 'link' }
}
},
id: 123,
kind: 'post-type',
type: 'page'
}2. Update existing binding sources
Modify core/post-data and core/term-data to check metadata for entity info first, falling back to current editor context if not found.
3. Remove core/entity source
This approach keeps Button minimal while using Navigation Link's existing infrastructure.
What do you think? I'm happy to explore this if you haven't got time. Noting that the cut off for 7.0 is tomorrow 😬
|
Hi @getdave 👋
Let me know what will be the best approach. Thanks |
|
Hi @Vrishabhsk. Apologies but this is not going to make the cut for 7.0. We need to bring in relevant UI updates as well to ensure we're properly communicate the state of "bound" links. Based on experience introducing the original functionality in Navigation in 6.9 there were a lot of edge cases and trying to rush this in pre 7.0 cut off today is going to make for a less stable release. I do think this is important and we should follow up in WordPress 7.1. We can continue to work on this right away here in the Gutenberg Plugin. Thank you again for your hard work and I'm looking forward to working with you to get this into a good place really soon. |
c48e200 to
2015d96
Compare
|
Hi @getdave 👋, im implemented your suggestions. Here is a quick summary of it : Key Changes
|
What?
Navigation linksforbuttonblockWhy?
How?
Testing Instructions
(Optional) Paste/type a custom external URL and confirm:
The entity binding is removed and the Button uses the typed URL.
Screenshots or screencast