Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for column and row spans in grid children. #6493

Conversation

tellthemachines
Copy link
Contributor

@tellthemachines tellthemachines commented May 3, 2024

Trac ticket: https://core.trac.wordpress.org/ticket/61111

Syncs the changes from WordPress/gutenberg#58539, WordPress/gutenberg#59057, WordPress/gutenberg#59452 and WordPress/gutenberg#61392 to core.

To test, paste the following markup in a post:

test markup
<!-- wp:group {"layout":{"type":"grid"}} -->
<div class="wp-block-group"><!-- wp:paragraph {"style":{"color":{"background":"#91ded8"},"layout":{"columnSpan":"2"}}} -->
<p class="has-background" style="background-color:#91ded8">grid item</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph {"style":{"color":{"background":"#91ded8"},"layout":{"rowSpan":"3"}}} -->
<p class="has-background" style="background-color:#91ded8">grid item</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph {"style":{"color":{"background":"#91ded8"}}} -->
<p class="has-background" style="background-color:#91ded8">grid item</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph {"style":{"color":{"background":"#91ded8"}}} -->
<p class="has-background" style="background-color:#91ded8">grid item</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph {"style":{"color":{"background":"#91ded8"}}} -->
<p class="has-background" style="background-color:#91ded8">grid item</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph {"style":{"color":{"background":"#91ded8"}}} -->
<p class="has-background" style="background-color:#91ded8">grid item</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group -->

Save and view on the front end. It should show grid items spanning multiple columns and rows:

Screenshot 2024-05-03 at 4 17 21 PM

This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Copy link

github-actions bot commented May 3, 2024

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@tellthemachines tellthemachines marked this pull request as ready for review May 7, 2024 07:03
Copy link

github-actions bot commented May 7, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props isabel_brison, andrewserong, peterwilsoncc, mukesh27.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@tellthemachines
Copy link
Contributor Author

I've added a test so marking this one ready for review!

*/
add_filter(
'render_block_data',
function ( $parsed_block, $source_block, $parent_block ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just double-checked the WP coding standards, and it looks like it's discouraged to use anonymous functions in filters:

Closures should not be passed as filter or action callbacks, as removing these via remove_action() / remove_filter() is complex (at this time) (see #46635 for a proposal to address this).

Should we move this to a named function so that plugins (if they really wanted to) are able to remove_filter this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Contributor

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is testing great for me on the site frontend, and matches the merged PRs in Gutenberg as far as I can tell 👍

Just left a couple of minor nits. I think the main issue to fix in terms of WP coding style is to make the render_block_data callback a named function so that it can be removed by a plugin if need be, but otherwise this is looking good to me!

),
),
),
'expected_output' => '<p class="wp-container-content-1">Some text.</p>', // The generated classname number assumes `wp_unique_id` will not have run previously in this test.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny nit: the code now uses wp_unique_prefixed_id so should the comment refer to that now, too?

Suggested change
'expected_output' => '<p class="wp-container-content-1">Some text.</p>', // The generated classname number assumes `wp_unique_id` will not have run previously in this test.
'expected_output' => '<p class="wp-container-content-1">Some text.</p>', // The generated classname number assumes `wp_unique_prefixed_id` will not have run previously in this test.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably worth including the prefix in Andrew's comment too, wp_unique_prefixed_id( 'wp-container-content-' ), as the counter is unique to each prefix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks!

@@ -181,6 +181,7 @@ public function test_outer_container_not_restored_for_aligned_image_block_with_t
* @param string $expected_output The expected output.
*/
public function test_layout_support_flag_renders_classnames_on_wrapper( $args, $expected_output ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice this function includes references to the tickets directly above it. Should the linked trac ticket be added to that list?

Copy link
Contributor

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates! This is still testing well, and the code looks good to me 👍

return $parsed_block;
}

add_filter( 'render_block_data', 'wp_add_parent_layout_to_parsed_block', 10, 3 );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to add unit test for new filter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests added!

@tellthemachines
Copy link
Contributor Author

Committed in r58170.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants