Editor: Support the block_types and viewport_width props for remote patterns fetched from Pattern Directory.

Props ntsekouras, ironprogrammer, hellofromtonya, flixos90.
Fixes #57611.

Built from https://develop.svn.wordpress.org/trunk@55234


git-svn-id: http://core.svn.wordpress.org/trunk@54767 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Felix Arntz
2023-02-06 19:40:16 +00:00
parent 1593f0615a
commit 53c7f7a8a7
3 changed files with 54 additions and 11 deletions

View File

@@ -103,7 +103,7 @@ class WP_REST_Pattern_Directory_Controller extends WP_REST_Controller {
'search' => true,
'slug' => true,
);
$query_args = array_intersect_key( $request->get_params(), $valid_query_args );
$query_args = array_intersect_key( $request->get_params(), $valid_query_args );
$query_args['locale'] = get_user_locale();
$query_args['wp-version'] = $wp_version; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable -- it's defined in `version.php` above.
@@ -202,6 +202,7 @@ class WP_REST_Pattern_Directory_Controller extends WP_REST_Controller {
'keywords' => array_map( 'sanitize_text_field', explode( ',', $raw_pattern->meta->wpop_keywords ) ),
'description' => sanitize_text_field( $raw_pattern->meta->wpop_description ),
'viewport_width' => absint( $raw_pattern->meta->wpop_viewport_width ),
'block_types' => array_map( 'sanitize_text_field', $raw_pattern->meta->wpop_block_types ),
);
$prepared_pattern = $this->add_additional_fields_to_object( $prepared_pattern, $request );
@@ -224,6 +225,7 @@ class WP_REST_Pattern_Directory_Controller extends WP_REST_Controller {
* Retrieves the block pattern's schema, conforming to JSON Schema.
*
* @since 5.8.0
* @since 6.2.0 Added `'block_types'` to schema.
*
* @return array Item schema data.
*/
@@ -286,6 +288,14 @@ class WP_REST_Pattern_Directory_Controller extends WP_REST_Controller {
'type' => 'integer',
'context' => array( 'view', 'edit', 'embed' ),
),
'block_types' => array(
'description' => __( 'The block types which can use this pattern.' ),
'type' => 'array',
'uniqueItems' => true,
'items' => array( 'type' => 'string' ),
'context' => array( 'view', 'embed' ),
),
),
);