Make WordPress Core


Ignore:
Timestamp:
04/21/2023 10:41:58 AM (18 months ago)
Author:
gziolo
Message:

Editor: Add selectors field to block type definition

Adds support for the new selectors property for block types. It adds it to the allowed metadata when registering a block type, makes the WP_Block_Type class aware of it, exposes it through the block types REST API, and the get_block_editor_server_block_settings function.

Corresponding work in the Gutenberg plugin: https://github.com/WordPress/gutenberg/pull/46496.

Fixes #57585.
Props aaronrobertshaw, hellofromTonya.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-block-type-controller.php

    r55457 r55673  
    197197    /**
    198198     * @ticket 47620
     199     * @ticket 57585
    199200     */
    200201    public function test_get_item_invalid() {
     
    217218            'parent'           => 'invalid_parent',
    218219            'ancestor'         => 'invalid_ancestor',
     220            'selectors'        => 'invalid_selectors',
    219221            'supports'         => 'invalid_supports',
    220222            'styles'           => array(),
     
    248250        $this->assertSameSets( array( 'invalid_parent' ), $data['parent'] );
    249251        $this->assertSameSets( array( 'invalid_ancestor' ), $data['ancestor'] );
     252        $this->assertSameSets( array(), $data['selectors'], 'invalid selectors defaults to empty array' );
    250253        $this->assertSameSets( array(), $data['supports'] );
    251254        $this->assertSameSets( array(), $data['styles'] );
     
    266269    /**
    267270     * @ticket 47620
     271     * @ticket 57585
    268272     */
    269273    public function test_get_item_defaults() {
     
    285289            'parent'           => false,
    286290            'ancestor'         => false,
     291            'selectors'        => false,
    287292            'supports'         => false,
    288293            'styles'           => false,
     
    317322        $this->assertSameSets( array(), $data['parent'] );
    318323        $this->assertSameSets( array(), $data['ancestor'] );
     324        $this->assertSameSets( array(), $data['selectors'], 'selectors defaults to empty array' );
    319325        $this->assertSameSets( array(), $data['supports'] );
    320326        $this->assertSameSets( array(), $data['styles'] );
     
    535541    /**
    536542     * @ticket 47620
     543     * @ticket 57585
    537544     */
    538545    public function test_get_item_schema() {
     
    542549        $data       = $response->get_data();
    543550        $properties = $data['schema']['properties'];
    544         $this->assertCount( 28, $properties );
     551        $this->assertCount( 29, $properties );
    545552        $this->assertArrayHasKey( 'api_version', $properties );
    546553        $this->assertArrayHasKey( 'title', $properties );
     
    552559        $this->assertArrayHasKey( 'name', $properties );
    553560        $this->assertArrayHasKey( 'attributes', $properties );
     561        $this->assertArrayHasKey( 'selectors', $properties, 'schema must contain selectors' );
    554562        $this->assertArrayHasKey( 'supports', $properties );
    555563        $this->assertArrayHasKey( 'category', $properties );
Note: See TracChangeset for help on using the changeset viewer.