• t.schwarz

    (@tschwarz-1)


    Hi! I have a simple Block Variation for core/heading –

        wp.blocks.registerBlockVariation(
        'core/heading',
        [{
            name: 'my heading',
            title: 'My Heading',
            attributes: {
                level: 3,
                className: 'is-style-my-heading',
            },
            scope: [ 'inserter', 'block', 'transform' ],
        }]
    );

    It works in the inserter, but I can’t make the variation visible in the transforms component for some reason. But maybe I don’t sufficiently understand what the ‘transform’ in the scope attribute is supposed to do. I can transform the block variation to, say, a paragraph (not the core version of heading for some reason), but when I try to transform a paragraph or a core heading the list of available transforms only gives the core/heading block (or none), not the variation.

    Can only one core/heading block be in the transforms list and thus variations will only appear if they are assigned as “default” variation?

    Is that expected behavior? Seems strange to me, why shouldn’t I be able to transform a paragraph into a specific version of the headline?

Viewing 1 replies (of 1 total)
  • Hi there, I see no one has found a solution in over a week, are you still struggling with this?

    A block declares which transformations it supports via the transforms key in the block configuration. It’s subkeys to and from then store an array of available transforms.

    Example taken from the Block Editor Handbook:

    export const settings = {
        title: 'My Block Title',
        description: 'My block description',
        /* ... */
        transforms: {
            from: [
                /* supported from transforms */
            ],
            to: [
                /* supported to transforms */
            ],
        },
    };

    Not sure if this is what you are after, there is more info on Transforms in the block editor handbook.

    Let me know if you need more assistance and I’ll see what I can do to help.
    -Jamie

    • This reply was modified 2 years, 11 months ago by jamiehlake.
Viewing 1 replies (of 1 total)
  • The topic ‘Can blocks be transformed into block variations?’ is closed to new replies.