Search and/or group patterns by block
It's likely that the editor UI will have a flow where users could discover patterns that contain a particular block.
As a hypothetical example, if I'm adding a Buy Now button to content, it should be easy for me to discover that my e-commerce plugin already has some patterns for product layouts that contain the Buy Now button, to save me doing it all manually.
That suggests some things would be required on the back end:
- A way to search both local and remote patterns for an exact match by block slug.
- Possibly a way to retrieve all local patterns grouped by block (if for example the inserter UI was to display blocks and patterns side by side).
This is still a feature idea in progress so it's not clear exactly how it might pan out and what the final flow and requirements might be.
Related https://github.com/WordPress/gutenberg/issues/27575.
Block patterns can have a blockTypes property, which identifies blocks that can be converted into this pattern. For example, the paragraph block:
We should add some (optional) way of flagging patterns as related to block types, and on the validation side, make sure the pattern can be transformed from the chosen block. It seems like patterns can be related to more than one block type, but I think in practice, it's usually just one.
The API & proxy API will also need to be updated to allow a "blockTypes" parameter for fetching patterns.
There is a PR on the Gutenberg side to use the blockTypes meta value when registering patterns: https://github.com/WordPress/gutenberg/pull/32113
We still need to create a flow for setting the blockType value when creating a pattern.
We can set blockTypes for a pattern, and that will pass through the API to the editor to make it work (once WordPress/gutenberg#32113 is merged).
The unanswered question here is how that should work (in the UI) when creating a pattern. Since we still don't have a design here, and the gutenberg API has no traction (so it won't make 5.9), I've pulled this out of the pattern creation v1 milestone. We can revisit it post-beta or post-launch.