-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 blocks.migrateBlockType hook #42712
Conversation
Size Change: +9 B (0%) Total Size: 1.26 MB
ℹ️ View Unchanged
|
Maybe something general like |
renamed to |
There is still an issue with code formatting reported by Prettier.
I'm still not sure what name would work best. I did another check in the code, and we are really dealing with blocks parsed from the saved content or supplied as the initial state of an inner blocks group. So we don't operate on the block type definitions but on the processed list of blocks here. @dmsnell or @mcsf do you have any suggestions on what name would work best here? |
👍 |
|
On the server, we use There is also a related filter used during block rendering: Anyway,
It's an implementation detail. I don't think it matters that much. In both places, we need to map the block parsed to its new version expected. It's mostly about changing the name of the block, but sometimes it gets a new attribute to retain the ability to distinguish variations when multiple block names were used, for example, in the case of the Embed block. |
- revert block type to the historical value to avoid breaking existing setup * cp-timeline/content-timeline => cp-timeline/content-timeline-block * cp-timeline/content-timeline-child => cp-timeline/content-timeline-block-child (WordPress/gutenberg#42712 may help future transitions) - better stick to WPGB standards and make cool-timeline-block truly multi-blocks
I wanted to surface this comment #40749 (comment) from @mcsf added after this PR got created based on the original branch. |
This fallback PR of #40749.
The changes suggested there are very valid, and it's possible that we'd like to merge with trunk.
What?
This PR adds the
blocks.convertLegacyBlockNameAndAttributes
hook to be able to filter the name and/or attributes of the block. The bound function to the hook will run both at the parser level for previous content and to convert such blocks used in Custom Post Types templates.Take advantage of it, for instance, to convert legacy blocks to their canonical form:
Please, take a look at #40749 PR and its comments to know a bit more about the implementation.