Make WordPress Core


Ignore:
Timestamp:
02/13/2024 03:10:21 PM (4 months ago)
Author:
Bernhard Reiter
Message:

Block Hooks: Set ignoredHookedBlocks metadata upon saving.

Decouple hooked blocks insertion from setting the metadata.ignoredHookedBlocks attribute on anchor blocks, and perform the latter step upon saving a template or template part to the database. This ensures that anchor blocks that have been newly added to a template (or part) on the client side will also get ignoredHookedBlocks metadata set correctly, thus preserving editor/front-end parity. Hooked block insertion, on the other hand, will continue to happen upon reading a template (or part).

Props gziolo, tomjcafferkey.
Fixes #60506.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/blocks/insertHookedBlocks.php

    r57354 r57627  
    2626     * @ticket 59572
    2727     * @ticket 60126
     28     * @ticket 60506
    2829     *
    2930     * @covers ::insert_hooked_blocks
    3031     */
    31     public function test_insert_hooked_blocks_adds_metadata() {
     32    public function test_insert_hooked_blocks_returns_correct_markup() {
    3233        $anchor_block = array(
    3334            'blockName' => self::ANCHOR_BLOCK_TYPE,
     
    3536
    3637        $actual = insert_hooked_blocks( $anchor_block, 'after', self::HOOKED_BLOCKS, array() );
    37         $this->assertSame(
    38             array( self::HOOKED_BLOCK_TYPE ),
    39             $anchor_block['attrs']['metadata']['ignoredHookedBlocks'],
    40             "Hooked block type wasn't added to ignoredHookedBlocks metadata."
    41         );
    4238        $this->assertSame(
    4339            '<!-- wp:' . self::HOOKED_BLOCK_TYPE . ' /-->',
     
    5046     * @ticket 59572
    5147     * @ticket 60126
     48     * @ticket 60506
    5249     *
    5350     * @covers ::insert_hooked_blocks
    5451     */
    55     public function test_insert_hooked_blocks_if_block_is_already_hooked() {
     52    public function test_insert_hooked_blocks_if_block_is_ignored() {
    5653        $anchor_block = array(
    5754            'blockName' => 'tests/anchor-block',
     
    6562        $actual = insert_hooked_blocks( $anchor_block, 'after', self::HOOKED_BLOCKS, array() );
    6663        $this->assertSame(
    67             array( self::HOOKED_BLOCK_TYPE ),
    68             $anchor_block['attrs']['metadata']['ignoredHookedBlocks'],
    69             "ignoredHookedBlocks metadata shouldn't have been modified."
    70         );
    71         $this->assertSame(
    7264            '',
    7365            $actual,
     
    7971     * @ticket 59572
    8072     * @ticket 60126
     73     * @ticket 60506
    8174     *
    8275     * @covers ::insert_hooked_blocks
    8376     */
    84     public function test_insert_hooked_blocks_adds_to_ignored_hooked_blocks() {
     77    public function test_insert_hooked_blocks_if_other_block_is_ignored() {
    8578        $anchor_block = array(
    8679            'blockName' => 'tests/anchor-block',
     
    9487        $actual = insert_hooked_blocks( $anchor_block, 'before', self::HOOKED_BLOCKS, array() );
    9588        $this->assertSame(
    96             array( self::HOOKED_BLOCK_TYPE, self::OTHER_HOOKED_BLOCK_TYPE ),
    97             $anchor_block['attrs']['metadata']['ignoredHookedBlocks'],
    98             "Newly hooked block should've been added to ignoredHookedBlocks metadata while retaining previously ignored one."
    99         );
    100         $this->assertSame(
    10189            '<!-- wp:' . self::OTHER_HOOKED_BLOCK_TYPE . ' /-->',
    10290            $actual,
     
    10896     * @ticket 59572
    10997     * @ticket 60126
     98     * @ticket 60506
    11099     *
    111100     * @covers ::insert_hooked_blocks
     
    141130
    142131        $this->assertSame(
    143             array( self::HOOKED_BLOCK_TYPE ),
    144             $anchor_block['attrs']['metadata']['ignoredHookedBlocks'],
    145             "Hooked block type wasn't added to ignoredHookedBlocks metadata."
    146         );
    147         $this->assertSame(
    148132            '<!-- wp:' . self::HOOKED_BLOCK_TYPE . ' {"layout":{"type":"constrained"}} /-->',
    149133            $actual,
     
    155139     * @ticket 59572
    156140     * @ticket 60126
     141     * @ticket 60506
    157142     *
    158143     * @covers ::insert_hooked_blocks
     
    191176
    192177        $this->assertSame(
    193             array( self::HOOKED_BLOCK_TYPE ),
    194             $anchor_block['attrs']['metadata']['ignoredHookedBlocks'],
    195             "Hooked block type wasn't added to ignoredHookedBlocks metadata."
    196         );
    197         $this->assertSame(
    198178            '<!-- wp:group --><div class="wp-block-group"><!-- wp:' . self::HOOKED_BLOCK_TYPE . ' /--></div><!-- /wp:group -->',
    199179            $actual,
Note: See TracChangeset for help on using the changeset viewer.