Skip to content

Commit

Permalink
Update: Reverse backport changes on post type REST API changes. (#62751)
Browse files Browse the repository at this point in the history
Co-authored-by: jorgefilipecosta <jorgefilipecosta@git.wordpress.org>
Co-authored-by: ellatrix <ellatrix@git.wordpress.org>
  • Loading branch information
3 people committed Jun 25, 2024
1 parent 4c59025 commit 70ff7c8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
16 changes: 8 additions & 8 deletions lib/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ function gutenberg_register_wp_rest_post_types_controller_fields() {
array(
'get_callback' => function ( $item ) {
$post_type = get_post_type_object( $item['slug'] );
if ( ! empty( $post_type ) && ! empty( $post_type->template ) ) {
return $post_type->template;
if ( ! empty( $post_type ) ) {
return $post_type->template ?? array();
}
},
'schema' => array(
'type' => 'array',
'description' => __( 'The block template associated with the post type, if it exists.', 'gutenberg' ),
'description' => __( 'The block template associated with the post type.', 'gutenberg' ),
'readonly' => true,
'context' => array( 'view', 'edit', 'embed' ),
),
Expand All @@ -48,14 +48,14 @@ function gutenberg_register_wp_rest_post_types_controller_fields() {
array(
'get_callback' => function ( $item ) {
$post_type = get_post_type_object( $item['slug'] );
if ( ! empty( $post_type ) && ! empty( $post_type->template_lock ) && false !== $post_type->template_lock ) {
return $post_type->template_lock;
if ( ! empty( $post_type ) ) {
return ! empty( $post_type->template_lock ) ? $post_type->template_lock : false;
}
},
'schema' => array(
'type' => 'string',
'enum' => array( 'all', 'insert', 'contentOnly' ),
'description' => __( 'The template_lock associated with the post type, if any.', 'gutenberg' ),
'type' => array( 'string', 'boolean' ),
'enum' => array( 'all', 'insert', 'contentOnly', false ),
'description' => __( 'The template_lock associated with the post type, or false if none.', 'gutenberg' ),
'readonly' => true,
'context' => array( 'view', 'edit', 'embed' ),
),
Expand Down
17 changes: 9 additions & 8 deletions packages/edit-site/src/components/add-new-page/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ export default function AddNewPageModal( { onSave, onClose } ) {
status: 'draft',
title,
slug: title || __( 'No title' ),
content: !! pagePostType.template
? serialize(
synchronizeBlocksWithTemplate(
[],
pagePostType.template
)
)
: undefined,
content:
!! pagePostType.template && pagePostType.template.length
? serialize(
synchronizeBlocksWithTemplate(
[],
pagePostType.template
)
)
: undefined,
},
{ throwOnError: true }
);
Expand Down

0 comments on commit 70ff7c8

Please sign in to comment.