-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 anchor support for dynamic blocks #44771
Conversation
Yes! I have been waiting for this for so long! |
I'm very eager to get this merged! Nice work @Soean! 👏
Could you create a ticket for this in WordPress Core Trac so that a relevant change can be made there? There's also a small merge conflict in the docs I see 🙂 |
@michalczaplinski I created a trac ticket and PR:
I also solved the merge conflict. |
Just tested this PR using a Social Link block, and it works great. For others testing, note that you need to manually apply the patch in WordPress/wordpress-develop#3497. |
Would it be possible to make the anchor block support enabled by default for all blocks? |
Flaky tests detected in 291cced. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4053938383
|
@ndiego, do you see any errors in the DevTools console when testing this branch, with or without the core patch? I think failing E2E tests are related to the changes in this PR. |
@carolinan I am getting fatal errors now with the recent updates. Per @Mamaduka it looks like this PR needs to be updated due to #47195. |
After updating to Update: Ignore that ^, it was theme related. |
I just retested and everything is looking good on my end. |
Thanks for testing, what do we need to get it merged? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes here look good to me. Thank you, @Soean!
While there are many file updates, only the anchor.php
contains significant changes.
@Soean, can you update WordPress/wordpress-develop#3497 and sync changes for the anchor.php
after the merge?
Here's the tracking issue for PHP backports: #47187.
Thanks @Mamaduka. I synced the changes to the PR WordPress/wordpress-develop#3497, updated the trac ticket and added it to the tracking issue. |
Thank you, @Soean! |
@Soean I added the If not I can help with writing something up. :) |
I fear that this change may affect the backward compatibility of some blocks with the anchor. Please see #48232. |
function gutenberg_register_anchor_support( $block_type ) { | ||
$has_anchor_support = _wp_array_get( $block_type->supports, array( 'anchor' ), true ); | ||
if ( ! $has_anchor_support ) { | ||
return; | ||
} | ||
|
||
if ( ! $block_type->attributes ) { | ||
$block_type->attributes = array(); | ||
} | ||
|
||
if ( ! array_key_exists( 'anchor', $block_type->attributes ) ) { | ||
$block_type->attributes['anchor'] = array( | ||
'type' => 'string', | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This process would also apply to static blocks, which would add an extra comment as attributes.
We've been building pages for wordpress.org and seeing blocks with existing anchors becoming unrecoverable. Typically Group blocks. |
@fabiankaegy and @Soean Are either of you working the dev note for this PR?
If you could do write this by Thursday (March 2 EOB), that would be helpful. The release squad for 6.2 documentation, will start working on the Field guide for 6.2 on Friday. |
What?
Fixes #29401
Testing Instructions
You need to add
'id'
to$attributes_to_merge
inget_block_wrapper_attributes()
from theWP_Block_Supports
class, see https://github.com/WordPress/wordpress-develop/blob/6.0.2/src/wp-includes/class-wp-block-supports.php#L178Change to: