-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Open
Labels
[Type] BugAn existing feature does not function as intendedAn existing feature does not function as intended
Description
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:
{
"clientId": "dc20b9f6-4d79-42f2-bdf1-79d6f11bc4ab",
"name": "core/heading",
"isValid": true,
"attributes": {
"content": {
#value: {
...
"text": "Here is my custom header",
}
},
"level": 2
},
"innerBlocks": []
}
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
fromdirection - set
blocks: ['*'] - set either
__experimentalConvertortransformfunction 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.
Screenshots, screen recording, code snippet
import {
registerBlockType,
} from '@wordpress/blocks';
registerBlockType( 'gutentest/jp', {
"apiVersion": 2,
"name": "gutentest/jp",
"title": "Gutentest JP",
edit: function ( props ) {
return ( <p>Hello</p> );
},
save: function ( props ) {
return null;
},
transforms: {
from: [
{
type: 'block',
blocks: [ '*' ],
isMultiBlock: true,
isMatch: () => true,
transform: function ( attributesArray ) {
console.debug( attributesArray)
return createBlock( 'gutenttest/jp');
},
// OR (one or the other)
// __experimentalConvert ( blocks ) {
// console.debug( blocks )
// return createBlock( 'gutentest/jp' );
// }
}
]
}
});
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
[Type] BugAn existing feature does not function as intendedAn existing feature does not function as intended
Type
Fields
Give feedbackNo fields configured for issues without a type.