<!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>[58170] trunk: Editor: add column and row spans to grid children.</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/58170">58170</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/58170","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>isabel_brison</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2024-05-18 20:30:57 +0000 (Sat, 18 May 2024)</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'>Editor: add column and row spans to grid children.
Adds support for setting spans using `grid-column` and `grid-row` properties on children of blocks with grid layout.
Props isabel_brison, andrewserong, peterwilsoncc, mukesh27.
Fixes <a href="https://core.trac.wordpress.org/ticket/61111">#61111</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesblocksupportslayoutphp">trunk/src/wp-includes/block-supports/layout.php</a></li>
<li><a href="#trunksrcwpincludesksesphp">trunk/src/wp-includes/kses.php</a></li>
<li><a href="#trunktestsphpunittestsblocksupportslayoutphp">trunk/tests/phpunit/tests/block-supports/layout.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesblocksupportslayoutphp"></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/block-supports/layout.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/block-supports/layout.php 2024-05-18 18:20:19 UTC (rev 58169)
+++ trunk/src/wp-includes/block-supports/layout.php 2024-05-18 20:30:57 UTC (rev 58170)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -489,7 +489,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $layout_styles[] = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'selector' => $selector,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'declarations' => array( 'grid-template-columns' => 'repeat(auto-fill, minmax(min(' . $minimum_column_width . ', 100%), 1fr))' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'declarations' => array(
+ 'grid-template-columns' => 'repeat(auto-fill, minmax(min(' . $minimum_column_width . ', 100%), 1fr))',
+ 'container-type' => 'inline-size',
+ ),
</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 class="lines" style="display: block; padding: 0 10px; color: #888">@@ -555,37 +558,92 @@
</span><span class="cx" style="display: block; padding: 0 10px"> function wp_render_layout_support_flag( $block_content, $block ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );
</span><span class="cx" style="display: block; padding: 0 10px"> $block_supports_layout = block_has_support( $block_type, 'layout', false ) || block_has_support( $block_type, '__experimentalLayout', false );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $layout_from_parent = isset( $block['attrs']['style']['layout']['selfStretch'] ) ? $block['attrs']['style']['layout']['selfStretch'] : null;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $child_layout = isset( $block['attrs']['style']['layout'] ) ? $block['attrs']['style']['layout'] : null;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! $block_supports_layout && ! $layout_from_parent ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $block_supports_layout && ! $child_layout ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return $block_content;
</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"> $outer_class_names = array();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( 'fixed' === $layout_from_parent || 'fill' === $layout_from_parent ) {
- $container_content_class = wp_unique_id( 'wp-container-content-' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Child layout specific logic.
+ if ( $child_layout ) {
+ $container_content_class = wp_unique_prefixed_id( 'wp-container-content-' );
+ $child_layout_declarations = array();
+ $child_layout_styles = array();
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $child_layout_styles = array();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $self_stretch = isset( $child_layout['selfStretch'] ) ? $child_layout['selfStretch'] : null;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( 'fixed' === $layout_from_parent && isset( $block['attrs']['style']['layout']['flexSize'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( 'fixed' === $self_stretch && isset( $child_layout['flexSize'] ) ) {
+ $child_layout_declarations['flex-basis'] = $child_layout['flexSize'];
+ $child_layout_declarations['box-sizing'] = 'border-box';
+ } elseif ( 'fill' === $self_stretch ) {
+ $child_layout_declarations['flex-grow'] = '1';
+ }
+
+ if ( isset( $child_layout['columnSpan'] ) ) {
+ $column_span = $child_layout['columnSpan'];
+ $child_layout_declarations['grid-column'] = "span $column_span";
+ }
+ if ( isset( $child_layout['rowSpan'] ) ) {
+ $row_span = $child_layout['rowSpan'];
+ $child_layout_declarations['grid-row'] = "span $row_span";
+ }
+ $child_layout_styles[] = array(
+ 'selector' => ".$container_content_class",
+ 'declarations' => $child_layout_declarations,
+ );
+
+ /*
+ * If columnSpan is set, and the parent grid is responsive, i.e. if it has a minimumColumnWidth set,
+ * the columnSpan should be removed on small grids. If there's a minimumColumnWidth, the grid is responsive.
+ * But if the minimumColumnWidth value wasn't changed, it won't be set. In that case, if columnCount doesn't
+ * exist, we can assume that the grid is responsive.
+ */
+ if ( isset( $child_layout['columnSpan'] ) && ( isset( $block['parentLayout']['minimumColumnWidth'] ) || ! isset( $block['parentLayout']['columnCount'] ) ) ) {
+ $column_span_number = floatval( $child_layout['columnSpan'] );
+ $parent_column_width = isset( $block['parentLayout']['minimumColumnWidth'] ) ? $block['parentLayout']['minimumColumnWidth'] : '12rem';
+ $parent_column_value = floatval( $parent_column_width );
+ $parent_column_unit = explode( $parent_column_value, $parent_column_width );
+
+ /*
+ * If there is no unit, the width has somehow been mangled so we reset both unit and value
+ * to defaults.
+ * Additionally, the unit should be one of px, rem or em, so that also needs to be checked.
+ */
+ if ( count( $parent_column_unit ) <= 1 ) {
+ $parent_column_unit = 'rem';
+ $parent_column_value = 12;
+ } else {
+ $parent_column_unit = $parent_column_unit[1];
+
+ if ( ! in_array( $parent_column_unit, array( 'px', 'rem', 'em' ), true ) ) {
+ $parent_column_unit = 'rem';
+ }
+ }
+
+ /*
+ * A default gap value is used for this computation because custom gap values may not be
+ * viable to use in the computation of the container query value.
+ */
+ $default_gap_value = 'px' === $parent_column_unit ? 24 : 1.5;
+ $container_query_value = $column_span_number * $parent_column_value + ( $column_span_number - 1 ) * $default_gap_value;
+ $container_query_value = $container_query_value . $parent_column_unit;
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $child_layout_styles[] = array(
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'rules_group' => "@container (max-width: $container_query_value )",
</ins><span class="cx" style="display: block; padding: 0 10px"> 'selector' => ".$container_content_class",
</span><span class="cx" style="display: block; padding: 0 10px"> 'declarations' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'flex-basis' => $block['attrs']['style']['layout']['flexSize'],
- 'box-sizing' => 'border-box',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'grid-column' => '1/-1',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } elseif ( 'fill' === $layout_from_parent ) {
- $child_layout_styles[] = array(
- 'selector' => ".$container_content_class",
- 'declarations' => array(
- 'flex-grow' => '1',
- ),
- );
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_style_engine_get_stylesheet_from_css_rules(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /*
+ * Add to the style engine store to enqueue and render layout styles.
+ * Return styles here just to check if any exist.
+ */
+ $child_css = wp_style_engine_get_stylesheet_from_css_rules(
</ins><span class="cx" style="display: block; padding: 0 10px"> $child_layout_styles,
</span><span class="cx" style="display: block; padding: 0 10px"> array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'context' => 'block-supports',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -593,7 +651,9 @@
</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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $outer_class_names[] = $container_content_class;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $child_css ) {
+ $outer_class_names[] = $container_content_class;
+ }
</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"> // Prep the processor for modifying the block output.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -851,6 +911,27 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return $processor->get_updated_html();
</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">+/**
+ * Check if the parent block exists and if it has a layout attribute.
+ * If it does, add the parent layout to the parsed block
+ *
+ * @since 6.6.0
+ * @access private
+ *
+ * @param array $parsed_block The parsed block.
+ * @param array $source_block The source block.
+ * @param WP_Block $parent_block The parent block.
+ * @return array The parsed block with parent layout attribute if it exists.
+ */
+function wp_add_parent_layout_to_parsed_block( $parsed_block, $source_block, $parent_block ) {
+ if ( $parent_block && isset( $parent_block->parsed_block['attrs']['layout'] ) ) {
+ $parsed_block['parentLayout'] = $parent_block->parsed_block['attrs']['layout'];
+ }
+ return $parsed_block;
+}
+
+add_filter( 'render_block_data', 'wp_add_parent_layout_to_parsed_block', 10, 3 );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Register the block support.
</span><span class="cx" style="display: block; padding: 0 10px"> WP_Block_Supports::get_instance()->register(
</span><span class="cx" style="display: block; padding: 0 10px"> 'layout',
</span></span></pre></div>
<a id="trunksrcwpincludesksesphp"></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/kses.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/kses.php 2024-05-18 18:20:19 UTC (rev 58169)
+++ trunk/src/wp-includes/kses.php 2024-05-18 20:30:57 UTC (rev 58170)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2441,11 +2441,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'grid-auto-columns',
</span><span class="cx" style="display: block; padding: 0 10px"> 'grid-column-start',
</span><span class="cx" style="display: block; padding: 0 10px"> 'grid-column-end',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'grid-column',
</ins><span class="cx" style="display: block; padding: 0 10px"> 'grid-column-gap',
</span><span class="cx" style="display: block; padding: 0 10px"> 'grid-template-rows',
</span><span class="cx" style="display: block; padding: 0 10px"> 'grid-auto-rows',
</span><span class="cx" style="display: block; padding: 0 10px"> 'grid-row-start',
</span><span class="cx" style="display: block; padding: 0 10px"> 'grid-row-end',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'grid-row',
</ins><span class="cx" style="display: block; padding: 0 10px"> 'grid-row-gap',
</span><span class="cx" style="display: block; padding: 0 10px"> 'grid-gap',
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2475,6 +2477,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'z-index',
</span><span class="cx" style="display: block; padding: 0 10px"> 'box-shadow',
</span><span class="cx" style="display: block; padding: 0 10px"> 'aspect-ratio',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'container-type',
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Custom CSS properties.
</span><span class="cx" style="display: block; padding: 0 10px"> '--*',
</span></span></pre></div>
<a id="trunktestsphpunittestsblocksupportslayoutphp"></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/block-supports/layout.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/block-supports/layout.php 2024-05-18 18:20:19 UTC (rev 58169)
+++ trunk/tests/phpunit/tests/block-supports/layout.php 2024-05-18 20:30:57 UTC (rev 58170)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -172,6 +172,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 57584
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 58548
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 60292
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @ticket 61111
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @dataProvider data_layout_support_flag_renders_classnames_on_wrapper
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -181,6 +182,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $expected_output The expected output.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_layout_support_flag_renders_classnames_on_wrapper( $args, $expected_output ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ switch_theme( 'default' );
</ins><span class="cx" style="display: block; padding: 0 10px"> $actual_output = wp_render_layout_support_flag( $args['block_content'], $args['block'] );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame( $expected_output, $actual_output );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -251,6 +253,27 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'expected_output' => '<div class="wp-block-group"><div class="wp-block-group__inner-wrapper is-layout-flow wp-block-group-is-layout-flow"></div></div>',
</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 with child layout' => array(
+ 'args' => array(
+ 'block_content' => '<p>Some text.</p>',
+ 'block' => array(
+ 'blockName' => 'core/paragraph',
+ 'attrs' => array(
+ 'style' => array(
+ 'layout' => array(
+ 'columnSpan' => '2',
+ ),
+ ),
+ ),
+ 'innerBlocks' => array(),
+ 'innerHTML' => '<p>Some text.</p>',
+ 'innerContent' => array(
+ '<p>Some text.</p>',
+ ),
+ ),
+ ),
+ 'expected_output' => '<p class="wp-container-content-1">Some text.</p>', // The generated classname number assumes `wp_unique_prefixed_id( 'wp-container-content-' )` will not have run previously in this test.
+ ),
</ins><span class="cx" style="display: block; padding: 0 10px"> 'skip classname output if block does not support layout and there are no child layout classes to be output' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'args' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'block_content' => '<p>A paragraph</p>',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -362,4 +385,81 @@
</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">+
+ /**
+ * Checks that `wp_add_parent_layout_to_parsed_block` adds the parent layout attribute to the block object.
+ *
+ * @ticket 61111
+ *
+ * @covers ::wp_add_parent_layout_to_parsed_block
+ *
+ * @dataProvider data_wp_add_parent_layout_to_parsed_block
+ *
+ * @param array $block The block object.
+ * @param WP_Block $parent_block The parent block object.
+ * @param array $expected The expected block object.
+ */
+ public function test_wp_add_parent_layout_to_parsed_block( $block, $parent_block, $expected ) {
+ $actual = wp_add_parent_layout_to_parsed_block( $block, array(), $parent_block );
+ $this->assertSame( $expected, $actual );
+ }
+
+ /**
+ * Data provider for test_wp_add_parent_layout_to_parsed_block.
+ *
+ * @return array
+ */
+ public function data_wp_add_parent_layout_to_parsed_block() {
+ return array(
+ 'block with no parent layout' => array(
+ 'block' => array(
+ 'blockName' => 'core/group',
+ 'attrs' => array(
+ 'layout' => array(
+ 'type' => 'default',
+ ),
+ ),
+ ),
+ 'parent_block' => array(),
+ 'expected' => array(
+ 'blockName' => 'core/group',
+ 'attrs' => array(
+ 'layout' => array(
+ 'type' => 'default',
+ ),
+ ),
+ ),
+ ),
+ 'block with parent layout' => array(
+ 'block' => array(
+ 'blockName' => 'core/group',
+ 'attrs' => array(
+ 'layout' => array(
+ 'type' => 'default',
+ ),
+ ),
+ ),
+ 'parent_block' => new WP_Block(
+ array(
+ 'attrs' => array(
+ 'layout' => array(
+ 'type' => 'grid',
+ ),
+ ),
+ )
+ ),
+ 'expected' => array(
+ 'blockName' => 'core/group',
+ 'attrs' => array(
+ 'layout' => array(
+ 'type' => 'default',
+ ),
+ ),
+ 'parentLayout' => array(
+ 'type' => 'grid',
+ ),
+ ),
+ ),
+ );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>
</body>
</html>