diff --git a/lib/compat/wordpress-6.0/class-wp-rest-block-patterns-controller.php b/lib/compat/wordpress-6.0/class-wp-rest-block-patterns-controller.php index 33d3076c1be51d..a73660f1342658 100644 --- a/lib/compat/wordpress-6.0/class-wp-rest-block-patterns-controller.php +++ b/lib/compat/wordpress-6.0/class-wp-rest-block-patterns-controller.php @@ -113,19 +113,19 @@ public function get_items( $request ) { // phpcs:ignore VariableAnalysis.CodeAna public function prepare_item_for_response( $item, $request ) { $fields = $this->get_fields_for_response( $request ); $keys = array( - 'name', - 'title', - 'description', - 'viewportWidth', - 'blockTypes', - 'categories', - 'keywords', - 'content', + 'name' => 'name', + 'title' => 'title', + 'description' => 'description', + 'viewportWidth' => 'viewport_width', + 'blockTypes' => 'block_types', + 'categories' => 'categories', + 'keywords' => 'keywords', + 'content' => 'content', ); $data = array(); - foreach ( $keys as $key ) { - if ( isset( $item[ $key ] ) && rest_is_field_included( $key, $fields ) ) { - $data[ $key ] = $item[ $key ]; + foreach ( $keys as $item_key => $rest_key ) { + if ( isset( $item[ $item_key ] ) && rest_is_field_included( $rest_key, $fields ) ) { + $data[ $rest_key ] = $item[ $item_key ]; } } @@ -148,49 +148,49 @@ public function get_item_schema() { 'title' => 'block-pattern', 'type' => 'object', 'properties' => array( - 'name' => array( + 'name' => array( 'description' => __( 'The pattern name.', 'gutenberg' ), 'type' => 'string', 'readonly' => true, 'context' => array( 'view', 'embed' ), ), - 'title' => array( + 'title' => array( 'description' => __( 'The pattern title, in human readable format.', 'gutenberg' ), 'type' => 'string', 'readonly' => true, 'context' => array( 'view', 'embed' ), ), - 'description' => array( + 'description' => array( 'description' => __( 'The pattern detailed description.', 'gutenberg' ), 'type' => 'string', 'readonly' => true, 'context' => array( 'view', 'embed' ), ), - 'viewportWidth' => array( + 'viewport_width' => array( 'description' => __( 'The pattern viewport width for inserter preview.', 'gutenberg' ), 'type' => 'number', 'readonly' => true, 'context' => array( 'view', 'embed' ), ), - 'blockTypes' => array( + 'block_types' => array( 'description' => __( 'Block types that the pattern is intended to be used with.', 'gutenberg' ), 'type' => 'array', 'readonly' => true, 'context' => array( 'view', 'embed' ), ), - 'categories' => array( + 'categories' => array( 'description' => __( 'The pattern category slugs.', 'gutenberg' ), 'type' => 'array', 'readonly' => true, 'context' => array( 'view', 'embed' ), ), - 'keywords' => array( + 'keywords' => array( 'description' => __( 'The pattern keywords.', 'gutenberg' ), 'type' => 'array', 'readonly' => true, 'context' => array( 'view', 'embed' ), ), - 'content' => array( + 'content' => array( 'description' => __( 'The pattern content.', 'gutenberg' ), 'type' => 'string', 'readonly' => true, diff --git a/packages/core-data/src/resolvers.js b/packages/core-data/src/resolvers.js index 481f63445efef0..830d9ca97bb0f7 100644 --- a/packages/core-data/src/resolvers.js +++ b/packages/core-data/src/resolvers.js @@ -1,7 +1,7 @@ /** * External dependencies */ -import { find, includes, get, compact, uniq } from 'lodash'; +import { find, includes, get, compact, uniq, map, mapKeys } from 'lodash'; /** * WordPress dependencies @@ -455,9 +455,21 @@ export const __experimentalGetCurrentThemeGlobalStylesVariations = () => async ( }; export const getBlockPatterns = () => async ( { dispatch } ) => { - const patterns = await apiFetch( { + const restPatterns = await apiFetch( { path: '/wp/v2/block-patterns/patterns', } ); + const patterns = map( restPatterns, ( pattern ) => + mapKeys( pattern, ( value, key ) => { + switch ( key ) { + case 'block_types': + return 'blockTypes'; + case 'viewport_width': + return 'viewportWidth'; + default: + return key; + } + } ) + ); dispatch( { type: 'RECEIVE_BLOCK_PATTERNS', patterns } ); };