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 layout classes to legacy Group inner container #5812

Conversation

tellthemachines
Copy link
Contributor

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

Syncs the changes from WordPress/gutenberg#56130 to core. Editor-side changes will be added with the npm package updates as usual; this PR will work without them but classname changes will only be visible in the front end.

To test:

  1. Activate a classic theme;
  2. In the editor, add a Group block with some children;
  3. Save and publish;
  4. Check that classnames is-layout-constrained wp-block-group-is-layout-constrained are added to the inner container on the front end.
  5. Run the layout unit tests.

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

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.

Copy link
Member

@mukeshpanchal27 mukeshpanchal27 left a comment

Choose a reason for hiding this comment

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

Thanks @tellthemachines for ping. Left some initial feedback for consideration.

src/wp-includes/block-supports/layout.php Outdated Show resolved Hide resolved
src/wp-includes/block-supports/layout.php Outdated Show resolved Hide resolved
src/wp-includes/block-supports/layout.php Outdated Show resolved Hide resolved
tests/phpunit/tests/block-supports/layout.php Outdated Show resolved Hide resolved
if ( method_exists( $processor, 'class_list' ) ) {
foreach ( $processor->class_list() as $class_name ) {
if ( str_contains( $class_name, 'layout' ) ) {
array_push( $layout_classes, $class_name );
Copy link
Member

Choose a reason for hiding this comment

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

Not blocker: If adding a single element to an array, using $layout_classes[] = $class_name tends to be more concise and easier to read. However, if you're adding multiple elements at once, array_push() might be more suitable for that purpose.

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

@tellthemachines Looks good, only one change request other than what @mukeshpanchal27 pointed out.

src/wp-includes/block-supports/layout.php Outdated Show resolved Hide resolved
tellthemachines and others added 6 commits January 3, 2024 11:21
Fix inline comment formatting.

Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
Fix inline comment formatting

Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
Remove empty line

Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
Add ticket number to test.

Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
@tellthemachines
Copy link
Contributor Author

Thanks for the feedback folks! All points have been addressed now.

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

@tellthemachines LGTM mostly. There's one thing I'm wary about, please let me know what you think.


if ( $processor->next_tag( array( 'class_name' => 'wp-block-group' ) ) ) {
foreach ( $processor->class_list() as $class_name ) {
if ( str_contains( $class_name, 'layout' ) ) {
Copy link
Member

Choose a reason for hiding this comment

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

This seems a bit error-prone to me. Shouldn't we maybe check for the more specific class names that can be there, or at least for a more specific pattern? What if any custom class name includes the word layout? It would be covered here when it probably shouldn't.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, the problem is finding one pattern that covers all classnames. We can have:
is-layout-[type]
wp-block-group-is-layout-[type]
wp-container-core-group-layout-[random number]

At most I think we could change the auto-generated class (the one with the random number) to match is-layout and check for that. Do you reckon that's worth trying?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I think that would be a reasonable improvement. Then we could probably look for is-layout- (since there's always a suffix if I'm not mistaken)?

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! Yes, there wouldn't ever be a class that ended in is-layout.

@tellthemachines
Copy link
Contributor Author

Committed in r57246.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants