<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[52186] trunk: REST API: Make the templates controller follow core REST patterns.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/52186">52186</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/52186","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>spacedmonkey</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2021-11-16 18:04:49 +0000 (Tue, 16 Nov 2021)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>REST API: Make the templates controller follow core REST patterns.

The templates controller now respects the `_fields` parameter and filters the response accordingly. The schema has been updated to include all the fields returned. The `content.block_version` field has been added. The controller now returns WP_Error objects for improved error handling.

Add new unit tests.

Props TimothyBlynJacobs, hellofromtonya, zieladam.
Fixes <a href="https://core.trac.wordpress.org/ticket/54422">#54422</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswpresttemplatescontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php</a></li>
<li><a href="#trunktestsqunitfixtureswpapigeneratedjs">trunk/tests/qunit/fixtures/wp-api-generated.js</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunktestsphpunittestsrestapiwpRestTemplatesControllerphp">trunk/tests/phpunit/tests/rest-api/wpRestTemplatesController.php</a></li>
</ul>

<h3>Removed Paths</h3>
<ul>
<li><a href="#trunktestsphpunittestsrestapiresttemplatescontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-templates-controller.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesrestapiendpointsclasswpresttemplatescontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php   2021-11-16 17:16:07 UTC (rev 52185)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php     2021-11-16 18:04:49 UTC (rev 52186)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -70,15 +70,18 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->namespace,
</span><span class="cx" style="display: block; padding: 0 10px">                        '/' . $this->rest_base . '/(?P<id>[\/\w-]+)',
</span><span class="cx" style="display: block; padding: 0 10px">                        array(
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'args'   => array(
+                                       'id' => array(
+                                               'description' => __( 'The id of a template' ),
+                                               'type'        => 'string',
+                                       ),
+                               ),
</ins><span class="cx" style="display: block; padding: 0 10px">                                 array(
</span><span class="cx" style="display: block; padding: 0 10px">                                        'methods'             => WP_REST_Server::READABLE,
</span><span class="cx" style="display: block; padding: 0 10px">                                        'callback'            => array( $this, 'get_item' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                        'permission_callback' => array( $this, 'get_item_permissions_check' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                        'args'                => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                'id' => array(
-                                                       'description' => __( 'The id of a template' ),
-                                                       'type'        => 'string',
-                                               ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                         'context' => $this->get_context_param( array( 'default' => 'view' ) ),
</ins><span class="cx" style="display: block; padding: 0 10px">                                         ),
</span><span class="cx" style="display: block; padding: 0 10px">                                ),
</span><span class="cx" style="display: block; padding: 0 10px">                                array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -231,7 +234,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                if ( isset( $request['source'] ) && 'theme' === $request['source'] ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        wp_delete_post( $template->wp_id, true );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return $this->prepare_item_for_response( get_block_file_template( $request['id'], $this->post_type ), $request );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $request->set_param( 'context', 'edit' );
+
+                       $template = get_block_template( $request['id'], $this->post_type );
+                       $response = $this->prepare_item_for_response( $template, $request );
+
+                       return rest_ensure_response( $response );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $changes = $this->prepare_item_for_database( $request );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -241,7 +249,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                } else {
</span><span class="cx" style="display: block; padding: 0 10px">                        $result = wp_insert_post( wp_slash( (array) $changes ), true );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( is_wp_error( $result ) ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        if ( 'db_update_error' === $result->get_error_code() ) {
+                               $result->add_data( array( 'status' => 500 ) );
+                       } else {
+                               $result->add_data( array( 'status' => 400 ) );
+                       }
</ins><span class="cx" style="display: block; padding: 0 10px">                         return $result;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -251,10 +265,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        return $fields_update;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                return $this->prepare_item_for_response(
-                       get_block_template( $request['id'], $this->post_type ),
-                       $request
-               );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $request->set_param( 'context', 'edit' );
+
+               $response = $this->prepare_item_for_response( $template, $request );
+
+               return rest_ensure_response( $response );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -278,15 +293,21 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function create_item( $request ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $changes            = $this->prepare_item_for_database( $request );
-               $changes->post_name = $request['slug'];
-               $result             = wp_insert_post( wp_slash( (array) $changes ), true );
-               if ( is_wp_error( $result ) ) {
-                       return $result;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $prepared_post            = $this->prepare_item_for_database( $request );
+               $prepared_post->post_name = $request['slug'];
+               $post_id                  = wp_insert_post( wp_slash( (array) $prepared_post ), true );
+               if ( is_wp_error( $post_id ) ) {
+                       if ( 'db_insert_error' === $post_id->get_error_code() ) {
+                               $post_id->add_data( array( 'status' => 500 ) );
+                       } else {
+                               $post_id->add_data( array( 'status' => 400 ) );
+                       }
+
+                       return $post_id;
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $posts = get_block_templates( array( 'wp_id' => $result ), $this->post_type );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $posts = get_block_templates( array( 'wp_id' => $post_id ), $this->post_type );
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( ! count( $posts ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return new WP_Error( 'rest_template_insert_error', __( 'No templates exist with that id.' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return new WP_Error( 'rest_template_insert_error', __( 'No templates exist with that id.' ), array( 'status' => 400 ) );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px">                $id            = $posts[0]->id;
</span><span class="cx" style="display: block; padding: 0 10px">                $template      = get_block_template( $id, $this->post_type );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -295,10 +316,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        return $fields_update;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                return $this->prepare_item_for_response(
-                       get_block_template( $id, $this->post_type ),
-                       $request
-               );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $response = $this->prepare_item_for_response( $template, $request );
+               $response = rest_ensure_response( $response );
+
+               $response->set_status( 201 );
+               $response->header( 'Location', rest_url( sprintf( '%s/%s/%s', $this->namespace, $this->rest_base, $template->id ) ) );
+
+               return $response;
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -333,10 +357,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $id    = $template->wp_id;
</span><span class="cx" style="display: block; padding: 0 10px">                $force = (bool) $request['force'];
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $request->set_param( 'context', 'edit' );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 // If we're forcing, then delete permanently.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $force ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $previous = $this->prepare_item_for_response( $template, $request );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        wp_delete_post( $id, true );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $result   = wp_delete_post( $id, true );
</ins><span class="cx" style="display: block; padding: 0 10px">                         $response = new WP_REST_Response();
</span><span class="cx" style="display: block; padding: 0 10px">                        $response->set_data(
</span><span class="cx" style="display: block; padding: 0 10px">                                array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -344,22 +370,32 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                        'previous' => $previous->get_data(),
</span><span class="cx" style="display: block; padding: 0 10px">                                )
</span><span class="cx" style="display: block; padding: 0 10px">                        );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                } else {
+                       // Otherwise, only trash if we haven't already.
+                       if ( 'trash' === $template->status ) {
+                               return new WP_Error(
+                                       'rest_template_already_trashed',
+                                       __( 'The template has already been deleted.' ),
+                                       array( 'status' => 410 )
+                               );
+                       }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return $response;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 // (Note that internally this falls through to `wp_delete_post()`
+                       // if the Trash is disabled.)
+                       $result           = wp_trash_post( $id );
+                       $template->status = 'trash';
+                       $response         = $this->prepare_item_for_response( $template, $request );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // Otherwise, only trash if we haven't already.
-               if ( 'trash' === $template->status ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( ! $result ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         return new WP_Error(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                'rest_template_already_trashed',
-                               __( 'The template has already been deleted.' ),
-                               array( 'status' => 410 )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         'rest_cannot_delete',
+                               __( 'The template cannot be deleted.' ),
+                               array( 'status' => 500 )
</ins><span class="cx" style="display: block; padding: 0 10px">                         );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                wp_trash_post( $id );
-               $template->status = 'trash';
-               return $this->prepare_item_for_response( $template, $request );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         return $response;
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -392,12 +428,20 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $changes->post_status = 'publish';
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px">                if ( isset( $request['content'] ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $changes->post_content = $request['content'];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( is_string( $request['content'] ) ) {
+                               $changes->post_content = $request['content'];
+                       } elseif ( isset( $request['content']['raw'] ) ) {
+                               $changes->post_content = $request['content']['raw'];
+                       }
</ins><span class="cx" style="display: block; padding: 0 10px">                 } elseif ( null !== $template && 'custom' !== $template->source ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $changes->post_content = $template->content;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px">                if ( isset( $request['title'] ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $changes->post_title = $request['title'];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( is_string( $request['title'] ) ) {
+                               $changes->post_title = $request['title'];
+                       } elseif ( ! empty( $request['title']['raw'] ) ) {
+                               $changes->post_title = $request['title']['raw'];
+                       }
</ins><span class="cx" style="display: block; padding: 0 10px">                 } elseif ( null !== $template && 'custom' !== $template->source ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $changes->post_title = $template->title;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -433,31 +477,88 @@
</span><span class="cx" style="display: block; padding: 0 10px">        public function prepare_item_for_response( $item, $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
</span><span class="cx" style="display: block; padding: 0 10px">                // Restores the more descriptive, specific name for use within this method.
</span><span class="cx" style="display: block; padding: 0 10px">                $template = $item;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $result   = array(
-                       'id'             => $template->id,
-                       'theme'          => $template->theme,
-                       'content'        => array( 'raw' => $template->content ),
-                       'slug'           => $template->slug,
-                       'source'         => $template->source,
-                       'type'           => $template->type,
-                       'description'    => $template->description,
-                       'title'          => array(
-                               'raw'      => $template->title,
-                               'rendered' => $template->title,
-                       ),
-                       'status'         => $template->status,
-                       'wp_id'          => $template->wp_id,
-                       'has_theme_file' => $template->has_theme_file,
-               );
</del><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( 'wp_template_part' === $template->type ) {
-                       $result['area'] = $template->area;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $fields = $this->get_fields_for_response( $request );
+
+               // Base fields for every template.
+               $data = array();
+
+               if ( rest_is_field_included( 'id', $fields ) ) {
+                       $data['id'] = $template->id;
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $result = $this->add_additional_fields_to_object( $result, $request );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( rest_is_field_included( 'theme', $fields ) ) {
+                       $data['theme'] = $template->theme;
+               }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $response = rest_ensure_response( $result );
-               $links    = $this->prepare_links( $template->id );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( rest_is_field_included( 'content', $fields ) ) {
+                       $data['content'] = array();
+               }
+               if ( rest_is_field_included( 'content.raw', $fields ) ) {
+                       $data['content']['raw'] = $template->content;
+               }
+
+               if ( rest_is_field_included( 'content.block_version', $fields ) ) {
+                       $data['content']['block_version'] = block_version( $template->content );
+               }
+
+               if ( rest_is_field_included( 'slug', $fields ) ) {
+                       $data['slug'] = $template->slug;
+               }
+
+               if ( rest_is_field_included( 'source', $fields ) ) {
+                       $data['source'] = $template->source;
+               }
+
+               if ( rest_is_field_included( 'type', $fields ) ) {
+                       $data['type'] = $template->type;
+               }
+
+               if ( rest_is_field_included( 'description', $fields ) ) {
+                       $data['description'] = $template->description;
+               }
+
+               if ( rest_is_field_included( 'title', $fields ) ) {
+                       $data['title'] = array();
+               }
+
+               if ( rest_is_field_included( 'title.raw', $fields ) ) {
+                       $data['title']['raw'] = $template->title;
+               }
+
+               if ( rest_is_field_included( 'title.rendered', $fields ) ) {
+                       if ( $template->wp_id ) {
+                               /** This filter is documented in wp-includes/post-template.php */
+                               $data['title']['rendered'] = apply_filters( 'the_title', $template->title, $template->wp_id );
+                       } else {
+                               $data['title']['rendered'] = $template->title;
+                       }
+               }
+
+               if ( rest_is_field_included( 'status', $fields ) ) {
+                       $data['status'] = $template->status;
+               }
+
+               if ( rest_is_field_included( 'wp_id', $fields ) ) {
+                       $data['wp_id'] = (int) $template->wp_id;
+               }
+
+               if ( rest_is_field_included( 'has_theme_file', $fields ) ) {
+                       $data['has_theme_file'] = (bool) $template->has_theme_file;
+               }
+
+               if ( rest_is_field_included( 'area', $fields ) && 'wp_template_part' === $template->type ) {
+                       $data['area'] = $template->area;
+               }
+
+               $context = ! empty( $request['context'] ) ? $request['context'] : 'view';
+               $data    = $this->add_additional_fields_to_object( $data, $request );
+               $data    = $this->filter_response_by_context( $data, $context );
+
+               // Wrap the data in a response object.
+               $response = rest_ensure_response( $data );
+
+               $links = $this->prepare_links( $template->id );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $response->add_links( $links );
</span><span class="cx" style="display: block; padding: 0 10px">                if ( ! empty( $links['self']['href'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $actions = $this->get_available_actions();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -530,7 +631,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function get_collection_params() {
</span><span class="cx" style="display: block; padding: 0 10px">                return array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'context'   => $this->get_context_param(),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'context'   => $this->get_context_param( array( 'default' => 'view' ) ),
</ins><span class="cx" style="display: block; padding: 0 10px">                         'wp_id'     => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'description' => __( 'Limit to the specified post id.' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                'type'        => 'integer',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -583,6 +684,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                        'type'        => 'string',
</span><span class="cx" style="display: block; padding: 0 10px">                                        'context'     => array( 'embed', 'view', 'edit' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                ),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'type'           => array(
+                                       'description' => __( 'Type of template.' ),
+                                       'type'        => 'string',
+                                       'context'     => array( 'embed', 'view', 'edit' ),
+                               ),
</ins><span class="cx" style="display: block; padding: 0 10px">                                 'source'         => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                        'description' => __( 'Source of template' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                        'type'        => 'string',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -594,6 +700,19 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                        'type'        => array( 'object', 'string' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                        'default'     => '',
</span><span class="cx" style="display: block; padding: 0 10px">                                        'context'     => array( 'embed', 'view', 'edit' ),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                        'properties'  => array(
+                                               'raw'           => array(
+                                                       'description' => __( 'Content for the template, as it exists in the database.' ),
+                                                       'type'        => 'string',
+                                                       'context'     => array( 'view', 'edit' ),
+                                               ),
+                                               'block_version' => array(
+                                                       'description' => __( 'Version of the content block format used by the template.' ),
+                                                       'type'        => 'integer',
+                                                       'context'     => array( 'edit' ),
+                                                       'readonly'    => true,
+                                               ),
+                                       ),
</ins><span class="cx" style="display: block; padding: 0 10px">                                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                                'title'          => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                        'description' => __( 'Title of template.' ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -600,6 +719,19 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                        'type'        => array( 'object', 'string' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                        'default'     => '',
</span><span class="cx" style="display: block; padding: 0 10px">                                        'context'     => array( 'embed', 'view', 'edit' ),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                        'properties'  => array(
+                                               'raw'      => array(
+                                                       'description' => __( 'Title for the template, as it exists in the database.' ),
+                                                       'type'        => 'string',
+                                                       'context'     => array( 'view', 'edit', 'embed' ),
+                                               ),
+                                               'rendered' => array(
+                                                       'description' => __( 'HTML title for the template, transformed for display.' ),
+                                                       'type'        => 'string',
+                                                       'context'     => array( 'view', 'edit', 'embed' ),
+                                                       'readonly'    => true,
+                                               ),
+                                       ),
</ins><span class="cx" style="display: block; padding: 0 10px">                                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                                'description'    => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                        'description' => __( 'Description of template.' ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -610,6 +742,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'status'         => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                        'description' => __( 'Status of template.' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                        'type'        => 'string',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                        'enum'        => array_keys( get_post_stati( array( 'internal' => false ) ) ),
</ins><span class="cx" style="display: block; padding: 0 10px">                                         'default'     => 'publish',
</span><span class="cx" style="display: block; padding: 0 10px">                                        'context'     => array( 'embed', 'view', 'edit' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                ),
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapiresttemplatescontrollerphp"></a>
<div class="delfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Deleted: trunk/tests/phpunit/tests/rest-api/rest-templates-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-templates-controller.php  2021-11-16 17:16:07 UTC (rev 52185)
+++ trunk/tests/phpunit/tests/rest-api/rest-templates-controller.php    2021-11-16 18:04:49 UTC (rev 52186)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,197 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-/**
- * Unit tests covering the templates endpoint..
- *
- * @package WordPress
- * @subpackage REST API
- */
-
-class WP_REST_Template_Controller_Test extends WP_Test_REST_Controller_Testcase {
-       /**
-        * @var int
-        */
-       protected static $admin_id;
-       private static $post;
-
-       /**
-        * Create fake data before our tests run.
-        *
-        * @param WP_UnitTest_Factory $factory Helper that lets us create fake data.
-        */
-       public static function wpSetupBeforeClass( $factory ) {
-               self::$admin_id = $factory->user->create(
-                       array(
-                               'role' => 'administrator',
-                       )
-               );
-
-               // Set up template post.
-               $args       = array(
-                       'post_type'    => 'wp_template',
-                       'post_name'    => 'my_template',
-                       'post_title'   => 'My Template',
-                       'post_content' => 'Content',
-                       'post_excerpt' => 'Description of my template.',
-                       'tax_input'    => array(
-                               'wp_theme' => array(
-                                       get_stylesheet(),
-                               ),
-                       ),
-               );
-               self::$post = self::factory()->post->create_and_get( $args );
-               wp_set_post_terms( self::$post->ID, get_stylesheet(), 'wp_theme' );
-       }
-
-       public static function wpTearDownAfterClass() {
-               wp_delete_post( self::$post->ID );
-       }
-
-
-       public function test_register_routes() {
-               $routes = rest_get_server()->get_routes();
-               $this->assertArrayHasKey( '/wp/v2/templates', $routes );
-               $this->assertArrayHasKey( '/wp/v2/templates/(?P<id>[\/\w-]+)', $routes );
-       }
-
-       public function test_context_param() {
-               // TODO: Implement test_context_param() method.
-       }
-
-       public function test_get_items() {
-               function find_and_normalize_template_by_id( $templates, $id ) {
-                       foreach ( $templates as $template ) {
-                               if ( $template['id'] === $id ) {
-                                       unset( $template['content'] );
-                                       unset( $template['_links'] );
-                                       return $template;
-                               }
-                       }
-
-                       return null;
-               }
-
-               wp_set_current_user( 0 );
-               $request  = new WP_REST_Request( 'GET', '/wp/v2/templates' );
-               $response = rest_get_server()->dispatch( $request );
-               $this->assertErrorResponse( 'rest_cannot_manage_templates', $response, 401 );
-
-               wp_set_current_user( self::$admin_id );
-               $request  = new WP_REST_Request( 'GET', '/wp/v2/templates' );
-               $response = rest_get_server()->dispatch( $request );
-               $data     = $response->get_data();
-
-               $this->assertSame(
-                       array(
-                               'id'             => 'default//my_template',
-                               'theme'          => 'default',
-                               'slug'           => 'my_template',
-                               'source'         => 'custom',
-                               'type'           => 'wp_template',
-                               'description'    => 'Description of my template.',
-                               'title'          => array(
-                                       'raw'      => 'My Template',
-                                       'rendered' => 'My Template',
-                               ),
-                               'status'         => 'publish',
-                               'wp_id'          => self::$post->ID,
-                               'has_theme_file' => false,
-                       ),
-                       find_and_normalize_template_by_id( $data, 'default//my_template' )
-               );
-       }
-
-       public function test_get_item() {
-               wp_set_current_user( self::$admin_id );
-               $request  = new WP_REST_Request( 'GET', '/wp/v2/templates/default//my_template' );
-               $response = rest_get_server()->dispatch( $request );
-               $data     = $response->get_data();
-               unset( $data['content'] );
-               unset( $data['_links'] );
-
-               $this->assertSame(
-                       array(
-                               'id'             => 'default//my_template',
-                               'theme'          => 'default',
-                               'slug'           => 'my_template',
-                               'source'         => 'custom',
-                               'type'           => 'wp_template',
-                               'description'    => 'Description of my template.',
-                               'title'          => array(
-                                       'raw'      => 'My Template',
-                                       'rendered' => 'My Template',
-                               ),
-                               'status'         => 'publish',
-                               'wp_id'          => self::$post->ID,
-                               'has_theme_file' => false,
-                       ),
-                       $data
-               );
-       }
-
-       public function test_create_item() {
-               wp_set_current_user( self::$admin_id );
-               $request = new WP_REST_Request( 'POST', '/wp/v2/templates' );
-               $request->set_body_params(
-                       array(
-                               'slug'        => 'my_custom_template',
-                               'description' => 'Just a description',
-                               'title'       => 'My Template',
-                               'content'     => 'Content',
-                       )
-               );
-               $response = rest_get_server()->dispatch( $request );
-               $data     = $response->get_data();
-               unset( $data['_links'] );
-               unset( $data['wp_id'] );
-
-               $this->assertSame(
-                       array(
-                               'id'             => 'default//my_custom_template',
-                               'theme'          => 'default',
-                               'content'        => array(
-                                       'raw' => 'Content',
-                               ),
-                               'slug'           => 'my_custom_template',
-                               'source'         => 'custom',
-                               'type'           => 'wp_template',
-                               'description'    => 'Just a description',
-                               'title'          => array(
-                                       'raw'      => 'My Template',
-                                       'rendered' => 'My Template',
-                               ),
-                               'status'         => 'publish',
-                               'has_theme_file' => false,
-                       ),
-                       $data
-               );
-       }
-
-       public function test_update_item() {
-               wp_set_current_user( self::$admin_id );
-               $request = new WP_REST_Request( 'PUT', '/wp/v2/templates/default//my_template' );
-               $request->set_body_params(
-                       array(
-                               'title' => 'My new Index Title',
-                       )
-               );
-               $response = rest_get_server()->dispatch( $request );
-               $data     = $response->get_data();
-               $this->assertSame( 'My new Index Title', $data['title']['raw'] );
-               $this->assertSame( 'custom', $data['source'] );
-       }
-
-       public function test_delete_item() {
-               wp_set_current_user( self::$admin_id );
-               $request  = new WP_REST_Request( 'DELETE', '/wp/v2/templates/justrandom//template' );
-               $response = rest_get_server()->dispatch( $request );
-               $this->assertErrorResponse( 'rest_template_not_found', $response, 404 );
-       }
-
-       public function test_prepare_item() {
-               // TODO: Implement test_prepare_item() method.
-       }
-
-       public function test_get_item_schema() {
-               // TODO: Implement test_get_item_schema() method.
-       }
-}
</del></span></pre></div>
<a id="trunktestsphpunittestsrestapiwpRestTemplatesControllerphpfromrev52185trunktestsphpunittestsrestapiresttemplatescontrollerphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: trunk/tests/phpunit/tests/rest-api/wpRestTemplatesController.php (from rev 52185, trunk/tests/phpunit/tests/rest-api/rest-templates-controller.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/wpRestTemplatesController.php                          (rev 0)
+++ trunk/tests/phpunit/tests/rest-api/wpRestTemplatesController.php    2021-11-16 18:04:49 UTC (rev 52186)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,400 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * Unit tests covering the templates endpoint..
+ *
+ * @package WordPress
+ * @subpackage REST API
+ */
+
+/**
+ * Tests for REST API for templates.
+ *
+ * @covers WP_REST_Templates_Controller
+ *
+ * @group restapi
+ */
+class Tests_REST_WpRestTemplatesController extends WP_Test_REST_Controller_Testcase {
+       /**
+        * @var int
+        */
+       protected static $admin_id;
+       private static $post;
+
+       /**
+        * Create fake data before our tests run.
+        *
+        * @param WP_UnitTest_Factory $factory Helper that lets us create fake data.
+        */
+       public static function wpSetupBeforeClass( $factory ) {
+               self::$admin_id = $factory->user->create(
+                       array(
+                               'role' => 'administrator',
+                       )
+               );
+
+               // Set up template post.
+               $args       = array(
+                       'post_type'    => 'wp_template',
+                       'post_name'    => 'my_template',
+                       'post_title'   => 'My Template',
+                       'post_content' => 'Content',
+                       'post_excerpt' => 'Description of my template.',
+                       'tax_input'    => array(
+                               'wp_theme' => array(
+                                       get_stylesheet(),
+                               ),
+                       ),
+               );
+               self::$post = self::factory()->post->create_and_get( $args );
+               wp_set_post_terms( self::$post->ID, get_stylesheet(), 'wp_theme' );
+       }
+
+       public static function wpTearDownAfterClass() {
+               wp_delete_post( self::$post->ID );
+       }
+
+
+       public function test_register_routes() {
+               $routes = rest_get_server()->get_routes();
+               $this->assertArrayHasKey( '/wp/v2/templates', $routes );
+               $this->assertArrayHasKey( '/wp/v2/templates/(?P<id>[\/\w-]+)', $routes );
+       }
+
+       /**
+        * @covers WP_REST_Templates_Controller::get_context_param
+        */
+       public function test_context_param() {
+               // Collection.
+               $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/templates' );
+               $response = rest_get_server()->dispatch( $request );
+               $data     = $response->get_data();
+               $this->assertSame( 'view', $data['endpoints'][0]['args']['context']['default'] );
+               $this->assertSame( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
+               // Single.
+               $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/templates/default//my_template' );
+               $response = rest_get_server()->dispatch( $request );
+               $data     = $response->get_data();
+               $this->assertSame( 'view', $data['endpoints'][0]['args']['context']['default'] );
+               $this->assertSame( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
+       }
+
+       /**
+        * @covers WP_REST_Templates_Controller::get_items
+        */
+       public function test_get_items() {
+               wp_set_current_user( self::$admin_id );
+               $request  = new WP_REST_Request( 'GET', '/wp/v2/templates' );
+               $response = rest_get_server()->dispatch( $request );
+               $data     = $response->get_data();
+
+               $this->assertSame(
+                       array(
+                               'id'             => 'default//my_template',
+                               'theme'          => 'default',
+                               'slug'           => 'my_template',
+                               'source'         => 'custom',
+                               'type'           => 'wp_template',
+                               'description'    => 'Description of my template.',
+                               'title'          => array(
+                                       'raw'      => 'My Template',
+                                       'rendered' => 'My Template',
+                               ),
+                               'status'         => 'publish',
+                               'wp_id'          => self::$post->ID,
+                               'has_theme_file' => false,
+                       ),
+                       $this->find_and_normalize_template_by_id( $data, 'default//my_template' )
+               );
+       }
+
+       /**
+        * @covers WP_REST_Templates_Controller::get_items
+        */
+       public function test_get_items_no_permission() {
+               wp_set_current_user( 0 );
+               $request  = new WP_REST_Request( 'GET', '/wp/v2/templates' );
+               $response = rest_get_server()->dispatch( $request );
+               $this->assertErrorResponse( 'rest_cannot_manage_templates', $response, 401 );
+       }
+
+       /**
+        * @covers WP_REST_Templates_Controller::get_item
+        */
+       public function test_get_item() {
+               wp_set_current_user( self::$admin_id );
+               $request  = new WP_REST_Request( 'GET', '/wp/v2/templates/default//my_template' );
+               $response = rest_get_server()->dispatch( $request );
+               $data     = $response->get_data();
+               unset( $data['content'] );
+               unset( $data['_links'] );
+
+               $this->assertSame(
+                       array(
+                               'id'             => 'default//my_template',
+                               'theme'          => 'default',
+                               'slug'           => 'my_template',
+                               'source'         => 'custom',
+                               'type'           => 'wp_template',
+                               'description'    => 'Description of my template.',
+                               'title'          => array(
+                                       'raw'      => 'My Template',
+                                       'rendered' => 'My Template',
+                               ),
+                               'status'         => 'publish',
+                               'wp_id'          => self::$post->ID,
+                               'has_theme_file' => false,
+                       ),
+                       $data
+               );
+       }
+
+       /**
+        * @ticket 54422
+        * @covers WP_REST_Templates_Controller::create_item
+        */
+       public function test_create_item() {
+               wp_set_current_user( self::$admin_id );
+               $request = new WP_REST_Request( 'POST', '/wp/v2/templates' );
+               $request->set_body_params(
+                       array(
+                               'slug'        => 'my_custom_template',
+                               'description' => 'Just a description',
+                               'title'       => 'My Template',
+                               'content'     => 'Content',
+                       )
+               );
+               $response = rest_get_server()->dispatch( $request );
+               $data     = $response->get_data();
+               unset( $data['_links'] );
+               unset( $data['wp_id'] );
+
+               $this->assertSame(
+                       array(
+                               'id'             => 'default//my_custom_template',
+                               'theme'          => 'default',
+                               'content'        => array(
+                                       'raw' => 'Content',
+                               ),
+                               'slug'           => 'my_custom_template',
+                               'source'         => 'custom',
+                               'type'           => 'wp_template',
+                               'description'    => 'Just a description',
+                               'title'          => array(
+                                       'raw'      => 'My Template',
+                                       'rendered' => 'My Template',
+                               ),
+                               'status'         => 'publish',
+                               'has_theme_file' => false,
+                       ),
+                       $data
+               );
+       }
+
+       /**
+        * @ticket 54422
+        * @covers WP_REST_Templates_Controller::create_item
+        */
+       public function test_create_item_raw() {
+               wp_set_current_user( self::$admin_id );
+               $request = new WP_REST_Request( 'POST', '/wp/v2/templates' );
+               $request->set_body_params(
+                       array(
+                               'slug'        => 'my_custom_template_raw',
+                               'description' => 'Just a description',
+                               'title'       => array(
+                                       'raw' => 'My Template',
+                               ),
+                               'content'     => array(
+                                       'raw' => 'Content',
+                               ),
+                       )
+               );
+               $response = rest_get_server()->dispatch( $request );
+               $data     = $response->get_data();
+               unset( $data['_links'] );
+               unset( $data['wp_id'] );
+
+               $this->assertSame(
+                       array(
+                               'id'             => 'default//my_custom_template_raw',
+                               'theme'          => 'default',
+                               'content'        => array(
+                                       'raw' => 'Content',
+                               ),
+                               'slug'           => 'my_custom_template_raw',
+                               'source'         => 'custom',
+                               'type'           => 'wp_template',
+                               'description'    => 'Just a description',
+                               'title'          => array(
+                                       'raw'      => 'My Template',
+                                       'rendered' => 'My Template',
+                               ),
+                               'status'         => 'publish',
+                               'has_theme_file' => false,
+                       ),
+                       $data
+               );
+       }
+
+       /**
+        * @covers WP_REST_Templates_Controller::update_item
+        */
+       public function test_update_item() {
+               wp_set_current_user( self::$admin_id );
+               $request = new WP_REST_Request( 'PUT', '/wp/v2/templates/default//my_template' );
+               $request->set_body_params(
+                       array(
+                               'title' => 'My new Index Title',
+                       )
+               );
+               $response = rest_get_server()->dispatch( $request );
+               $data     = $response->get_data();
+               $this->assertSame( 'My new Index Title', $data['title']['raw'] );
+               $this->assertSame( 'custom', $data['source'] );
+       }
+
+       /**
+        * @covers WP_REST_Templates_Controller::update_item
+        */
+       public function test_update_item_raw() {
+               wp_set_current_user( self::$admin_id );
+               $request = new WP_REST_Request( 'PUT', '/wp/v2/templates/default//my_template' );
+               $request->set_body_params(
+                       array(
+                               'title' => array( 'raw' => 'My new raw Index Title' ),
+                       )
+               );
+               $response = rest_get_server()->dispatch( $request );
+               $data     = $response->get_data();
+               $this->assertSame( 'My new raw Index Title', $data['title']['raw'] );
+               $this->assertSame( 'custom', $data['source'] );
+       }
+
+       /**
+        * @covers WP_REST_Templates_Controller::delete_item
+        */
+       public function test_delete_item() {
+               // Set up template post.
+               $args    = array(
+                       'post_type'    => 'wp_template',
+                       'post_name'    => 'my_test_template',
+                       'post_title'   => 'My Template',
+                       'post_content' => 'Content',
+                       'post_excerpt' => 'Description of my template.',
+                       'tax_input'    => array(
+                               'wp_theme' => array(
+                                       get_stylesheet(),
+                               ),
+                       ),
+               );
+               $post_id = self::factory()->post->create( $args );
+               wp_set_post_terms( $post_id, get_stylesheet(), 'wp_theme' );
+
+               wp_set_current_user( self::$admin_id );
+               $request = new WP_REST_Request( 'DELETE', '/wp/v2/templates/default//my_test_template' );
+               $request->set_param( 'force', 'false' );
+               $response = rest_get_server()->dispatch( $request );
+               $data     = $response->get_data();
+               $this->assertSame( 'My Template', $data['title']['raw'] );
+               $this->assertSame( 'trash', $data['status'] );
+       }
+
+       /**
+        * @covers WP_REST_Templates_Controller::delete_item
+        */
+       public function test_delete_item_skip_trash() {
+               // Set up template post.
+               $args    = array(
+                       'post_type'    => 'wp_template',
+                       'post_name'    => 'my_test_template',
+                       'post_title'   => 'My Template',
+                       'post_content' => 'Content',
+                       'post_excerpt' => 'Description of my template.',
+                       'tax_input'    => array(
+                               'wp_theme' => array(
+                                       get_stylesheet(),
+                               ),
+                       ),
+               );
+               $post_id = self::factory()->post->create( $args );
+               wp_set_post_terms( $post_id, get_stylesheet(), 'wp_theme' );
+
+               wp_set_current_user( self::$admin_id );
+               $request = new WP_REST_Request( 'DELETE', '/wp/v2/templates/default//my_test_template' );
+               $request->set_param( 'force', 'true' );
+               $response = rest_get_server()->dispatch( $request );
+               $this->assertSame( 200, $response->get_status() );
+               $data = $response->get_data();
+               $this->assertTrue( $data['deleted'] );
+               $this->assertNotEmpty( $data['previous'] );
+       }
+
+       /**
+        * @covers WP_REST_Templates_Controller::delete_item
+        */
+       public function test_delete_item_fail() {
+               wp_set_current_user( self::$admin_id );
+               $request  = new WP_REST_Request( 'DELETE', '/wp/v2/templates/justrandom//template' );
+               $response = rest_get_server()->dispatch( $request );
+               $this->assertErrorResponse( 'rest_template_not_found', $response, 404 );
+       }
+
+       public function test_prepare_item() {
+               // TODO: Implement test_prepare_item() method.
+       }
+
+       public function test_prepare_item_limit_fields() {
+               wp_set_current_user( self::$admin_id );
+
+               $endpoint = new WP_REST_Templates_Controller( 'wp_template' );
+               $request  = new WP_REST_Request( 'GET', '/wp/v2/templates/default//my_template' );
+               $request->set_param( 'context', 'edit' );
+               $request->set_param( '_fields', 'id,slug' );
+               $obj      = get_block_template( 'default//my_template', 'wp_template' );
+               $response = $endpoint->prepare_item_for_response( $obj, $request );
+               $this->assertSame(
+                       array(
+                               'id',
+                               'slug',
+                       ),
+                       array_keys( $response->get_data() )
+               );
+       }
+
+       /**
+        * @ticket 54422
+        * @covers WP_REST_Templates_Controller::get_item_schema
+        */
+       public function test_get_item_schema() {
+               $request    = new WP_REST_Request( 'OPTIONS', '/wp/v2/templates' );
+               $response   = rest_get_server()->dispatch( $request );
+               $data       = $response->get_data();
+               $properties = $data['schema']['properties'];
+               $this->assertCount( 11, $properties );
+               $this->assertArrayHasKey( 'id', $properties );
+               $this->assertArrayHasKey( 'description', $properties );
+               $this->assertArrayHasKey( 'slug', $properties );
+               $this->assertArrayHasKey( 'theme', $properties );
+               $this->assertArrayHasKey( 'type', $properties );
+               $this->assertArrayHasKey( 'source', $properties );
+               $this->assertArrayHasKey( 'content', $properties );
+               $this->assertArrayHasKey( 'title', $properties );
+               $this->assertArrayHasKey( 'description', $properties );
+               $this->assertArrayHasKey( 'status', $properties );
+               $this->assertArrayHasKey( 'wp_id', $properties );
+               $this->assertArrayHasKey( 'has_theme_file', $properties );
+       }
+
+       protected function find_and_normalize_template_by_id( $templates, $id ) {
+               foreach ( $templates as $template ) {
+                       if ( $template['id'] === $id ) {
+                               unset( $template['content'] );
+                               unset( $template['_links'] );
+                               return $template;
+                       }
+               }
+
+               return null;
+       }
+
+}
</ins></span></pre></div>
<a id="trunktestsqunitfixtureswpapigeneratedjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/qunit/fixtures/wp-api-generated.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/qunit/fixtures/wp-api-generated.js    2021-11-16 17:16:07 UTC (rev 52185)
+++ trunk/tests/qunit/fixtures/wp-api-generated.js      2021-11-16 18:04:49 UTC (rev 52186)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5000,6 +5000,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                 "embed",
</span><span class="cx" style="display: block; padding: 0 10px">                                 "edit"
</span><span class="cx" style="display: block; padding: 0 10px">                             ],
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                            "default": "view",
</ins><span class="cx" style="display: block; padding: 0 10px">                             "required": false
</span><span class="cx" style="display: block; padding: 0 10px">                         },
</span><span class="cx" style="display: block; padding: 0 10px">                         "wp_id": {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5036,6 +5037,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                             "type": "string",
</span><span class="cx" style="display: block; padding: 0 10px">                             "required": false
</span><span class="cx" style="display: block; padding: 0 10px">                         },
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        "type": {
+                            "description": "Type of template.",
+                            "type": "string",
+                            "required": false
+                        },
</ins><span class="cx" style="display: block; padding: 0 10px">                         "content": {
</span><span class="cx" style="display: block; padding: 0 10px">                             "default": "",
</span><span class="cx" style="display: block; padding: 0 10px">                             "description": "Content of template.",
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5043,6 +5049,24 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                 "object",
</span><span class="cx" style="display: block; padding: 0 10px">                                 "string"
</span><span class="cx" style="display: block; padding: 0 10px">                             ],
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                            "properties": {
+                                "raw": {
+                                    "description": "Content for the template, as it exists in the database.",
+                                    "type": "string",
+                                    "context": [
+                                        "view",
+                                        "edit"
+                                    ]
+                                },
+                                "block_version": {
+                                    "description": "Version of the content block format used by the template.",
+                                    "type": "integer",
+                                    "context": [
+                                        "edit"
+                                    ],
+                                    "readonly": true
+                                }
+                            },
</ins><span class="cx" style="display: block; padding: 0 10px">                             "required": false
</span><span class="cx" style="display: block; padding: 0 10px">                         },
</span><span class="cx" style="display: block; padding: 0 10px">                         "title": {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5052,6 +5076,27 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                 "object",
</span><span class="cx" style="display: block; padding: 0 10px">                                 "string"
</span><span class="cx" style="display: block; padding: 0 10px">                             ],
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                            "properties": {
+                                "raw": {
+                                    "description": "Title for the template, as it exists in the database.",
+                                    "type": "string",
+                                    "context": [
+                                        "view",
+                                        "edit",
+                                        "embed"
+                                    ]
+                                },
+                                "rendered": {
+                                    "description": "HTML title for the template, transformed for display.",
+                                    "type": "string",
+                                    "context": [
+                                        "view",
+                                        "edit",
+                                        "embed"
+                                    ],
+                                    "readonly": true
+                                }
+                            },
</ins><span class="cx" style="display: block; padding: 0 10px">                             "required": false
</span><span class="cx" style="display: block; padding: 0 10px">                         },
</span><span class="cx" style="display: block; padding: 0 10px">                         "description": {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5064,6 +5109,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                             "default": "publish",
</span><span class="cx" style="display: block; padding: 0 10px">                             "description": "Status of template.",
</span><span class="cx" style="display: block; padding: 0 10px">                             "type": "string",
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                            "enum": [
+                                "publish",
+                                "future",
+                                "draft",
+                                "pending",
+                                "private"
+                            ],
</ins><span class="cx" style="display: block; padding: 0 10px">                             "required": false
</span><span class="cx" style="display: block; padding: 0 10px">                         }
</span><span class="cx" style="display: block; padding: 0 10px">                     }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5096,6 +5148,17 @@
</span><span class="cx" style="display: block; padding: 0 10px">                             "description": "The id of a template",
</span><span class="cx" style="display: block; padding: 0 10px">                             "type": "string",
</span><span class="cx" style="display: block; padding: 0 10px">                             "required": false
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        },
+                        "context": {
+                            "description": "Scope under which the request is made; determines fields present in response.",
+                            "type": "string",
+                            "enum": [
+                                "view",
+                                "embed",
+                                "edit"
+                            ],
+                            "default": "view",
+                            "required": false
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><span class="cx" style="display: block; padding: 0 10px">                     }
</span><span class="cx" style="display: block; padding: 0 10px">                 },
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5106,6 +5169,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                         "PATCH"
</span><span class="cx" style="display: block; padding: 0 10px">                     ],
</span><span class="cx" style="display: block; padding: 0 10px">                     "args": {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        "id": {
+                            "description": "The id of a template",
+                            "type": "string",
+                            "required": false
+                        },
</ins><span class="cx" style="display: block; padding: 0 10px">                         "slug": {
</span><span class="cx" style="display: block; padding: 0 10px">                             "description": "Unique slug identifying the template.",
</span><span class="cx" style="display: block; padding: 0 10px">                             "type": "string",
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5118,6 +5186,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                             "type": "string",
</span><span class="cx" style="display: block; padding: 0 10px">                             "required": false
</span><span class="cx" style="display: block; padding: 0 10px">                         },
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        "type": {
+                            "description": "Type of template.",
+                            "type": "string",
+                            "required": false
+                        },
</ins><span class="cx" style="display: block; padding: 0 10px">                         "content": {
</span><span class="cx" style="display: block; padding: 0 10px">                             "description": "Content of template.",
</span><span class="cx" style="display: block; padding: 0 10px">                             "type": [
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5124,6 +5197,24 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                 "object",
</span><span class="cx" style="display: block; padding: 0 10px">                                 "string"
</span><span class="cx" style="display: block; padding: 0 10px">                             ],
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                            "properties": {
+                                "raw": {
+                                    "description": "Content for the template, as it exists in the database.",
+                                    "type": "string",
+                                    "context": [
+                                        "view",
+                                        "edit"
+                                    ]
+                                },
+                                "block_version": {
+                                    "description": "Version of the content block format used by the template.",
+                                    "type": "integer",
+                                    "context": [
+                                        "edit"
+                                    ],
+                                    "readonly": true
+                                }
+                            },
</ins><span class="cx" style="display: block; padding: 0 10px">                             "required": false
</span><span class="cx" style="display: block; padding: 0 10px">                         },
</span><span class="cx" style="display: block; padding: 0 10px">                         "title": {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5132,6 +5223,27 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                 "object",
</span><span class="cx" style="display: block; padding: 0 10px">                                 "string"
</span><span class="cx" style="display: block; padding: 0 10px">                             ],
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                            "properties": {
+                                "raw": {
+                                    "description": "Title for the template, as it exists in the database.",
+                                    "type": "string",
+                                    "context": [
+                                        "view",
+                                        "edit",
+                                        "embed"
+                                    ]
+                                },
+                                "rendered": {
+                                    "description": "HTML title for the template, transformed for display.",
+                                    "type": "string",
+                                    "context": [
+                                        "view",
+                                        "edit",
+                                        "embed"
+                                    ],
+                                    "readonly": true
+                                }
+                            },
</ins><span class="cx" style="display: block; padding: 0 10px">                             "required": false
</span><span class="cx" style="display: block; padding: 0 10px">                         },
</span><span class="cx" style="display: block; padding: 0 10px">                         "description": {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5142,6 +5254,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                         "status": {
</span><span class="cx" style="display: block; padding: 0 10px">                             "description": "Status of template.",
</span><span class="cx" style="display: block; padding: 0 10px">                             "type": "string",
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                            "enum": [
+                                "publish",
+                                "future",
+                                "draft",
+                                "pending",
+                                "private"
+                            ],
</ins><span class="cx" style="display: block; padding: 0 10px">                             "required": false
</span><span class="cx" style="display: block; padding: 0 10px">                         }
</span><span class="cx" style="display: block; padding: 0 10px">                     }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5151,6 +5270,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                         "DELETE"
</span><span class="cx" style="display: block; padding: 0 10px">                     ],
</span><span class="cx" style="display: block; padding: 0 10px">                     "args": {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        "id": {
+                            "description": "The id of a template",
+                            "type": "string",
+                            "required": false
+                        },
</ins><span class="cx" style="display: block; padding: 0 10px">                         "force": {
</span><span class="cx" style="display: block; padding: 0 10px">                             "type": "boolean",
</span><span class="cx" style="display: block; padding: 0 10px">                             "default": false,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5371,6 +5495,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                             "type": "string",
</span><span class="cx" style="display: block; padding: 0 10px">                             "required": false
</span><span class="cx" style="display: block; padding: 0 10px">                         },
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        "type": {
+                            "description": "Type of template.",
+                            "type": "string",
+                            "required": false
+                        },
</ins><span class="cx" style="display: block; padding: 0 10px">                         "content": {
</span><span class="cx" style="display: block; padding: 0 10px">                             "description": "Content of template.",
</span><span class="cx" style="display: block; padding: 0 10px">                             "type": [
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5377,6 +5506,24 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                 "object",
</span><span class="cx" style="display: block; padding: 0 10px">                                 "string"
</span><span class="cx" style="display: block; padding: 0 10px">                             ],
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                            "properties": {
+                                "raw": {
+                                    "description": "Content for the template, as it exists in the database.",
+                                    "type": "string",
+                                    "context": [
+                                        "view",
+                                        "edit"
+                                    ]
+                                },
+                                "block_version": {
+                                    "description": "Version of the content block format used by the template.",
+                                    "type": "integer",
+                                    "context": [
+                                        "edit"
+                                    ],
+                                    "readonly": true
+                                }
+                            },
</ins><span class="cx" style="display: block; padding: 0 10px">                             "required": false
</span><span class="cx" style="display: block; padding: 0 10px">                         },
</span><span class="cx" style="display: block; padding: 0 10px">                         "title": {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5385,6 +5532,27 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                 "object",
</span><span class="cx" style="display: block; padding: 0 10px">                                 "string"
</span><span class="cx" style="display: block; padding: 0 10px">                             ],
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                            "properties": {
+                                "raw": {
+                                    "description": "Title for the template, as it exists in the database.",
+                                    "type": "string",
+                                    "context": [
+                                        "view",
+                                        "edit",
+                                        "embed"
+                                    ]
+                                },
+                                "rendered": {
+                                    "description": "HTML title for the template, transformed for display.",
+                                    "type": "string",
+                                    "context": [
+                                        "view",
+                                        "edit",
+                                        "embed"
+                                    ],
+                                    "readonly": true
+                                }
+                            },
</ins><span class="cx" style="display: block; padding: 0 10px">                             "required": false
</span><span class="cx" style="display: block; padding: 0 10px">                         },
</span><span class="cx" style="display: block; padding: 0 10px">                         "description": {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5395,6 +5563,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                         "status": {
</span><span class="cx" style="display: block; padding: 0 10px">                             "description": "Status of template.",
</span><span class="cx" style="display: block; padding: 0 10px">                             "type": "string",
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                            "enum": [
+                                "publish",
+                                "future",
+                                "draft",
+                                "pending",
+                                "private"
+                            ],
</ins><span class="cx" style="display: block; padding: 0 10px">                             "required": false
</span><span class="cx" style="display: block; padding: 0 10px">                         }
</span><span class="cx" style="display: block; padding: 0 10px">                     }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5457,6 +5632,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                 "embed",
</span><span class="cx" style="display: block; padding: 0 10px">                                 "edit"
</span><span class="cx" style="display: block; padding: 0 10px">                             ],
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                            "default": "view",
</ins><span class="cx" style="display: block; padding: 0 10px">                             "required": false
</span><span class="cx" style="display: block; padding: 0 10px">                         },
</span><span class="cx" style="display: block; padding: 0 10px">                         "wp_id": {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5493,6 +5669,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                             "type": "string",
</span><span class="cx" style="display: block; padding: 0 10px">                             "required": false
</span><span class="cx" style="display: block; padding: 0 10px">                         },
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        "type": {
+                            "description": "Type of template.",
+                            "type": "string",
+                            "required": false
+                        },
</ins><span class="cx" style="display: block; padding: 0 10px">                         "content": {
</span><span class="cx" style="display: block; padding: 0 10px">                             "default": "",
</span><span class="cx" style="display: block; padding: 0 10px">                             "description": "Content of template.",
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5500,6 +5681,24 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                 "object",
</span><span class="cx" style="display: block; padding: 0 10px">                                 "string"
</span><span class="cx" style="display: block; padding: 0 10px">                             ],
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                            "properties": {
+                                "raw": {
+                                    "description": "Content for the template, as it exists in the database.",
+                                    "type": "string",
+                                    "context": [
+                                        "view",
+                                        "edit"
+                                    ]
+                                },
+                                "block_version": {
+                                    "description": "Version of the content block format used by the template.",
+                                    "type": "integer",
+                                    "context": [
+                                        "edit"
+                                    ],
+                                    "readonly": true
+                                }
+                            },
</ins><span class="cx" style="display: block; padding: 0 10px">                             "required": false
</span><span class="cx" style="display: block; padding: 0 10px">                         },
</span><span class="cx" style="display: block; padding: 0 10px">                         "title": {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5509,6 +5708,27 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                 "object",
</span><span class="cx" style="display: block; padding: 0 10px">                                 "string"
</span><span class="cx" style="display: block; padding: 0 10px">                             ],
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                            "properties": {
+                                "raw": {
+                                    "description": "Title for the template, as it exists in the database.",
+                                    "type": "string",
+                                    "context": [
+                                        "view",
+                                        "edit",
+                                        "embed"
+                                    ]
+                                },
+                                "rendered": {
+                                    "description": "HTML title for the template, transformed for display.",
+                                    "type": "string",
+                                    "context": [
+                                        "view",
+                                        "edit",
+                                        "embed"
+                                    ],
+                                    "readonly": true
+                                }
+                            },
</ins><span class="cx" style="display: block; padding: 0 10px">                             "required": false
</span><span class="cx" style="display: block; padding: 0 10px">                         },
</span><span class="cx" style="display: block; padding: 0 10px">                         "description": {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5521,6 +5741,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                             "default": "publish",
</span><span class="cx" style="display: block; padding: 0 10px">                             "description": "Status of template.",
</span><span class="cx" style="display: block; padding: 0 10px">                             "type": "string",
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                            "enum": [
+                                "publish",
+                                "future",
+                                "draft",
+                                "pending",
+                                "private"
+                            ],
</ins><span class="cx" style="display: block; padding: 0 10px">                             "required": false
</span><span class="cx" style="display: block; padding: 0 10px">                         },
</span><span class="cx" style="display: block; padding: 0 10px">                         "area": {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5558,6 +5785,17 @@
</span><span class="cx" style="display: block; padding: 0 10px">                             "description": "The id of a template",
</span><span class="cx" style="display: block; padding: 0 10px">                             "type": "string",
</span><span class="cx" style="display: block; padding: 0 10px">                             "required": false
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        },
+                        "context": {
+                            "description": "Scope under which the request is made; determines fields present in response.",
+                            "type": "string",
+                            "enum": [
+                                "view",
+                                "embed",
+                                "edit"
+                            ],
+                            "default": "view",
+                            "required": false
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><span class="cx" style="display: block; padding: 0 10px">                     }
</span><span class="cx" style="display: block; padding: 0 10px">                 },
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5568,6 +5806,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                         "PATCH"
</span><span class="cx" style="display: block; padding: 0 10px">                     ],
</span><span class="cx" style="display: block; padding: 0 10px">                     "args": {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        "id": {
+                            "description": "The id of a template",
+                            "type": "string",
+                            "required": false
+                        },
</ins><span class="cx" style="display: block; padding: 0 10px">                         "slug": {
</span><span class="cx" style="display: block; padding: 0 10px">                             "description": "Unique slug identifying the template.",
</span><span class="cx" style="display: block; padding: 0 10px">                             "type": "string",
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5580,6 +5823,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                             "type": "string",
</span><span class="cx" style="display: block; padding: 0 10px">                             "required": false
</span><span class="cx" style="display: block; padding: 0 10px">                         },
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        "type": {
+                            "description": "Type of template.",
+                            "type": "string",
+                            "required": false
+                        },
</ins><span class="cx" style="display: block; padding: 0 10px">                         "content": {
</span><span class="cx" style="display: block; padding: 0 10px">                             "description": "Content of template.",
</span><span class="cx" style="display: block; padding: 0 10px">                             "type": [
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5586,6 +5834,24 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                 "object",
</span><span class="cx" style="display: block; padding: 0 10px">                                 "string"
</span><span class="cx" style="display: block; padding: 0 10px">                             ],
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                            "properties": {
+                                "raw": {
+                                    "description": "Content for the template, as it exists in the database.",
+                                    "type": "string",
+                                    "context": [
+                                        "view",
+                                        "edit"
+                                    ]
+                                },
+                                "block_version": {
+                                    "description": "Version of the content block format used by the template.",
+                                    "type": "integer",
+                                    "context": [
+                                        "edit"
+                                    ],
+                                    "readonly": true
+                                }
+                            },
</ins><span class="cx" style="display: block; padding: 0 10px">                             "required": false
</span><span class="cx" style="display: block; padding: 0 10px">                         },
</span><span class="cx" style="display: block; padding: 0 10px">                         "title": {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5594,6 +5860,27 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                 "object",
</span><span class="cx" style="display: block; padding: 0 10px">                                 "string"
</span><span class="cx" style="display: block; padding: 0 10px">                             ],
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                            "properties": {
+                                "raw": {
+                                    "description": "Title for the template, as it exists in the database.",
+                                    "type": "string",
+                                    "context": [
+                                        "view",
+                                        "edit",
+                                        "embed"
+                                    ]
+                                },
+                                "rendered": {
+                                    "description": "HTML title for the template, transformed for display.",
+                                    "type": "string",
+                                    "context": [
+                                        "view",
+                                        "edit",
+                                        "embed"
+                                    ],
+                                    "readonly": true
+                                }
+                            },
</ins><span class="cx" style="display: block; padding: 0 10px">                             "required": false
</span><span class="cx" style="display: block; padding: 0 10px">                         },
</span><span class="cx" style="display: block; padding: 0 10px">                         "description": {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5604,6 +5891,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                         "status": {
</span><span class="cx" style="display: block; padding: 0 10px">                             "description": "Status of template.",
</span><span class="cx" style="display: block; padding: 0 10px">                             "type": "string",
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                            "enum": [
+                                "publish",
+                                "future",
+                                "draft",
+                                "pending",
+                                "private"
+                            ],
</ins><span class="cx" style="display: block; padding: 0 10px">                             "required": false
</span><span class="cx" style="display: block; padding: 0 10px">                         },
</span><span class="cx" style="display: block; padding: 0 10px">                         "area": {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5618,6 +5912,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                         "DELETE"
</span><span class="cx" style="display: block; padding: 0 10px">                     ],
</span><span class="cx" style="display: block; padding: 0 10px">                     "args": {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        "id": {
+                            "description": "The id of a template",
+                            "type": "string",
+                            "required": false
+                        },
</ins><span class="cx" style="display: block; padding: 0 10px">                         "force": {
</span><span class="cx" style="display: block; padding: 0 10px">                             "type": "boolean",
</span><span class="cx" style="display: block; padding: 0 10px">                             "default": false,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5838,6 +6137,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                             "type": "string",
</span><span class="cx" style="display: block; padding: 0 10px">                             "required": false
</span><span class="cx" style="display: block; padding: 0 10px">                         },
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        "type": {
+                            "description": "Type of template.",
+                            "type": "string",
+                            "required": false
+                        },
</ins><span class="cx" style="display: block; padding: 0 10px">                         "content": {
</span><span class="cx" style="display: block; padding: 0 10px">                             "description": "Content of template.",
</span><span class="cx" style="display: block; padding: 0 10px">                             "type": [
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5844,6 +6148,24 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                 "object",
</span><span class="cx" style="display: block; padding: 0 10px">                                 "string"
</span><span class="cx" style="display: block; padding: 0 10px">                             ],
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                            "properties": {
+                                "raw": {
+                                    "description": "Content for the template, as it exists in the database.",
+                                    "type": "string",
+                                    "context": [
+                                        "view",
+                                        "edit"
+                                    ]
+                                },
+                                "block_version": {
+                                    "description": "Version of the content block format used by the template.",
+                                    "type": "integer",
+                                    "context": [
+                                        "edit"
+                                    ],
+                                    "readonly": true
+                                }
+                            },
</ins><span class="cx" style="display: block; padding: 0 10px">                             "required": false
</span><span class="cx" style="display: block; padding: 0 10px">                         },
</span><span class="cx" style="display: block; padding: 0 10px">                         "title": {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5852,6 +6174,27 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                 "object",
</span><span class="cx" style="display: block; padding: 0 10px">                                 "string"
</span><span class="cx" style="display: block; padding: 0 10px">                             ],
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                            "properties": {
+                                "raw": {
+                                    "description": "Title for the template, as it exists in the database.",
+                                    "type": "string",
+                                    "context": [
+                                        "view",
+                                        "edit",
+                                        "embed"
+                                    ]
+                                },
+                                "rendered": {
+                                    "description": "HTML title for the template, transformed for display.",
+                                    "type": "string",
+                                    "context": [
+                                        "view",
+                                        "edit",
+                                        "embed"
+                                    ],
+                                    "readonly": true
+                                }
+                            },
</ins><span class="cx" style="display: block; padding: 0 10px">                             "required": false
</span><span class="cx" style="display: block; padding: 0 10px">                         },
</span><span class="cx" style="display: block; padding: 0 10px">                         "description": {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5862,6 +6205,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                         "status": {
</span><span class="cx" style="display: block; padding: 0 10px">                             "description": "Status of template.",
</span><span class="cx" style="display: block; padding: 0 10px">                             "type": "string",
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                            "enum": [
+                                "publish",
+                                "future",
+                                "draft",
+                                "pending",
+                                "private"
+                            ],
</ins><span class="cx" style="display: block; padding: 0 10px">                             "required": false
</span><span class="cx" style="display: block; padding: 0 10px">                         },
</span><span class="cx" style="display: block; padding: 0 10px">                         "area": {
</span></span></pre>
</div>
</div>

</body>
</html>