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

Patterns: Allow for filtering of block patterns by source #51672

Merged
merged 8 commits into from
Jun 21, 2023

Conversation

aaronrobertshaw
Copy link
Contributor

@aaronrobertshaw aaronrobertshaw commented Jun 20, 2023

Related:

Backport PR for this change: WordPress/wordpress-develop#4697

What?

  • Extends the REST API endpoint for block patterns to provide a new source attribute
  • When registering core block patterns, the new source attribute

Why?

The Site Editor Library has been designed to allow users a more refined experience in managing their patterns. This requires the ability to filter out core block patterns which will not be editable by users.

How?

Testing Instructions

  1. Test via Site Editor: Add Library for Template Parts & Patterns Management #51078
  2. Open the Site Editor and navigate to the Library
  3. Explore the library categories and ensure that only template parts, theme patterns, and reusable blocks are shown.

@aaronrobertshaw aaronrobertshaw added [Type] Enhancement A suggestion for improvement. [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced labels Jun 20, 2023
@github-actions
Copy link

github-actions bot commented Jun 20, 2023

Flaky tests detected in aac252d.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5320797322
📝 Reported issues:

Copy link
Contributor

@talldan talldan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good so far. I think there are a few changes that would be good to address.

There should also be some documentation changes for register_block_pattern - https://developer.wordpress.org/block-editor/reference-guides/block-api/block-patterns/.

$patterns = $response->get_data();

foreach ( $patterns as $pattern ) {
$pattern['source'] = 'core';
Copy link
Contributor

@talldan talldan Jun 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be more granular descriptive than just 'core' so that there are more options to use it for different things in the future.

Some suggestions based on the sources that I can see:

  • 'core' (bundled with WordPress core)
  • 'plugin' (plugins that register patterns can use this)
  • 'theme' (I'm not sure if themes call register_block_pattern directly, but they could use this as the source if they do)
  • 'pattern-directory/theme' (declared in the theme.json and pulled from the pattern directory)
  • 'pattern-directory/core' (core patterns in the pattern directory)
  • 'pattern-directory/featured' (featured patterns in the pattern directory).

Might be good to get some more opinions though, as I'm not too familiar with all the different places that patterns come from.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed a few more granular source values in 694f71d.

lib/compat/wordpress-6.3/block-patterns.php Outdated Show resolved Hide resolved
@aaronrobertshaw
Copy link
Contributor Author

@TimothyBJacobs it was suggested you might have some wisdom to share regarding the proposed REST API changes in this PR. If you have the time to take a look at this, it would be greatly appreciated as we're trying to get this in for 6.3 🙏

@talldan
Copy link
Contributor

talldan commented Jun 20, 2023

I've pushed a commit that adds mention of source in the docs.

edit: rebased the PR to solve a conflict too.

@talldan talldan force-pushed the try/filter-out-core-patterns branch from e0d5c25 to 7ea3b03 Compare June 20, 2023 07:55
Copy link
Contributor

@talldan talldan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me.

There will be a PHP backport of this code to WordPress core, so that's a further opportunity to leave feedback, and we can replicate any changes back to the Gutenberg codebase.

I think the one thing missing right now is tests, so it'll be good to include some in the backport PR.

Copy link
Contributor

@glendaviesnz glendaviesnz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@aaronrobertshaw aaronrobertshaw enabled auto-merge (squash) June 21, 2023 01:51
@aaronrobertshaw aaronrobertshaw merged commit c819200 into trunk Jun 21, 2023
@aaronrobertshaw aaronrobertshaw deleted the try/filter-out-core-patterns branch June 21, 2023 02:27
@github-actions github-actions bot added this to the Gutenberg 16.1 milestone Jun 21, 2023
@ramonjd ramonjd added the Needs PHP backport Needs PHP backport to Core label Jun 26, 2023
@ramonjd ramonjd removed the Needs PHP backport Needs PHP backport to Core label Jun 30, 2023
sethrubenstein pushed a commit to pewresearch/gutenberg that referenced this pull request Jul 13, 2023
…51672)

---------

Co-authored-by: kevin940726 <kai@kaihao.dev>
Co-authored-by: Daniel Richards <daniel.richards@automattic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants