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

__experimentalBlockPatterns: load them with REST API #39185

Merged
merged 30 commits into from
Mar 28, 2022
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
528325b
Add REST endpoint to fetch registered block patterns
jsnajdr Mar 1, 2022
fa4e1f5
Core Data: add getBlockPatterns selector (with resolver and state)
jsnajdr Mar 1, 2022
78cbd56
Editor: fetch block patterns from REST if not supplied in editor sett…
jsnajdr Mar 1, 2022
e810c38
Site Editor: fetch block patterns from REST, don't preload in settings
jsnajdr Mar 3, 2022
4b43ef7
Remove __experimentalBlockPatterns from settings generated by Core
jsnajdr Mar 3, 2022
f7d681a
Re-add the request param
jsnajdr Mar 4, 2022
3fc42fd
Move the patterns endpoint to experimental namespace, change name
jsnajdr Mar 16, 2022
84d3c4e
Disable lint error about unused parameter
jsnajdr Mar 17, 2022
65735f5
Sync schema descriptions with pattern directory endpoint
jsnajdr Mar 17, 2022
2d01beb
Move the REST endpoint to lib/compat/wordpress-6.0
jsnajdr Mar 17, 2022
2368d78
Load remote block patterns when processing the REST request
jsnajdr Mar 17, 2022
c7c6fbf
Implement prepare_item_for_response
jsnajdr Mar 17, 2022
c1a55d9
Prevent loading remote block patterns in site/post editor, limit to REST
jsnajdr Mar 17, 2022
a71161e
Fix name of the REST controller file
jsnajdr Mar 17, 2022
28f9c91
Fix code style nits reported by linter
jsnajdr Mar 17, 2022
3642a83
Add context support
jsnajdr Mar 17, 2022
92b5c2a
Stop calling gutenberg_register_remote_theme_patterns in site/post ed…
jsnajdr Mar 17, 2022
b6cd4dd
Document filter param
jsnajdr Mar 17, 2022
9663f48
Add REST endpoint for block pattern categories
jsnajdr Mar 17, 2022
b864fa0
Core Data: add getBlockPatternCategories selector (with resolver and …
jsnajdr Mar 17, 2022
124196e
Load block pattern categories from REST instead of settings
jsnajdr Mar 17, 2022
f5be609
Remove block pattern categories from server-generated editor settings
jsnajdr Mar 17, 2022
e1f3e3e
Fix spacing issues
jsnajdr Mar 17, 2022
8d41a92
Return only requested fields
jsnajdr Mar 22, 2022
5896ea3
Unit tests for the REST controllers
jsnajdr Mar 22, 2022
0f35b2c
Fixup action field name when receiving categories
jsnajdr Mar 23, 2022
71d6c78
Use mock registries in unit tests
jsnajdr Mar 24, 2022
bbe130c
Add missing pattern properties
jsnajdr Mar 24, 2022
e8c1a9c
Restore original registry instance after test is finished
jsnajdr Mar 28, 2022
f2edbd5
Add PHP docs comments to unit test suites
jsnajdr Mar 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix code style nits reported by linter
  • Loading branch information
jsnajdr committed Mar 28, 2022
commit 28f9c911fb34555696211393b7a656a833fc21ab
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ public function get_items_permissions_check( $request ) { // phpcs:ignore Variab
*/
public function get_items( $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
// Load block patterns from w.org.
Copy link
Member

Choose a reason for hiding this comment

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

Is there value in allow to limit the query by category?

_load_remote_block_patterns(); // patterns with the `core` keyword
_load_remote_featured_patterns(); // patterns in the `featured` category
gutenberg_register_remote_theme_patterns(); // patterns requested by current theme
_load_remote_block_patterns(); // Patterns with the `core` keyword.
_load_remote_featured_patterns(); // Patterns in the `featured` category.
gutenberg_register_remote_theme_patterns(); // Patterns requested by current theme.

$response = array();
$patterns = WP_Block_Patterns_Registry::get_instance()->get_all_registered();
foreach ( $patterns as $pattern ) {
$prepared_pattern = $this->prepare_item_for_response( $pattern, $request );
$response[] = $this->prepare_response_for_collection( $prepared_pattern );
$response[] = $this->prepare_response_for_collection( $prepared_pattern );
}
return rest_ensure_response( $response );
}
Expand All @@ -98,11 +98,11 @@ public function get_items( $request ) { // phpcs:ignore VariableAnalysis.CodeAna
*/
public function prepare_item_for_response( $item, $request ) {
$prepared_pattern = array(
'name' => $item['name'],
'title' => $item['title'],
'blockTypes' => $item['blockTypes'],
'categories' => $item['categories'],
'content' => $item['content'],
'name' => $item['name'],
'title' => $item['title'],
'blockTypes' => $item['blockTypes'],
'categories' => $item['categories'],
'content' => $item['content'],
);

$prepared_pattern = $this->add_additional_fields_to_object( $prepared_pattern, $request );
Expand All @@ -127,7 +127,7 @@ public function get_item_schema() {
'readonly' => true,
),
'name' => array(
'description' => __( "The pattern name.", 'gutenberg' ),
'description' => __( 'The pattern name.', 'gutenberg' ),
'type' => 'string',
'readonly' => true,
),
Expand Down