Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Media & Text: Provide a way to transform into both image & paragraph #16516

Open
melchoyce opened this issue Jul 10, 2019 · 4 comments
Open

Media & Text: Provide a way to transform into both image & paragraph #16516

melchoyce opened this issue Jul 10, 2019 · 4 comments
Labels
[Block] Media & Text Affects the Media & Text Block Needs Dev Ready for, and needs developer efforts [Type] Enhancement A suggestion for improvement.

Comments

@melchoyce
Copy link
Contributor

Sometimes when I'm trying out different layouts in a page, I'll try out a media & text block, and then realize it might just be better as an image and a paragraph underneath. You can transform media & text into an image, but not into an image and a paragraph. In order to make a paragraph, you need to copy and paste the text from the media & text block into a new paragraph block, then transform the block

Likewise, it would be great to be able to do the opposite — highlight and image and paragraph block, and transform into a media & text block.

@melchoyce melchoyce added [Block] Media & Text Affects the Media & Text Block Needs Design Needs design efforts. labels Jul 10, 2019
@karmatosed
Copy link
Member

karmatosed commented Jul 10, 2019

I agree this makes sense as a transformation. To me, this feels like it may not need design but just be something happens? @youknowriad looping you in to see if this doesn't need design as much as can be done in transforming?

@youknowriad
Copy link
Contributor

I think it makes sense too. I know we had limitations due to InnerBlocks not available in transforms at some point but this might be solved now.

@karmatosed karmatosed removed the Needs Design Needs design efforts. label Jul 11, 2019
@paaljoachim
Copy link
Contributor

What if the Media & Text block consisted of an nested image and paragraph blocks. If one wanted to separate them one could drag the image or paragraph out from the nested area to become full single blocks.

@melchoyce melchoyce added the Needs Dev Ready for, and needs developer efforts label Aug 12, 2019
@Mamaduka
Copy link
Member

Mamaduka commented Jun 4, 2021

While this is technically possible, "Transforms To" doesn't support wildcard transformations. It will require a unique menu item when the blocks param is set to wildcard.

The wildcard support for "Transforms To" can be a nice addition to the new convert API.

This is a simplified example where I used core/paragraph as a hack to display transformation in the menu.

{
    type: 'block',
    blocks: [ 'core/paragraph' ], // No menu items is displayed when using `*`.
    isMatch: ( { mediaType, mediaUrl } ) => {
        return ! mediaUrl || mediaType === 'image';
    },
    transform: (
        { mediaAlt, mediaId, mediaUrl, anchor },
        innerBlocks
    ) => {
        return [
            createBlock( 'core/image', {
                alt: mediaAlt,
                id: mediaId,
                url: mediaUrl,
                anchor,
            } ),
            ...innerBlocks,
        ];
    },
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Media & Text Affects the Media & Text Block Needs Dev Ready for, and needs developer efforts [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

6 participants