Skip to content

Commit

Permalink
REST API: Improve the block type schema for the name field
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Sep 22, 2023
1 parent e413569 commit e00f028
Showing 1 changed file with 11 additions and 4 deletions.
Expand Up @@ -16,6 +16,8 @@
*/
class WP_REST_Block_Types_Controller extends WP_REST_Controller {

const NAME_PATTERN = '^[a-z][a-z0-9-]*/[a-z][a-z0-9-]*$';

/**
* Instance of WP_Block_Type_Registry.
*
Expand Down Expand Up @@ -402,6 +404,8 @@ public function get_item_schema() {
'name' => array(
'description' => __( 'The name of the inner block.' ),
'type' => 'string',
'pattern' => self::NAME_PATTERN,
'required' => true,
),
'attributes' => array(
'description' => __( 'The attributes of the inner block.' ),
Expand Down Expand Up @@ -479,7 +483,8 @@ public function get_item_schema() {
'name' => array(
'description' => __( 'Unique name identifying the block type.' ),
'type' => 'string',
'default' => '',
'pattern' => self::NAME_PATTERN,
'required' => true,
'context' => array( 'embed', 'view', 'edit' ),
'readonly' => true,
),
Expand Down Expand Up @@ -689,7 +694,8 @@ public function get_item_schema() {
'description' => __( 'Parent blocks.' ),
'type' => array( 'array', 'null' ),
'items' => array(
'type' => 'string',
'type' => 'string',
'pattern' => self::NAME_PATTERN,
),
'default' => null,
'context' => array( 'embed', 'view', 'edit' ),
Expand All @@ -699,7 +705,8 @@ public function get_item_schema() {
'description' => __( 'Ancestor blocks.' ),
'type' => array( 'array', 'null' ),
'items' => array(
'type' => 'string',
'type' => 'string',
'pattern' => self::NAME_PATTERN,
),
'default' => null,
'context' => array( 'embed', 'view', 'edit' ),
Expand All @@ -711,7 +718,7 @@ public function get_item_schema() {
'description' => __( 'This block is automatically inserted near any occurence of the block types used as keys of this map, into a relative position given by the corresponding value.' ),
'type' => 'object',
'patternProperties' => array(
'^[a-zA-Z0-9-]+/[a-zA-Z0-9-]+$' => array(
self::NAME_PATTERN => array(
'type' => 'string',
'enum' => array( 'before', 'after', 'first_child', 'last_child' ),
),
Expand Down

0 comments on commit e00f028

Please sign in to comment.