<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[56587] trunk: General: Add `block_hooks` field to block type registration, REST API.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/56587">56587</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/56587","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>Bernhard Reiter</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2023-09-14 13:23:13 +0000 (Thu, 14 Sep 2023)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>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 <a href="https://core.trac.wordpress.org/ticket/59346">#59346</a>. See <a href="https://core.trac.wordpress.org/ticket/59313">#59313</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminincludespostphp">trunk/src/wp-admin/includes/post.php</a></li>
<li><a href="#trunksrcwpincludesblocksphp">trunk/src/wp-includes/blocks.php</a></li>
<li><a href="#trunksrcwpincludesclasswpblocktypephp">trunk/src/wp-includes/class-wp-block-type.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestblocktypescontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php</a></li>
<li><a href="#trunktestsphpunitdatablocksnoticeblockjson">trunk/tests/phpunit/data/blocks/notice/block.json</a></li>
<li><a href="#trunktestsphpunittestsadminincludesPostphp">trunk/tests/phpunit/tests/admin/includesPost.php</a></li>
<li><a href="#trunktestsphpunittestsblocksregisterphp">trunk/tests/phpunit/tests/blocks/register.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestblocktypecontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-block-type-controller.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminincludespostphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/post.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/post.php      2023-09-14 12:44:23 UTC (rev 56586)
+++ trunk/src/wp-admin/includes/post.php        2023-09-14 13:23:13 UTC (rev 56587)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2207,6 +2207,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 5.0.0
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 6.3.0 Added `selectors` field.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 6.4.0 Added `block_hooks` field.
</ins><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @return array An associative array of registered block data.
</span><span class="cx" style="display: block; padding: 0 10px">  */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2221,6 +2222,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                'attributes'       => 'attributes',
</span><span class="cx" style="display: block; padding: 0 10px">                'provides_context' => 'providesContext',
</span><span class="cx" style="display: block; padding: 0 10px">                'uses_context'     => 'usesContext',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                'block_hooks'      => 'blockHooks',
</ins><span class="cx" style="display: block; padding: 0 10px">                 'selectors'        => 'selectors',
</span><span class="cx" style="display: block; padding: 0 10px">                'supports'         => 'supports',
</span><span class="cx" style="display: block; padding: 0 10px">                'category'         => 'category',
</span></span></pre></div>
<a id="trunksrcwpincludesblocksphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/blocks.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/blocks.php  2023-09-14 12:44:23 UTC (rev 56586)
+++ trunk/src/wp-includes/blocks.php    2023-09-14 13:23:13 UTC (rev 56587)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -342,6 +342,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 5.9.0 Added support for `variations` and `viewScript` fields.
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 6.1.0 Added support for `render` field.
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 6.3.0 Added `selectors` field.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 6.4.0 Added support for `blockHooks` field.
</ins><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @param string $file_or_folder Path to the JSON file with metadata definition for
</span><span class="cx" style="display: block; padding: 0 10px">  *                               the block or path to the folder where the `block.json` file is located.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -513,6 +514,39 @@
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        if ( ! empty( $metadata['blockHooks'] ) ) {
+               /**
+                * Map camelCased position string (from block.json) to snake_cased block type position.
+                *
+                * @var array
+                */
+               $position_mappings = array(
+                       'before'     => 'before',
+                       'after'      => 'after',
+                       'firstChild' => 'first_child',
+                       'lastChild'  => 'last_child',
+               );
+
+               $settings['block_hooks'] = array();
+               foreach ( $metadata['blockHooks'] as $anchor_block_name => $position ) {
+                       // Avoid infinite recursion (hooking to itself).
+                       if ( $metadata['name'] === $anchor_block_name ) {
+                               _doing_it_wrong(
+                                       __METHOD__,
+                                       __( 'Cannot hook block to itself.', 'gutenberg' ),
+                                       '6.4.0'
+                               );
+                               continue;
+                       }
+
+                       if ( ! isset( $position_mappings[ $position ] ) ) {
+                               continue;
+                       }
+
+                       $settings['block_hooks'][ $anchor_block_name ] = $position_mappings[ $position ];
+               }
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         if ( ! empty( $metadata['render'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                $template_path = wp_normalize_path(
</span><span class="cx" style="display: block; padding: 0 10px">                        realpath(
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpblocktypephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-block-type.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-block-type.php     2023-09-14 12:44:23 UTC (rev 56586)
+++ trunk/src/wp-includes/class-wp-block-type.php       2023-09-14 13:23:13 UTC (rev 56587)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -174,6 +174,18 @@
</span><span class="cx" style="display: block; padding: 0 10px">        public $provides_context = null;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * Block hooks for this block type.
+        *
+        * A block hook is specified by a block type and a relative position.
+        * The hooked block will be automatically inserted in the given position
+        * next to the "anchor" block whenever the latter is encountered.
+        *
+        * @since 6.4.0
+        * @var array[]
+        */
+       public $block_hooks = array();
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * Block type editor only script handles.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 6.1.0
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -254,6 +266,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         *              `editor_style_handles`, and `style_handles` properties.
</span><span class="cx" style="display: block; padding: 0 10px">         *              Deprecated the `editor_script`, `script`, `view_script`, `editor_style`, and `style` properties.
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 6.3.0 Added the `selectors` property.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @since 6.4.0 Added the `block_hooks` property.
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><span class="cx" style="display: block; padding: 0 10px">         * @see register_block_type()
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -284,6 +297,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         *     @type array|null    $attributes               Block type attributes property schemas.
</span><span class="cx" style="display: block; padding: 0 10px">         *     @type string[]      $uses_context             Context values inherited by blocks of this type.
</span><span class="cx" style="display: block; padding: 0 10px">         *     @type string[]|null $provides_context         Context provided by blocks of this type.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         *     @type array[]       $block_hooks              Block hooks.
</ins><span class="cx" style="display: block; padding: 0 10px">          *     @type string[]      $editor_script_handles    Block type editor only script handles.
</span><span class="cx" style="display: block; padding: 0 10px">         *     @type string[]      $script_handles           Block type front end and editor script handles.
</span><span class="cx" style="display: block; padding: 0 10px">         *     @type string[]      $view_script_handles      Block type front end only script handles.
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestblocktypescontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php 2023-09-14 12:44:23 UTC (rev 56586)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php   2023-09-14 13:23:13 UTC (rev 56587)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -291,6 +291,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'editor_style_handles',
</span><span class="cx" style="display: block; padding: 0 10px">                                'style_handles',
</span><span class="cx" style="display: block; padding: 0 10px">                                'variations',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'block_hooks',
</ins><span class="cx" style="display: block; padding: 0 10px">                         ),
</span><span class="cx" style="display: block; padding: 0 10px">                        $deprecated_fields
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -706,6 +707,19 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                ),
</span><span class="cx" style="display: block; padding: 0 10px">                                'keywords'              => $keywords_definition,
</span><span class="cx" style="display: block; padding: 0 10px">                                'example'               => $example_definition,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'block_hooks'           => array(
+                                       'description'       => __( 'This block is automatically inserted near any occurence of the block types used as keys of this map, into a relative position given by the corresponding value.' ),
+                                       'type'              => 'object',
+                                       'patternProperties' => array(
+                                               '^[a-zA-Z0-9-]+/[a-zA-Z0-9-]+$' => array(
+                                                       'type' => 'string',
+                                                       'enum' => array( 'before', 'after', 'first_child', 'last_child' ),
+                                               ),
+                                       ),
+                                       'default'           => array(),
+                                       'context'           => array( 'embed', 'view', 'edit' ),
+                                       'readonly'          => true,
+                               ),
</ins><span class="cx" style="display: block; padding: 0 10px">                         ),
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="trunktestsphpunitdatablocksnoticeblockjson"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/data/blocks/notice/block.json</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/blocks/notice/block.json 2023-09-14 12:44:23 UTC (rev 56586)
+++ trunk/tests/phpunit/data/blocks/notice/block.json   2023-09-14 13:23:13 UTC (rev 56587)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -30,6 +30,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">        "selectors": {
</span><span class="cx" style="display: block; padding: 0 10px">                "root": ".wp-block-notice"
</span><span class="cx" style="display: block; padding: 0 10px">        },
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        "blockHooks": {
+               "core/post-content": "before"
+       },
</ins><span class="cx" style="display: block; padding: 0 10px">         "supports": {
</span><span class="cx" style="display: block; padding: 0 10px">                "align": true,
</span><span class="cx" style="display: block; padding: 0 10px">                "lightBlockWrapper": true
</span></span></pre></div>
<a id="trunktestsphpunittestsadminincludesPostphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/admin/includesPost.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/admin/includesPost.php  2023-09-14 12:44:23 UTC (rev 56586)
+++ trunk/tests/phpunit/tests/admin/includesPost.php    2023-09-14 13:23:13 UTC (rev 56587)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -918,6 +918,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'render_callback' => 'foo',
</span><span class="cx" style="display: block; padding: 0 10px">                        'ancestor'        => array( 'core/test-ancestor' ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'selectors'       => array( 'root' => '.wp-block-test' ),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        'block_hooks'     => array( 'core/post-content' => 'before' ),
</ins><span class="cx" style="display: block; padding: 0 10px">                 );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                register_block_type( $name, $settings );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -937,6 +938,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                        'lock' => array( 'type' => 'object' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                ),
</span><span class="cx" style="display: block; padding: 0 10px">                                'usesContext' => array(),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'blockHooks'  => array( 'core/post-content' => 'before' ),
</ins><span class="cx" style="display: block; padding: 0 10px">                                 'selectors'   => array( 'root' => '.wp-block-test' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                'category'    => 'common',
</span><span class="cx" style="display: block; padding: 0 10px">                                'styles'      => array(),
</span></span></pre></div>
<a id="trunktestsphpunittestsblocksregisterphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/blocks/register.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/blocks/register.php     2023-09-14 12:44:23 UTC (rev 56586)
+++ trunk/tests/phpunit/tests/blocks/register.php       2023-09-14 13:23:13 UTC (rev 56587)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -644,7 +644,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $result->selectors,
</span><span class="cx" style="display: block; padding: 0 10px">                        'Block type should contain selectors from metadata.'
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                // @ticket 59346
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertSame(
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        array( 'core/post-content' => 'before' ),
+                       $result->block_hooks,
+                       'Block type should contain block hooks from metadata.'
+               );
+               $this->assertSame(
</ins><span class="cx" style="display: block; padding: 0 10px">                         array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'align'             => true,
</span><span class="cx" style="display: block; padding: 0 10px">                                'lightBlockWrapper' => true,
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestblocktypecontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-block-type-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-block-type-controller.php 2023-09-14 12:44:23 UTC (rev 56586)
+++ trunk/tests/phpunit/tests/rest-api/rest-block-type-controller.php   2023-09-14 13:23:13 UTC (rev 56587)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -195,6 +195,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 47620
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 57585
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @ticket 59346
</ins><span class="cx" style="display: block; padding: 0 10px">          */
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_get_item_invalid() {
</span><span class="cx" style="display: block; padding: 0 10px">                $block_type = 'fake/invalid';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -205,6 +206,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'attributes'       => 'invalid_attributes',
</span><span class="cx" style="display: block; padding: 0 10px">                        'provides_context' => 'invalid_provides_context',
</span><span class="cx" style="display: block; padding: 0 10px">                        'uses_context'     => 'invalid_uses_context',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        'block_hooks'      => 'invalid_block_hooks',
</ins><span class="cx" style="display: block; padding: 0 10px">                         'category'         => true,
</span><span class="cx" style="display: block; padding: 0 10px">                        'editor_script'    => true,
</span><span class="cx" style="display: block; padding: 0 10px">                        'script'           => true,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -244,6 +246,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $data['attributes']
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSameSets( array( 'invalid_uses_context' ), $data['uses_context'] );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $this->assertSameSets( array(), $data['block_hooks'], 'invalid block_hooks defaults to empty array' );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertSameSets( array( 'invalid_keywords' ), $data['keywords'] );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSameSets( array( 'invalid_parent' ), $data['parent'] );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSameSets( array( 'invalid_ancestor' ), $data['ancestor'] );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -266,6 +269,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 47620
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 57585
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @ticket 59346
</ins><span class="cx" style="display: block; padding: 0 10px">          */
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_get_item_defaults() {
</span><span class="cx" style="display: block; padding: 0 10px">                $block_type = 'fake/false';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -276,6 +280,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'attributes'       => false,
</span><span class="cx" style="display: block; padding: 0 10px">                        'provides_context' => false,
</span><span class="cx" style="display: block; padding: 0 10px">                        'uses_context'     => false,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        'block_hooks'      => false,
</ins><span class="cx" style="display: block; padding: 0 10px">                         'category'         => false,
</span><span class="cx" style="display: block; padding: 0 10px">                        'editor_script'    => false,
</span><span class="cx" style="display: block; padding: 0 10px">                        'script'           => false,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -314,6 +319,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $data['attributes']
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSameSets( array(), $data['provides_context'] );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $this->assertSameSets( array(), $data['block_hooks'], 'block_hooks defaults to empty array' );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertSameSets( array(), $data['uses_context'] );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSameSets( array(), $data['keywords'] );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSameSets( array(), $data['parent'] );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -538,6 +544,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 47620
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 57585
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @ticket 59346
</ins><span class="cx" style="display: block; padding: 0 10px">          */
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_get_item_schema() {
</span><span class="cx" style="display: block; padding: 0 10px">                wp_set_current_user( self::$admin_id );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -545,7 +552,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $response   = rest_get_server()->dispatch( $request );
</span><span class="cx" style="display: block; padding: 0 10px">                $data       = $response->get_data();
</span><span class="cx" style="display: block; padding: 0 10px">                $properties = $data['schema']['properties'];
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertCount( 29, $properties );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertCount( 30, $properties );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertArrayHasKey( 'api_version', $properties );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertArrayHasKey( 'title', $properties );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertArrayHasKey( 'icon', $properties );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -568,6 +575,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertArrayHasKey( 'example', $properties );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertArrayHasKey( 'uses_context', $properties );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertArrayHasKey( 'provides_context', $properties );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $this->assertArrayHasKey( 'block_hooks', $properties );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertArrayHasKey( 'variations', $properties );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertArrayHasKey( 'ancestor', $properties );
</span><span class="cx" style="display: block; padding: 0 10px">                // Deprecated properties.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -664,6 +672,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * Util check block type object against.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 5.5.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @since 6.4.0 Added the `block_hooks` extra field.
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><span class="cx" style="display: block; padding: 0 10px">         * @param WP_Block_Type $block_type Sample block type.
</span><span class="cx" style="display: block; padding: 0 10px">         * @param array         $data Data to compare against.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -690,6 +699,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'parent',
</span><span class="cx" style="display: block; padding: 0 10px">                        'provides_context',
</span><span class="cx" style="display: block; padding: 0 10px">                        'uses_context',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        'block_hooks',
</ins><span class="cx" style="display: block; padding: 0 10px">                         'supports',
</span><span class="cx" style="display: block; padding: 0 10px">                        'styles',
</span><span class="cx" style="display: block; padding: 0 10px">                        'textdomain',
</span></span></pre>
</div>
</div>

</body>
</html>