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

Allow convert to blocks for other block types #4795

Closed
fastlinemedia opened this issue Feb 1, 2018 · 10 comments
Closed

Allow convert to blocks for other block types #4795

fastlinemedia opened this issue Feb 1, 2018 · 10 comments
Labels
[Feature] Blocks Overall functionality of blocks [Type] Developer Documentation Documentation for developers

Comments

@fastlinemedia
Copy link

Issue Overview

My apologies if this is already possible with transforms, I couldn't tell from the docs. I have a block that I'd like users to be able to "convert to blocks" similar to what you can do with the Classic Text block. That looks like a really powerful catch-all for converting a string of HTML into blocks.

I did notice that I can call setUnknownTypeHandlerName( 'my-plugin/my-block' ) to make that happen but that doesn't seem like a very safe solution. Thanks!

@gziolo gziolo added [Type] Question Questions about the design or development of the editor. [Feature] Blocks Overall functionality of blocks labels Feb 1, 2018
@youknowriad
Copy link
Contributor

Not sure I understand the question?

If you want your block to be a possible resulting block of the "convert to blocks" actions, you can do this by implemeting a "raw" transforms (not documented yet #4578). Example here https://github.com/WordPress/gutenberg/blob/master/blocks/library/image/index.js#L69-L87

If you want to allow your block to be transformed to other blocks (using the block switcher for instance), it's also done using the transforms property (but this time it's the type: "blocks")

@fastlinemedia
Copy link
Author

Thanks, @youknowriad! I actually want my block to be transformed to other blocks just like the Classic Text block. I played around with transforms but I couldn't figure out how to do a catch-all transform like that.

screenshot 2018-02-01 09 16 37_preview

Is it possible to do something like this with transforms?

https://github.com/WordPress/gutenberg/blob/master/editor/components/block-settings-menu/unknown-converter.js#L38

@youknowriad
Copy link
Contributor

@fastlinemedia I think you probably could do it since wp.blocks.rawHandler is exposed but I don't believe it's documented yet cc @iseulde

@ellatrix
Copy link
Member

Yes, I see no reason to not keep it exposed. We should add the button to the HTML block as well, which could be a good example on how to do it for other blocks.

@ellatrix
Copy link
Member

And yes, I should add a read me file for it :)

@ellatrix ellatrix added the [Type] Developer Documentation Documentation for developers label Feb 15, 2018
@fastlinemedia
Copy link
Author

That would be great. I'll dig into wp.blocks.rawHandler in the meantime, thanks!

@mtias mtias removed the [Type] Question Questions about the design or development of the editor. label Mar 7, 2018
@ZebulanStanphill
Copy link
Member

ZebulanStanphill commented Jul 13, 2018

The Convert to Blocks option has now been added to the Custom HTML block by #7667.

@aaronjorbin aaronjorbin added this to the Documentation & Handbook milestone Oct 8, 2018
@aaronjorbin
Copy link
Member

This needs documentation to be closed out.

@chrisvanpatten
Copy link
Contributor

I think we might be blocked on writing documentation by the potential changes to the raw handler to separate from pasting, but maybe @iseulde could help clarify here whether this might be impacted in those changes?

@youknowriad youknowriad removed this from the Documentation & Handbook milestone Mar 18, 2019
@youknowriad
Copy link
Contributor

So the rawHandler API is now automatically documented as part of the blocks module https://wordpress.org/gutenberg/handbook/designers-developers/developers/packages/packages-blocks/#rawHandler

I think it can be enhanced as this is pretty minimal but I think it's fine to close this issue now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Blocks Overall functionality of blocks [Type] Developer Documentation Documentation for developers
Projects
None yet
Development

No branches or pull requests

9 participants