Make WordPress Core

Changeset 53084


Ignore:
Timestamp:
04/06/2022 09:45:31 AM (3 years ago)
Author:
gziolo
Message:

Editor: Make block type aware of the ancestor field

The ancestor field was recently added to the block.json schema in Gutenberg. See: https://github.com/WordPress/gutenberg/pull/39894.

Props darerodz.
Fixes #55531.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/post.php

    r53056 r53084  
    22332233        'textdomain'       => 'textdomain',
    22342234        'parent'           => 'parent',
     2235        'ancestor'         => 'ancestor',
    22352236        'keywords'         => 'keywords',
    22362237        'example'          => 'example',
  • trunk/src/wp-includes/class-wp-block-type.php

    r52652 r53084  
    6060
    6161    /**
     62     * Setting ancestor makes a block available only inside the specified
     63     * block types at any position of the ancestor's block subtree.
     64     *
     65     * @since 6.0.0
     66     * @var array|null
     67     */
     68    public $ancestor = null;
     69
     70    /**
    6271     * Block type icon.
    6372     *
     
    208217     * @since 5.8.0 Added the `variations` property.
    209218     * @since 5.9.0 Added the `view_script` property.
     219     * @since 6.0.0 Added the `ancestor` property.
    210220     *
    211221     * @see register_block_type()
     
    222232     *     @type array|null    $parent           Setting parent lets a block require that it is only
    223233     *                                           available when nested within the specified blocks.
     234     *     @type array|null    $ancestor         Setting ancestor makes a block available only inside the specified
     235     *                                           block types at any position of the ancestor's block subtree.
    224236     *     @type string|null   $icon             Block type icon.
    225237     *     @type string        $description      A detailed block type description.
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php

    r51786 r53084  
    267267            'keywords',
    268268            'parent',
     269            'ancestor',
    269270            'provides_context',
    270271            'uses_context',
     
    646647                    'readonly'    => true,
    647648                ),
     649                'ancestor'           => array(
     650                    'description' => __( 'Ancestor blocks.' ),
     651                    'type'        => array( 'array', 'null' ),
     652                    'items'       => array(
     653                        'type' => 'string',
     654                    ),
     655                    'default'     => null,
     656                    'context'     => array( 'embed', 'view', 'edit' ),
     657                    'readonly'    => true,
     658                ),
    648659                'keywords'         => $keywords_definition,
    649660                'example'          => $example_definition,
  • trunk/tests/phpunit/tests/admin/includesPost.php

    r52010 r53084  
    829829            'category'        => 'common',
    830830            'render_callback' => 'foo',
     831            'ancestor'        => array( 'core/test-ancestor' ),
    831832        );
    832833
     
    847848                'category'    => 'common',
    848849                'styles'      => array(),
     850                'ancestor'    => array( 'core/test-ancestor' ),
    849851                'keywords'    => array(),
    850852                'variations'  => array(),
  • trunk/tests/phpunit/tests/rest-api/rest-block-type-controller.php

    r51501 r53084  
    222222            'example'          => 'invalid_example',
    223223            'parent'           => 'invalid_parent',
     224            'ancestor'         => 'invalid_ancestor',
    224225            'supports'         => 'invalid_supports',
    225226            'styles'           => 'invalid_styles',
     
    247248        $this->assertSameSets( array( 'invalid_keywords' ), $data['keywords'] );
    248249        $this->assertSameSets( array( 'invalid_parent' ), $data['parent'] );
     250        $this->assertSameSets( array( 'invalid_ancestor' ), $data['ancestor'] );
    249251        $this->assertSameSets( array(), $data['supports'] );
    250252        $this->assertSameSets( array(), $data['styles'] );
     
    276278            'keywords'         => false,
    277279            'parent'           => false,
     280            'ancestor'         => false,
    278281            'supports'         => false,
    279282            'styles'           => false,
     
    302305        $this->assertSameSets( array(), $data['keywords'] );
    303306        $this->assertSameSets( array(), $data['parent'] );
     307        $this->assertSameSets( array(), $data['ancestor'] );
    304308        $this->assertSameSets( array(), $data['supports'] );
    305309        $this->assertSameSets( array(), $data['styles'] );
     
    379383        $data       = $response->get_data();
    380384        $properties = $data['schema']['properties'];
    381         $this->assertCount( 22, $properties );
     385        $this->assertCount( 23, $properties );
    382386        $this->assertArrayHasKey( 'api_version', $properties );
    383387        $this->assertArrayHasKey( 'title', $properties );
     
    402406        $this->assertArrayHasKey( 'provides_context', $properties );
    403407        $this->assertArrayHasKey( 'variations', $properties );
     408        $this->assertArrayHasKey( 'ancestor', $properties );
    404409    }
    405410
Note: See TracChangeset for help on using the changeset viewer.