Skip to content

Commit

Permalink
Add edit context to patterns REST controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras committed Apr 12, 2022
1 parent a1227f8 commit b0ba8cb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
21 changes: 15 additions & 6 deletions lib/compat/wordpress-6.0/block-patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,31 +98,38 @@ function gutenberg_register_theme_block_patterns() {

foreach ( $themes as $theme ) {
$dirpath = $theme->get_stylesheet_directory() . '/patterns/';
if ( ! is_dir( $dirpath ) || ! is_readable( $dirpath ) ) {
continue;
}
if ( file_exists( $dirpath ) ) {
$files = glob( $dirpath . '*.php' );
if ( $files ) {
foreach ( $files as $file ) {
$pattern_data = get_file_data( $file, $default_headers );

if ( empty( $pattern_data['slug'] ) ) {
trigger_error(
_doing_it_wrong(
'_register_theme_block_patterns',
sprintf(
/* translators: %s: file name. */
__( 'Could not register file "%s" as a block pattern ("Slug" field missing)', 'gutenberg' ),
$file
)
),
'6.0.0'
);
continue;
}

if ( ! preg_match( '/^[A-z0-9\/_-]+$/', $pattern_data['slug'] ) ) {
trigger_error(
_doing_it_wrong(
'_register_theme_block_patterns',
sprintf(
/* translators: %1s: file name; %2s: slug value found. */
__( 'Could not register file "%1$s" as a block pattern (invalid slug "%2$s")', 'gutenberg' ),
$file,
$pattern_data['slug']
)
),
'6.0.0'
);
}

Expand All @@ -132,12 +139,14 @@ function gutenberg_register_theme_block_patterns() {

// Title is a required property.
if ( ! $pattern_data['title'] ) {
trigger_error(
_doing_it_wrong(
'_register_theme_block_patterns',
sprintf(
/* translators: %1s: file name; %2s: slug value found. */
__( 'Could not register file "%s" as a block pattern ("Title" field missing)', 'gutenberg' ),
$file
)
),
'6.0.0'
);
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ public function get_item_schema() {
'description' => __( 'The category name.', 'gutenberg' ),
'type' => 'string',
'readonly' => true,
'context' => array( 'view', 'embed' ),
'context' => array( 'view', 'edit', 'embed' ),
),
'label' => array(
'description' => __( 'The category label, in human readable format.', 'gutenberg' ),
'type' => 'string',
'readonly' => true,
'context' => array( 'view', 'embed' ),
'context' => array( 'view', 'edit', 'embed' ),
),
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,49 +148,49 @@ public function get_item_schema() {
'description' => __( 'The pattern name.', 'gutenberg' ),
'type' => 'string',
'readonly' => true,
'context' => array( 'view', 'embed' ),
'context' => array( 'view', 'edit', 'embed' ),
),
'title' => array(
'description' => __( 'The pattern title, in human readable format.', 'gutenberg' ),
'type' => 'string',
'readonly' => true,
'context' => array( 'view', 'embed' ),
'context' => array( 'view', 'edit', 'embed' ),
),
'description' => array(
'description' => __( 'The pattern detailed description.', 'gutenberg' ),
'type' => 'string',
'readonly' => true,
'context' => array( 'view', 'embed' ),
'context' => array( 'view', 'edit', 'embed' ),
),
'viewport_width' => array(
'description' => __( 'The pattern viewport width for inserter preview.', 'gutenberg' ),
'type' => 'number',
'readonly' => true,
'context' => array( 'view', 'embed' ),
'context' => array( 'view', 'edit', 'embed' ),
),
'block_types' => array(
'description' => __( 'Block types that the pattern is intended to be used with.', 'gutenberg' ),
'type' => 'array',
'readonly' => true,
'context' => array( 'view', 'embed' ),
'context' => array( 'view', 'edit', 'embed' ),
),
'categories' => array(
'description' => __( 'The pattern category slugs.', 'gutenberg' ),
'type' => 'array',
'readonly' => true,
'context' => array( 'view', 'embed' ),
'context' => array( 'view', 'edit', 'embed' ),
),
'keywords' => array(
'description' => __( 'The pattern keywords.', 'gutenberg' ),
'type' => 'array',
'readonly' => true,
'context' => array( 'view', 'embed' ),
'context' => array( 'view', 'edit', 'embed' ),
),
'content' => array(
'description' => __( 'The pattern content.', 'gutenberg' ),
'type' => 'string',
'readonly' => true,
'context' => array( 'view', 'embed' ),
'context' => array( 'view', 'edit', 'embed' ),
),
),
);
Expand Down

0 comments on commit b0ba8cb

Please sign in to comment.