-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Transforms: "isMatch" does not work for shortcode transformation #10674
Comments
@designsimply, |
@sayontan my apologies for not seeing your message sooner. I have updated the labels for you. I think I initially labeled this issue as a help request because you asked, "if |
Just confirmed this bug/missing feature and it's kinda blocker for using conditional transforms, especially for the poor Currently, a block with the highest Suppose these shortcodes and if every plugin implements
An alternative approach could be to define specific attributes as required with a possible list of accepted values. |
We're running into the same problem with the WooCommerce Blocks– we have a few different blocks that correspond to a single shortcode with different attributes. For example:
And so on (we have 7 blocks that all match different configurations of the products shortcode). Having an |
This is a useful issue to raise and I agree that there should be some sort of equivalent to other transform types'
After a quick stab at this, my personal preference goes for the mid-level API, i.e. the result of the shortcode attributes match per the Shortcode API, which also mirrors how attributes are transformed: {
type: 'shortcode',
tag: [ 'my-broccoli' ],
attributes: {
id: {
type: 'number',
shortcode: ( { named: { id } } ) => parseInt( id, 10 ),
},
},
isMatch( { named: { id } } ) {
return id < 1000;
},
}, |
See #18459 for a fix. |
Describe the bug
The Block API documentation talks about the use of
isMatch
to filter or specifically target certain blocks or nodes. This however does not seem to work if thetransform
from
is oftype: "shortcode"
.To Reproduce
Steps to reproduce the behavior:
Expected behavior
I would expect the first shortcode to continue to be treated as a regular WordPress gallery, and the second to be treated as a block defined by my plugin. If
isMatch
is not the right way for this to happen, how would such targeting be done?Use Case
There are multiple plugins today that use the same shortcode, with the
gallery
shortcode being one of the more commonly used ones. With the shortcodes there is a way to make them coexist by having specific attributes. Vendors typically use this approach to avoid shortcodes showing up in the front-end. E.g. in the two examples I have provided above the first gallery will render as per the inputs, while the second one will not be visible at all if you don't have the plugin.When the plugin developer wants to use the Block API they would typically target their specific instances by applying certain match criteria for transformation. Without this capability they will end up inadvertently changing all shortcodes with the same tag to the same block type when the user clicks on "Convert to Blocks" for the first time.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Additional context
The text was updated successfully, but these errors were encountered: