-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Use slug instead of id for ref in Navigation block #42809
base: trunk
Are you sure you want to change the base?
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
lib/compat/wordpress-6.1/class-gutenberg-rest-navigation-controller.php
Outdated
Show resolved
Hide resolved
lib/compat/wordpress-6.1/class-gutenberg-rest-navigation-controller.php
Outdated
Show resolved
Hide resolved
isEligible: ( { ref } ) => { | ||
return isNumeric( ref ); | ||
}, |
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.
This handles moving from number
to string
based ref
attribute.
I'm of the opinion that we shouldn't look to land this for WP 6.1. Why? This change has no user-facing benefit. In fact the whole point of the PR is that nothing changes for the user - otherwise we'd have a regression. This PR is focused on a longer term goal of allowing Navigation Menus to be carried across to the most appropriate position in a new Theme. However in and of itself it is purely a technical implementation change moving Whilst this PR is very important in laying the groundwork for future user facing benefits it won't change anything for the user and (as with all significant changes) it comes with the risk of introducing regressions. Furthermore, landing this change so close to WP 6.1 would not leave much time for contributors and/or users to test the functionality and provide feedback on regressions. It might be appropriate to try land this PR if we could also concurrently land a well thought out mechanic which could take a given Therefore I'm recommending we don't merge this PR unless we can also land the additional functionality and we wait until the WP 6.2 cycle. What do you think? |
@getdave I agree with your assessment that sufficient testing so close to 6.1 is unlikely to happen and, if it does/a mechanic is developed, it may be done in a crunch-like manner (i.e. stress). Given that this has no user-facing benefit, it makes sense to land this in 6.2 instead with the confidence that no regressions have been introduced. |
@getdave I'm a bit confused why we are trying to retrofit a slug in the |
d206240
to
0233c7b
Compare
I rebased this. |
Honestly I've considered this route several times but never voiced it because I felt it would be a "developer convenience" to simply add a new attribute to work around the problem that currently menus are referenced by IDs. Bear in mind that the Nav block has already had one migration from The pros of this approach are clearly:
Cons are:
That all said, as I see it, it should be pretty simple to rewrite the frontend to use a new The process is to request the menu by the For new blocks, we simply use I'll do this work tomorrow which will hopefully somewhat simplify the PR. From there we can decide whether it's possible to land a follow up to this PR which implements the "lookup" part of the plan which would allow the Navigation to be carried across on Theme switch. I know @draganescu has been looking at this but I believe we should be careful to be sure that landing such a feature without lots of testing this close to 6.1 is a good idea. |
I've explored how having a slug for navigation block would improve the navigation preservation experience. I found that:
The idea is that navigation preservation on theme switch based on slug works. But it is not perfect:
Some uncertainties:
Given the above, even if we land this work it is unlikely that we can produce any major user visible enhancement of UX based on this PR. Therefore it seems that despite @mtias ’s suggestion of just adding a |
Plus it would also work in template part focus mode. The blockers are (from what I understand):
Another option is a completely separate |
I agree with Andrei as I can't see a suitably robust system landing prior to WP 6.1 feature freeze. What we cam do now is hold off merging this PR until after the feature freeze thereby ensuring it does not end up in WP 6.1. Then we can look to merge and continue working on the template part hierarchy and lookup work. I think we should have an open-invite project kick off where the options for the lookup work are discussed and next steps are agreed. We should also agree to have regular sync checkins with stakeholders (i.e. anyone with an active interest in the work) to ensure that whoever is developing the PR has sufficient input and opinion to avoid things going off track.
Just noting that this work is already complete. So this now hangs on what you've concluded re: template part hierarchy and lookups. |
@getdave
It might be fine to just leave |
Yes and I've already updated the implementation as such 👍🏽. My instinct was to see them both as a form of "reference" thus the urge to normalize them but I have taken on board your well justified arguments and I don't feel any reason not to go ahead on that basis.
This is the question. If we want to leave ID-based "references" alone then we'll need to test this PR and check there are no scenarios where that occurs. My concern was always that there will be use cases already in the open whereby folks expect their reference to stay the same. If we suddenly start migrating them to |
Yeah, I wouldn't mind leaving refs untouched until users reset a template, switch themes, or remove/add navigation. |
I haven't forgotten about this. Contributors are focused on bugs for WP 6.1 at the moment but I will pick it up again asap. |
a6ca338
to
3455ffc
Compare
This PR is too large. I've extracted a sub PR to deal with the REST API parts. As this is fully backwards compatible we can merge it and then rebase this PR to remove all the REST API bits. |
What?
In #38291 (comment) we discussed why it is important that the Navigation block uses string based
slug
as the way for it to "refer" (via an attribute) to a Navigation post containing it's "items".This PR seeks to address that by adding a new
slug
attribute and soft deprecating the existingref
attribute. This allows the block to use aslug
to refer to a menu (wp_navigation
post) and updating the REST API to understand how to handle that.Please note: this PR is deliberately limited in scope. It does not attempt to implement any fallback behaviour relating to pick the "most appropriate" Navigation to use in the absence of an explicit reference. For example, this PR won't fix the situation whereby you switch Themes and the Navigation Menu isn't carried across the to new theme's Navigation block (although this PR does lay the foundation for such an effort).
Addresses part of work towards #38291
Why?
See #38291 (comment) for full explaination.
How?
This PR:
wp/v2/navigation
which adds a new endpoint to handle making requests for individualwp_navigation
posts by theirpost_name
(a.k.aslug
) or bypost_id
(for backwards compatibility).slug
attribute to the block.ref
attribute.navigation
post'sslug
(i.e.post_name
) as the reference.OPTIONS
permissions requests by overloading implementation ofget_post
method within the new Navigation REST Controller.Dependencies
Replace the OPTIONS requests with a faster HEAD request in canUser resolver #43703 - without this calls toI've created a workaround for this by overloading thecanUser
with aslug
will not provide the correct permissions.get_post
method to map slug to ID.Todo
saveEntityRecord
forupdate
requests.ref
change from ID to slug or do we want to preserve the existing data?rest_get_route_for_post
is filtered to account for usage ofslug
.Select menu
which doesn't pick the correct menu due to beingID
based.Testing Instructions
Manual
trunk
create a Navigation Menu using the block. You can use the Post Editor or the Site Editor.ref
attribute corresponding to the Navigation Post'sID
field.ref
which corresponds to theslug
of the Navigation Post.REST
Run tests using
Screenshots or screencast
Screen.Capture.on.2022-09-02.at.14-09-42.mp4