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

Backport: Elements - Merge element style and classname generation to single filter #6214

Conversation

aaronrobertshaw
Copy link

@aaronrobertshaw aaronrobertshaw commented Mar 4, 2024

Syncs the changes from WordPress/gutenberg#59535 and WordPress/gutenberg#59538.

These change update the elements block support filters such that the elements class name is only generated in a single location. This avoids conflicts between class names and makes the block support robust in the face of a block's data being filtered via other render_block_data filters.

To test:

Confirm WordPress/gutenberg#59462 is still resolved

  1. Edit a post and add a paragraph
  2. Create a link with the paragraph
  3. Via the block inspector apply a link color to the paragraph
  4. Save and view the frontend confirming the correct link color is shown
  5. Confirm nested applications of the same element styles work correctly:

Create some nested blocks containing links

  1. Apply a set of element styles to the parent block
  2. Apply different styles to a child block
  3. Apply the first set of element styles to a grand-child block
  4. Confirm the correct display of element styles

Unit tests:

npm run test:php -- --filter Tests_Block_Supports_WpRenderElementsSupport
npm run test:php -- --filter Tests_Block_Supports_WpRenderElementsSupportStyles

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


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.

@aaronrobertshaw
Copy link
Author

This PR is still only in a draft state as I have run out of time. Unfortunately, I'll be AFK until next week with limited bandwidth to push this across the line.

Anyone is welcome to pick this up, push to it, or create an alternate PR 🙏

Copy link

github-actions bot commented Mar 14, 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 aaronrobertshaw, isabel_brison.

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

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
Contributor

@tellthemachines tellthemachines 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 well for me! In order to reproduce the bug that this fixes, I dumped the filter that originally caused it in gutenberg into the layout.php file. I was then able to confirm that this change fixes the issue.

Just a couple minor corrections below, but otherwise looks good!

src/wp-includes/block-supports/elements.php Outdated Show resolved Hide resolved
src/wp-includes/block-supports/elements.php Show resolved Hide resolved
@aaronrobertshaw
Copy link
Author

Thanks for the review @tellthemachines 👍

I've addressed the feedback 1789ecf & 8e60ca7.

Copy link
Contributor

@tellthemachines tellthemachines 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 update! LGTM.

@tellthemachines
Copy link
Contributor

Committed in r58074.

* `render_block_data` filter in 6.6.0 to avoid filtered attributes
* breaking the application of the elements CSS class.
*
* @see https://github.com/WordPress/gutenberg/pull/59535.
Copy link
Member

Choose a reason for hiding this comment

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

Remove end period.

Comment on lines +261 to +263
* @param array $block Block object.
*
* @return string Filtered block content.
Copy link
Member

Choose a reason for hiding this comment

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

Remove empty line.

@aaronrobertshaw
Copy link
Author

@mukeshpanchal27 as these changes were already committed, I've created a follow-up PR to address the issues noted

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