How to transform block variant to default version?

Carolina Nymark pointed out, that there is possibility to filter transforms as any other settings, so one can modify the transformation like this:

const { addFilter } = wp.hooks;
const { assign, merge } = lodash;
const { createBlock } = wp.blocks;

function transformHeading(settings, name) {

    // Filter only heading.
    if (name !== 'core/heading') {
        return settings;
    }

    return assign({}, settings, {
        transforms: merge(settings.transforms, {
            from: [
                {
                    type: 'block',
                    blocks: ['core/paragraph'],
                    transform: ({ content }) => {
                        return createBlock('core/heading', {
                            content,
                            className: 'headline',
                        });
                    },
                }
            ],
        }),
    });
}

addFilter(
    'blocks.registerBlockType',
    'my-filters/transforms',
    transformHeading,
);

But there are still a few things that you can’t modify:

  • Name of the transformation (it’s still named by the default block, not the variation)
  • If the transformation for the “to” block is already in among the transforms, you’ll replace it (you can’t have two transforms to the same block)
  • as of WP 5.9.2 it doesn’t support transform within the same block – doesn’t migrate the content (not sure why)