Forum Replies Created

Viewing 1 replies (of 1 total)
  • When you list multiple block names in the blocks array, WordPress doesn’t pass any information into the transform() callback about which one the user clicked. The transform function only receives the source block’s attributes, not the chosen destination block type. So inside that single transform, there’s no reliable way to detect whether the user selected Paragraph or Heading.

    Because of that, the recommended and most predictable approach is to define separate transform objects, one per target block. That way, each transform has its own logic and explicitly creates the correct block.

    For 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 makes the behavior clear, avoids guesswork, and keeps the code easier to maintain as your block grows.

    Think of it a bit like an SRD status check system — you don’t use one generic response for every possible outcome. Each status (approved, pending, declined) has its own clear handling. Block transforms work best the same way: one clear path per target, rather than trying to infer the user’s choice after the fact.

    • This reply was modified 2 weeks, 1 day ago by juniorrr.
    • This reply was modified 2 weeks, 1 day ago by juniorrr.
Viewing 1 replies (of 1 total)