-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[Try] menuSlug instead of navigationMenuId #36522
Conversation
"navigationMenuId": { | ||
"type": "number" | ||
"type": "number" | ||
}, |
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 needs to be removed of course
const navigationMenu = slug | ||
? getEditedEntityRecord( ...navigationMenuSingleArgs ) | ||
: null; |
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.
Need to create a new entity if slug is set but there is no navigationMenu with that slug
if ( ! oldSlug ) { | ||
const newSlug = area?.area | ||
? `${ area.area }//menu` | ||
: `generic-one-off//menu`; |
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 should be unique. GUID + server side hooks perhaps?
$template_query = new WP_Query( $wp_query_args ); | ||
$post_id = $template_query->posts[0]->ID; | ||
|
||
$request['slug'] = $request['id']; |
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.
$request['slug'] = $request['id']; | |
$request['slug'] = $request['slug']; |
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.
or was that intentional?
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 code doesn't seem to get executed because @adamziel returns the value here: https://github.com/WordPress/gutenberg/pull/36522/files#diff-678d8bd4bed4738f7b7c74ec8f9eb0bfdcc45d87ae275466cce7cb3601e654ecR125
I suppose that is intentional, @adamziel ?
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.
It is sort of intentional, that's a very quick&dirty draft and I just wanted to get some data flowing, I guess I just didn't remove dead code.
// TODO: this util should perhaps be refactored somewhere like core-data. | ||
import { createTemplatePartId } from '../template-part/edit/utils/create-template-part-id'; | ||
|
||
export default function useTemplatePartArea( clientId ) { |
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 is mostly copied over from useTemplatePartAreaLabel
, there's a lot of deduplication that could be done here.
/** | ||
* Base Templates REST API Controller. | ||
*/ | ||
class Gutenberg_REST_Navigation_Controller extends WP_REST_Posts_Controller { |
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 is quick&dirty attempt to reproduce template areas mechanics of requesting items by their slug, e.g. /wp/v2/navigation/header-menu
. A lot of cleaning up needed here.
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.
Great job.
I have a couple of notes/questions.
Shouldn't we just use slug
instead of menuSlug
for the name of the block's attribute?
if ( ! current_user_can( 'edit_theme_options' ) ) { | ||
return new WP_Error( | ||
'rest_cannot_manage_templates', | ||
__( 'Sorry, you are not allowed to access the templates on this site.', 'gutenberg' ), |
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.
It says templates
.
Should we change this to
Sorry, you are not allowed to access the navigation menus on this site.
?
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.
Fully agreed, it's just a copy&paste from the other endpoint for now
// This capability is required to edit/view/delete templates. | ||
if ( ! current_user_can( 'edit_theme_options' ) ) { | ||
return new WP_Error( | ||
'rest_cannot_manage_templates', |
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.
Same here.
protected function permissions_check() { | ||
// Verify if the current user has edit_theme_options capability. | ||
// This capability is required to edit/view/delete templates. | ||
if ( ! current_user_can( 'edit_theme_options' ) ) { |
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.
I don't know if we have specific capability to edit navigation menus, but if we do, I think we should use it instead of edit_theme_options
$template_query = new WP_Query( $wp_query_args ); | ||
$post_id = $template_query->posts[0]->ID; | ||
|
||
$request['slug'] = $request['id']; |
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 code doesn't seem to get executed because @adamziel returns the value here: https://github.com/WordPress/gutenberg/pull/36522/files#diff-678d8bd4bed4738f7b7c74ec8f9eb0bfdcc45d87ae275466cce7cb3601e654ecR125
I suppose that is intentional, @adamziel ?
The biggest problem here is with automatically creating a new menu when it's missing. After a quick chat with @youknowriad it doesn't seem like core data supports initializing a new in-memory entity record and saving it later. A reasonable workaround for now would be calling |
name: slug, | ||
post_name: slug, | ||
}; | ||
dispatch( coreStore ) |
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 needs to be less hacky
"type": "number" | ||
"type": "number" | ||
}, | ||
"menuSlug": { |
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.
Why not just "slug" since we're on the navigation block already.
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.
good point
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.
also just "slug" is what template parts do
The endpoint sometimes returns a numeric ID instead of slug. Once that's fixed, perhaps the editor bits would just work. |
Yeah, this is how the nav block works already when inserting from a pattern, so it was already a trade-off. We're working with a foundation that doesn't yet support the concepts we need and it's too late to introduce them for 5.9, so trade-offs are the only option IMO, they just need to be smart trade-offs. I had a good think about in-memory entities. A problem is that the user can save the content without saving the in-memory entity (e.g. a post containing a nav block with in-memory data autosaves). If the user wants to recover that revision, it won't contain the in-memory data. Probably what we need is a more seamless switch between the nav block in this form, where it has normal inner blocks as part of the block's content: <!-- wp:navigation -->
<!-- wp:navigation-link /-->
<!-- /wp:navigation --> and this form where it saves to a CPT: <!-- wp:navigation { "id": 1 } /--> Maybe that's in conjunction with an in-memory entity. The in-memory experience serializes from/to the first form of the block, the persisted experience serializes from/to the second. |
94415c6
to
6e8aecd
Compare
Size Change: +883 B (0%) Total Size: 1.1 MB
ℹ️ View Unchanged
|
This PR is almost 1 years old and I moved on to other tasks since then so I'm closing it. If you could use the changes proposed here, feel free to pick up this PR! cc @draganescu @getdave @scruffian @MaggieCabrera – I wonder if that would be relevant for your work on theme switching. |
See #36524
CC @getdave @noisysocks @anton-vlasenko @mtias @gziolo @draganescu