My transform variations code partially fulfills its mission #51490
-
DescriptionI find that the documentation on the topic of transform variations is not fully disclosed and I'm stuck at the initial stage, I make a block that represent a section of three types, full width section, section with sidebar on the left side, and section with sidebar on the right side, I adapted the columns block code to make it work in Editor ( used Step-by-step reproduction instructions
Screenshots, screen recording, code snippetvariations.js
Environment infoWP 6.2.2, Gutenberg 15.9.1, Custom Theme Please confirm that you have searched existing issues in the repo.Yes Please confirm that you have tested with all plugins deactivated except Gutenberg.Yes |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 1 reply
-
I partially solved the problem,
When I click on transform variations button in Editor Sidebar block transformation does not occur, for example, if there are two blocks - unior-section-content and unior-section-sidebar they didn't transform to single inner block unior-section-content. |
Beta Was this translation helpful? Give feedback.
-
Hi @realthemes, I think it is a specification, not a bug, that the The block editor handbook mentions the following:
Therefore, I believe the I haven't tried it, but I think you may explicitly replace useEffect( () => {
const newInnerBlocks = [
// ...
];
replaceInnerBlocks( clientId, newInnerBlocks );
}, [ attributes.sidebarPosition ] ); |
Beta Was this translation helpful? Give feedback.
-
Thank you @t-hamano for reply, most likely you are right, despite the fact that I could not get the replaceInnerBlocks function to work. Here is the simple code that must change inner blocks to single innre block (just for example):
|
Beta Was this translation helpful? Give feedback.
-
As I recall, the hooks (useDispatch, useEffect) could only be used at the root level of the component. You appear to be using those hooks in your function. Also, I don't think this topic is an issue, so let's move it to Discussions. |
Beta Was this translation helpful? Give feedback.
Hi @realthemes,
I think it is a specification, not a bug, that the
innerBlocks
is maintained after changing the block variation.The block editor handbook mentions the following:
Therefore, I believe the
innerBlocks
property only defines the template when the block is first inserted.I haven't tried it, but I think you may explicitly replace
innerBlocks
template when certain attributes are changed, (i.e., when a variation is changed).