Skip to content

Commit

Permalink
Try making server aware of block variants
Browse files Browse the repository at this point in the history
  • Loading branch information
gwwar committed Feb 17, 2021
1 parent e794cb2 commit 85701d9
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/wp-admin/includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -2254,6 +2254,7 @@ function get_block_editor_server_block_settings() {
'parent' => 'parent',
'keywords' => 'keywords',
'example' => 'example',
'variations' => 'variations',
);

foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) {
Expand Down
1 change: 1 addition & 0 deletions src/wp-includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) {
'styles' => 'styles',
'example' => 'example',
'apiVersion' => 'api_version',
'variations' => 'variations',
);

foreach ( $property_mappings as $key => $mapped_key ) {
Expand Down
5 changes: 5 additions & 0 deletions src/wp-includes/class-wp-block-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ class WP_Block_Type {
*/
public $styles = array();

/**
* @var array
*/
public $variations = array();

/**
* @since 5.5.0
* @var array|null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,59 @@ public function get_item_schema() {
'context' => array( 'embed', 'view', 'edit' ),
'readonly' => true,
),
'variations' => array(
'description' => __( 'Block variations.' ),
'type' => 'array',
'items' => array(
'type' => 'object',
'properties' => array(
'name' => array(
'description' => __( 'The unique and machine-readable name.' ),
'type' => 'string',
'required' => true,
),
'title' => array(
'description' => __( 'A human-readable variation title.' ),
'type' => 'string',
'required' => true,
),
'description' => array(
'description' => __( 'A detailed variation description.' ),
'type' => 'string',
'required' => false,
),
'category' => array(
'description' => __( 'Block type category classification, used in search interfaces to arrange block types by category.' ),
'type' => 'string',
'required' => false,
),
'icon' => array(
'description' => __( 'An icon helping to visualize the variation.' ),
'type' => array( 'string', 'null' ),
'required' => false,
),
'isDefault' => array(
'description' => __( 'Indicates whether the current variation is the default one. Defaults to `false`' ),
'type' => 'boolean',
'required' => false,
'default' => false,
),
'attributes' => array(
'description' => __( 'Block attributes.' ),
'type' => array( 'object', 'null' ),
'properties' => array(),
'default' => null,
'additionalProperties' => array(
'type' => 'object',
),
),
//TODO: innerBlocks, example, scope, keywords, isActive
),
),
'readonly' => true,
'context' => array( 'embed', 'view', 'edit' ),
'default' => array(),
),
'textdomain' => array(
'description' => __( 'Public text domain.' ),
'type' => array( 'string', 'null' ),
Expand Down

0 comments on commit 85701d9

Please sign in to comment.