You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you transform from a block like core/heading or core/paragraph which has not yet been saved, the text content of that block is not available to the transform. Instead, it is locked inside an inaccessible private property in the attributes object provided to the transform function:
So if you want to transform a newly created header or paragraph block (those are the two I tested with), you can't do it. You have to first save the page, then transform them.
I tried this with both the transform() property function as well as the __experimentalConvert() property function.
Step-by-step reproduction instructions
Create a transform in the from direction
set blocks: ['*']
set either __experimentalConvert or transform function property.
The first argument to the function is either blocks (first case) or attributes (second case).
Save that block.
In the wordpress editor, create a header with some text
WITHOUT saving the page, attempt to tranform the header to your new block
If you console.log the incoming argument to the tranform function, you can see that you don't have access to the text content of the heading block.
import { serialize, parse } from '@wordpress/blocks';
export transform {
from: [
{
...
__experimentalConvert ( blocks ) {
let html = serialize( blocks );
let reparsedBlocks = parse( html );
// now the inner html of the blocks is always available
reparsedBlocks[0].attributes.content.originalHTML;
...
}
]
}
This works, but I wouldn't expect to have to do this on my own.
Description
When you transform from a block like core/heading or core/paragraph which has not yet been saved, the text content of that block is not available to the transform. Instead, it is locked inside an inaccessible private property in the attributes object provided to the transform function:
So if you want to transform a newly created header or paragraph block (those are the two I tested with), you can't do it. You have to first save the page, then transform them.
I tried this with both the
transform()
property function as well as the__experimentalConvert()
property function.Step-by-step reproduction instructions
from
directionblocks: ['*']
__experimentalConvert
ortransform
function property.Screenshots, screen recording, code snippet
Environment info
Wordpress 6.5.5
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
The text was updated successfully, but these errors were encountered: