Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add icon to types controller
  • Loading branch information
ntsekouras authored and hellofromtonya committed Sep 20, 2022
commit a416a0aaa1cf9378cd2ac8bb86e3f406e737f54c
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ public function prepare_item_for_response( $item, $request ) {
$data['slug'] = $post_type->name;
}

if ( in_array( 'icon', $fields, true ) ) {
$data['icon'] = $post_type->menu_icon;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this value is null, should it maybe default to something?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's okay to be null since it's not required and the consumers can decide what to do with it. For example in php core for post types we assign some default icon if it's in the admin menu, but in the site editor we assign different default icon..

}

if ( in_array( 'supports', $fields, true ) ) {
$data['supports'] = $supports;
}
Expand Down Expand Up @@ -287,6 +291,7 @@ protected function prepare_links( $post_type ) {
* @since 4.7.0
* @since 4.8.0 The `supports` property was added.
* @since 5.9.0 The `visibility` and `rest_namespace` properties were added.
* @since 6.1.0 The `icon` property was added.
*
* @return array Item schema data.
*/
Expand Down Expand Up @@ -385,6 +390,12 @@ public function get_item_schema() {
),
),
),
'icon' => array(
'description' => __( 'The icon for the post type.' ),
'type' => 'string',
'context' => array( 'view', 'edit', 'embed' ),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be in the view context? The icon is not public right now?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean public? I think it would be good to have in view as it can be useful in some cases. Do you see any drawback being in view context?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you make a property as view it means it can't be viewed pubilically. Do we want to expose this data publically?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no harm in it, but if you have a strong opinion on this, I can remove it.

'readonly' => true,
),
),
);

Expand Down