Make WordPress Core


Ignore:
Timestamp:
09/14/2023 01:23:13 PM (10 months ago)
Author:
Bernhard Reiter
Message:

General: Add block_hooks field to block type registration, REST API.

In order to implement Block Hooks, we need to add a new block_hooks field to the WP_Block_Type class, as well as to block registration related functions, the block types REST API controller, etc.

Props gziolo.
Fixes #59346. See #59313.

File:
1 edited

Legend:

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

    r56548 r56587  
    196196     * @ticket 47620
    197197     * @ticket 57585
     198     * @ticket 59346
    198199     */
    199200    public function test_get_item_invalid() {
     
    206207            'provides_context' => 'invalid_provides_context',
    207208            'uses_context'     => 'invalid_uses_context',
     209            'block_hooks'      => 'invalid_block_hooks',
    208210            'category'         => true,
    209211            'editor_script'    => true,
     
    245247        );
    246248        $this->assertSameSets( array( 'invalid_uses_context' ), $data['uses_context'] );
     249        $this->assertSameSets( array(), $data['block_hooks'], 'invalid block_hooks defaults to empty array' );
    247250        $this->assertSameSets( array( 'invalid_keywords' ), $data['keywords'] );
    248251        $this->assertSameSets( array( 'invalid_parent' ), $data['parent'] );
     
    267270     * @ticket 47620
    268271     * @ticket 57585
     272     * @ticket 59346
    269273     */
    270274    public function test_get_item_defaults() {
     
    277281            'provides_context' => false,
    278282            'uses_context'     => false,
     283            'block_hooks'      => false,
    279284            'category'         => false,
    280285            'editor_script'    => false,
     
    315320        );
    316321        $this->assertSameSets( array(), $data['provides_context'] );
     322        $this->assertSameSets( array(), $data['block_hooks'], 'block_hooks defaults to empty array' );
    317323        $this->assertSameSets( array(), $data['uses_context'] );
    318324        $this->assertSameSets( array(), $data['keywords'] );
     
    539545     * @ticket 47620
    540546     * @ticket 57585
     547     * @ticket 59346
    541548     */
    542549    public function test_get_item_schema() {
     
    546553        $data       = $response->get_data();
    547554        $properties = $data['schema']['properties'];
    548         $this->assertCount( 29, $properties );
     555        $this->assertCount( 30, $properties );
    549556        $this->assertArrayHasKey( 'api_version', $properties );
    550557        $this->assertArrayHasKey( 'title', $properties );
     
    569576        $this->assertArrayHasKey( 'uses_context', $properties );
    570577        $this->assertArrayHasKey( 'provides_context', $properties );
     578        $this->assertArrayHasKey( 'block_hooks', $properties );
    571579        $this->assertArrayHasKey( 'variations', $properties );
    572580        $this->assertArrayHasKey( 'ancestor', $properties );
     
    665673     *
    666674     * @since 5.5.0
     675     * @since 6.4.0 Added the `block_hooks` extra field.
    667676     *
    668677     * @param WP_Block_Type $block_type Sample block type.
     
    691700            'provides_context',
    692701            'uses_context',
     702            'block_hooks',
    693703            'supports',
    694704            'styles',
Note: See TracChangeset for help on using the changeset viewer.