Make WordPress Core


Ignore:
Timestamp:
07/02/2024 10:01:17 AM (2 years ago)
Author:
Bernhard Reiter
Message:

Block Hooks: Allow child insertion into Template Part block.

The Block Hooks mechanism was previously extended to allow insertion of a block as a Navigation block's first or last child. This was implemented by storing the ignoredHookedBlocks array in the corresponding wp_navigation post's post meta (instead of a metadata attribute on the anchor block).

This changeset extends that mechanism to Template Part blocks, by storing said metadata in the corresponding wp_template_part post's post meta, thus allowing extenders to use Block Hooks to insert a block as a Template Part block's first or last child, respectively.

Props tomjcafferkey, bernhard-reiter.
Fixes #60854.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/block-templates/buildBlockTemplateResultFromPost.php

    r57627 r58614  
    112112        }
    113113
     114        /*
     115         * @ticket 59646
     116         * @ticket 60506
     117         * @ticket 60854
     118         */
     119        public function test_should_injected_hooked_block_into_template_part_first_child() {
     120                register_block_type(
     121                        'tests/my-block',
     122                        array(
     123                                'block_hooks' => array(
     124                                        'core/template-part' => 'first_child',
     125                                ),
     126                        )
     127                );
     128
     129                $template_part = _build_block_template_result_from_post(
     130                        self::$template_part_post,
     131                        'wp_template_part'
     132                );
     133                $this->assertStringStartsWith( '<!-- wp:tests/my-block /-->', $template_part->content );
     134        }
     135
     136        /*
     137         * @ticket 59646
     138         * @ticket 60506
     139         * @ticket 60854
     140         */
     141        public function test_should_injected_hooked_block_into_template_part_last_child() {
     142                register_block_type(
     143                        'tests/my-block',
     144                        array(
     145                                'block_hooks' => array(
     146                                        'core/template-part' => 'last_child',
     147                                ),
     148                        )
     149                );
     150
     151                $template_part = _build_block_template_result_from_post(
     152                        self::$template_part_post,
     153                        'wp_template_part'
     154                );
     155                $this->assertStringEndsWith( '<!-- wp:tests/my-block /-->', $template_part->content );
     156        }
     157
    114158        /**
    115159         * @ticket 59646
Note: See TracChangeset for help on using the changeset viewer.