Skip to content

Commit 48342a2

Browse files
committed
Editor: Allow block pattern categories to have descriptions.
Updates the corresponding REST API endpoint and unit test. Fixes #57478. git-svn-id: https://develop.svn.wordpress.org/trunk@55097 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 134c05d commit 48342a2

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

src/wp-includes/rest-api/endpoints/class-wp-rest-block-pattern-categories-controller.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ public function get_items( $request ) {
102102
*/
103103
public function prepare_item_for_response( $item, $request ) {
104104
$fields = $this->get_fields_for_response( $request );
105-
$keys = array( 'name', 'label' );
105+
$keys = array( 'name', 'label', 'description' );
106106
$data = array();
107107
foreach ( $keys as $key ) {
108-
if ( rest_is_field_included( $key, $fields ) ) {
108+
if ( isset( $item[ $key ] ) && rest_is_field_included( $key, $fields ) ) {
109109
$data[ $key ] = $item[ $key ];
110110
}
111111
}
@@ -130,18 +130,24 @@ public function get_item_schema() {
130130
'title' => 'block-pattern-category',
131131
'type' => 'object',
132132
'properties' => array(
133-
'name' => array(
133+
'name' => array(
134134
'description' => __( 'The category name.' ),
135135
'type' => 'string',
136136
'readonly' => true,
137137
'context' => array( 'view', 'edit', 'embed' ),
138138
),
139-
'label' => array(
139+
'label' => array(
140140
'description' => __( 'The category label, in human readable format.' ),
141141
'type' => 'string',
142142
'readonly' => true,
143143
'context' => array( 'view', 'edit', 'embed' ),
144144
),
145+
'description' => array(
146+
'description' => __( 'The category description, in human readable format.' ),
147+
'type' => 'string',
148+
'readonly' => true,
149+
'context' => array( 'view', 'edit', 'embed' ),
150+
),
145151
),
146152
);
147153

tests/phpunit/tests/rest-api/wpRestBlockPatternCategoriesController.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,20 @@ public static function wpSetupBeforeClass( $factory ) {
7474
self::$registry_instance_property->setValue( $test_registry );
7575

7676
// Register some categories in the test registry.
77-
$test_registry->register( 'test', array( 'label' => 'Test' ) );
78-
$test_registry->register( 'query', array( 'label' => 'Query' ) );
77+
$test_registry->register(
78+
'test',
79+
array(
80+
'label' => 'Test',
81+
'description' => 'Test description',
82+
)
83+
);
84+
$test_registry->register(
85+
'query',
86+
array(
87+
'label' => 'Query',
88+
'description' => 'Query',
89+
)
90+
);
7991
}
8092

8193
public static function wpTearDownAfterClass() {
@@ -103,10 +115,10 @@ public function test_get_items() {
103115
wp_set_current_user( self::$admin_id );
104116

105117
$expected_names = array( 'test', 'query' );
106-
$expected_fields = array( 'name', 'label' );
118+
$expected_fields = array( 'name', 'label', 'description' );
107119

108120
$request = new WP_REST_Request( 'GET', static::REQUEST_ROUTE );
109-
$request['_fields'] = 'name,label';
121+
$request['_fields'] = 'name,label,description';
110122
$response = rest_get_server()->dispatch( $request );
111123
$data = $response->get_data();
112124

0 commit comments

Comments
 (0)