pattern-directory icon indicating copy to clipboard operation
pattern-directory copied to clipboard

Search and/or group patterns by block

Open tellyworth opened this issue 5 years ago • 4 comments

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.

tellyworth avatar Jan 18 '21 22:01 tellyworth

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

mtias avatar Feb 10 '21 11:02 mtias

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 avatar Apr 21 '21 19:04 ryelle

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 avatar Oct 20 '21 20:10 ryelle

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.

ryelle avatar Dec 01 '21 21:12 ryelle