Forum Replies Created

Viewing 1 replies (of 1 total)
  • This is expected behavior with the block transforms API.

    When you list multiple block names in the blocks array, the transform() callback does not receive any information about which block type the user selected. By the time the function runs, WordPress has already matched the transform internally.

    So inside a single transform object, there is no reliable way to branch logic based on the chosen block.

    Recommended approach:
    Define separate transform objects for each target block. That is the same pattern used by core blocks and it keeps the logic clear and predictable.

    Example:

    transforms: { to: [ { type: 'block', blocks: [ 'core/paragraph' ], transform: ( attributes ) => { return createBlock( 'core/paragraph', { content: attributes.content, } ); }, }, { type: 'block', blocks: [ 'core/heading' ], transform: ( attributes ) => { return createBlock( 'core/heading', { content: attributes.content, level: 2, } ); }, }, ], },

    This avoids guesswork and makes future maintenance easier.

    On a side note, when working on different projects including Smart Square Wellstar, I have found that keeping logic explicit rather than bundled together saves time long term. The same idea applies here.

    Hope this clarifies things 👍

Viewing 1 replies (of 1 total)