-
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
Navigation / Page List: Allow converting to individual menu items #29437
Comments
Hi @jasmussen, great to run into you! Here's some suggestions for the copy. Let me know if you have any questions or need some clarification. To edit this menu, convert it to single menu items. This allows you to add, re-order, remove items, or edit their labels. Note: if you add new pages to your site, you'll need to add them to your navigation menu. CANCEL CONVERT |
Thank you Krista, it's always a pleasure! This is great. 👌 |
It could be worth using the term 'page links' instead of 'menu items'. Menu items is what the old system is called, and Page Link is the block name that it would be converted to. |
Also wondering if this dialog could be something declarative that's built in to the transform system for blocks. It could be useful for transforms where there's potential for content to be removed (for example the Cover to Image transform). I'm assuming here that converting Page List -> Page Links would be implemented as a transform under the hood. |
It would be nice with a systematized way of being able to show a dialog on transforms like these. I could see it benefitting the classic block > blocks conversion also, even though that's probably a different type of conversion.
Presumably. Should there also be a way to transform one or more menu items into a Page List? I.e. select all menu items and convert to page list? It would probably be a lossy transformation as they'd very probably be out of sync. |
I can explore this one, @talldan I believe this will be one of the first dynamic blocks to be transformed? For example, HTML->Convert to Blocks is handled in |
Hadn't thought of that. You're right, there don't seem to be any transforms for dynamic core blocks. I guess this will be a bit more of a challenge. |
I ended up bugfixing today, but some early thoughts: Solving for the General CaseAre there any other core dynamic blocks that need information to transform in the "to" direction? We need page link informationFor this particular use case, block attributes are empty. So the client transform has no information. Some quick ideas:
Inserting the list of linksEven if we have all information to create the links in a to transform, we'll need sibling insertion of those links in the parent navigation block. Assuming that page-list contains "Test" and "About"
With the current transformation APIs it isn't possible to generate something like:
The block transform API expects This shouldn't be too bad to update in the block transform API, but I think it's worth verifying that there are more use cases to support this. If it's already possible to do this, let me know 👍 In case y'all were interested cc @gziolo @youknowriad @talldan @ellatrix |
I can't think of any. Something like Archives/Latest Posts to Post Link seems like the closest thing, but the blocks aren't useable in the same context. A lot of the existing dynamic blocks were created as replacements for widgets, so don't necessarily map to other blocks.
The server side transform sounds like the most plausible. What I have in mind is:
Considerations:
Another option could be to change how Page List renders in the editor—move it away from using ServerSideRender, so that there is actually data client side (though it'd still be challenging to get this into the transform callback). There was some discussion about the editor implementation during the original PR along with the idea to make Page List render Page Links internally.
I think this bit is possible. Gallery has a similar transform to images. Looks like returning an array of blocks is the way to achieve this: gutenberg/packages/block-library/src/gallery/transforms.js Lines 126 to 137 in 47dea65
|
One idea @dmsnell had was to refactor the page list block to save navigation links as inner blocks (instead of producing the custom markup we generate), which would allow us to use the existing block transform API. Page lists are currently embeddable outside of the Navigation block so there are some corner cases to consider, but it might be worth exploring. |
👋 — I think this is specific enough that we shouldn't be generalising around a new API yet. Some notes from my train of thought:
Can we then explore a solution that doesn't introduce a new API? Keeping this specific to the Page List and/or Navigation should give enough flexibility for the blocks to do whatever juggling data is necessary, coordinating REST API requests with editor APIs ( If I've overlooked something crucial, please call me out. |
Thanks for the feedback @mcsf you caught me a bit early! From the quick sketches in #30358 WordPress/wordpress-develop#1138 a few things stand out:
Yes, I was going to look into seeing if a PageList refactor is viable. The markup that this particular block generates isn't particularly interesting, so we could simplify things by saving navigation links to the innerBlocks. The deprecation path might need some work, as page list can exist outside of navigation blocks. Another area to explore is whether PageList is still needed as a block. There are a few odd combinations the current implementation allows. It feels more like a mode of the Navigation block container if it's controlled or if the user may add arbitrary links. |
Thanks for taking the time to assess this fully!
This is good to look into. Another thing comes to mind: the Query block has more in common with Navigation and Page List than one might think. In order for Query to work, we needed to be able to reconcile a few things; in particular, a Query block is capable of "containing" dynamic things. In its serialised form, a Query block will contain Query-related blocks, like Query Title, etc. But in the editor, once this all materialises as living blocks, the Query block contains posts, each of them containing a title, etc. This isn't necessarily the best path for Navigation, but it's food for thought on the whole question of dynamic vs. static. :) |
What problem does this address?
When you create a navigation menu and press "Add all pages", you get the Page List preinserted. This block stays in sync with pages you create or delete on your website, and is likely a good default experience for most people.
Every once in a while, you need a more curated experience:
What is your proposed solution?
Allow the Page List block to be converted to single menu items, so those can be reordered, deleted or tweaked at will. Here's a mockup:
The phrasing of the text in the modal could use fine tuning. It needs to be brief, simple, to the point, but still explain the purpose.
The text was updated successfully, but these errors were encountered: