Skip to content
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

Add description support for block pattern categories #3853

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ public function get_items( $request ) {
*/
public function prepare_item_for_response( $item, $request ) {
$fields = $this->get_fields_for_response( $request );
$keys = array( 'name', 'label' );
$keys = array( 'name', 'label', 'description' );
$data = array();
foreach ( $keys as $key ) {
if ( rest_is_field_included( $key, $fields ) ) {
if ( isset( $item[ $key ] ) && rest_is_field_included( $key, $fields ) ) {
$data[ $key ] = $item[ $key ];
}
}
Expand All @@ -130,18 +130,24 @@ public function get_item_schema() {
'title' => 'block-pattern-category',
'type' => 'object',
'properties' => array(
'name' => array(
'name' => array(
'description' => __( 'The category name.' ),
'type' => 'string',
'readonly' => true,
'context' => array( 'view', 'edit', 'embed' ),
),
'label' => array(
'label' => array(
'description' => __( 'The category label, in human readable format.' ),
'type' => 'string',
'readonly' => true,
'context' => array( 'view', 'edit', 'embed' ),
),
'description' => array(
'description' => __( 'The category description, in human readable format.' ),
'type' => 'string',
'readonly' => true,
'context' => array( 'view', 'edit', 'embed' ),
),
),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,20 @@ public static function wpSetupBeforeClass( $factory ) {
self::$registry_instance_property->setValue( $test_registry );

// Register some categories in the test registry.
$test_registry->register( 'test', array( 'label' => 'Test' ) );
$test_registry->register( 'query', array( 'label' => 'Query' ) );
$test_registry->register(
'test',
array(
'label' => 'Test',
'description' => 'Test description',
)
);
$test_registry->register(
'query',
array(
'label' => 'Query',
'description' => 'Query',
)
);
}

public static function wpTearDownAfterClass() {
Expand Down Expand Up @@ -103,10 +115,10 @@ public function test_get_items() {
wp_set_current_user( self::$admin_id );

$expected_names = array( 'test', 'query' );
$expected_fields = array( 'name', 'label' );
$expected_fields = array( 'name', 'label', 'description' );

$request = new WP_REST_Request( 'GET', static::REQUEST_ROUTE );
$request['_fields'] = 'name,label';
$request['_fields'] = 'name,label,description';
$response = rest_get_server()->dispatch( $request );
$data = $response->get_data();

Expand Down