WordPress / pattern-directory

The WordPress Block Pattern Directory
https://wordpress.org/patterns/
GNU General Public License v2.0
124 stars 34 forks source link

Search and/or group patterns by block #33

Open tellyworth opened 3 years ago

tellyworth commented 3 years ago

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:

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.

mtias commented 3 years ago

Related https://github.com/WordPress/gutenberg/issues/27575.

ryelle commented 3 years ago

Block patterns can have a blockTypes property, which identifies blocks that can be converted into this pattern. For example, the paragraph block:

Screen Shot 2021-04-21 at 2 31 17 PM

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.

ryelle commented 3 years ago

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.

ryelle commented 2 years ago

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.