Repository navigation
Content Type: Add menu_icon and menu_position fields
#78285
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
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 |
|---|---|---|
|
|
@@ -112,10 +112,18 @@ public static function get_config_schema() { | |
| 'type' => 'object', | ||
| 'additionalProperties' => false, | ||
| 'properties' => array( | ||
| 'public' => array( 'type' => 'boolean' ), | ||
| 'hierarchical' => array( 'type' => 'boolean' ), | ||
| 'has_archive' => array( 'type' => 'boolean' ), | ||
| 'show_in_rest' => array( 'type' => 'boolean' ), | ||
| 'public' => array( 'type' => 'boolean' ), | ||
| 'hierarchical' => array( 'type' => 'boolean' ), | ||
| 'has_archive' => array( 'type' => 'boolean' ), | ||
| 'show_in_rest' => array( 'type' => 'boolean' ), | ||
| 'menu_icon' => array( | ||
| 'type' => array( 'string', 'null' ), | ||
| ), | ||
| 'menu_position' => array( | ||
| 'type' => array( 'integer', 'null' ), | ||
| 'minimum' => 1, | ||
| 'maximum' => 100, | ||
|
Member
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. Not sure 100 should be the practical maximum here. Technically, folks can input
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. I agree we shouldn't have an upper limit if it's not enforced anywhere in PHP. Additionally we should add the same validation rules for the JS field. |
||
| ), | ||
| // Caps payload size; well above any reasonable description. | ||
| 'description' => array( | ||
| 'type' => 'string', | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -249,6 +249,46 @@ export const defaultForm: Form = { | |
| ], | ||
| }; | ||
|
|
||
| export const menuIconField: Field< PostTypeFormData > = { | ||
| id: 'menu_icon', | ||
|
Member
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. I'm noticing we don't add a max length for the menu icon field. Considering users can put in long base64 data URI blobs, this is a problematic source of problems. One way around it is to discourage data URIs and just work with either dashicons or empty icons that they can style with CSS. cc @ntsekouras who added some of the limits for the other fields - what limits would you put here?
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. For start I believe we should only start with |
||
| label: __( 'Menu icon' ), | ||
| type: 'text', | ||
| description: __( | ||
| 'Dashicon slug (e.g. "dashicons-book") or a data: URI for a custom icon shown in the admin menu.' | ||
|
Member
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. Should we use the same example of dashicon as in the placeholder? |
||
| ), | ||
| placeholder: 'dashicons-admin-post', | ||
| getValue: ( { item } ) => item.config.menu_icon ?? '', | ||
| setValue: ( { item, value } ) => ( { | ||
| config: { | ||
| ...item.config, | ||
| menu_icon: value ? String( value ) : null, | ||
| }, | ||
| } ), | ||
| filterBy: false, | ||
| enableSorting: false, | ||
| }; | ||
|
|
||
| export const menuPositionField: Field< PostTypeFormData > = { | ||
| id: 'menu_position', | ||
| label: __( 'Menu position' ), | ||
| type: 'integer', | ||
| description: __( | ||
| 'Position in the admin menu. Common values: 5 (below Posts), 10 (below Media), 20 (below Pages). Leave empty to use the default position.' | ||
| ), | ||
| getValue: ( { item } ) => item.config.menu_position ?? null, | ||
| setValue: ( { item, value } ) => ( { | ||
| config: { | ||
| ...item.config, | ||
| menu_position: | ||
| value !== '' && value !== null && value !== undefined | ||
| ? Number( value ) | ||
|
Member
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. I don't see the min/max in the REST API reflected here. We should ensure we're consistent between the UI and the REST API |
||
| : null, | ||
| }, | ||
| } ), | ||
| filterBy: false, | ||
| enableSorting: false, | ||
| }; | ||
|
|
||
| export const generalForm: Form = { | ||
| layout: { type: 'regular' }, | ||
| fields: [ | ||
|
|
@@ -262,6 +302,8 @@ export const generalForm: Form = { | |
| 'hierarchical', | ||
| 'has_archive', | ||
| 'show_in_rest', | ||
| 'menu_icon', | ||
| 'menu_position', | ||
|
Comment on lines
+305
to
+306
Member
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. I'm thinking this form is starting to get a bit cluttered and we might want to split it to multiple groups just like Taxonomies, so General will have just a few basic fields. Also, should these go right at the bottom, even bellow the status field?
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.
Agreed. Probably a |
||
| 'status', | ||
| ], | ||
| }; | ||
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 wonder if we need some special validation here. The
register_post_typedocumentation recognizes the special string'none'anddashicons-*slugs. I think a pattern (e.g. dashicons slug OR data: URI OR http(s): URL OR none) would catch typos at the REST layer, in addition to the max length limit that I'm also mentioning below.