Changeset 58452
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php
r56586 r58452 245 245 if ( rest_is_field_included( 'rest_namespace', $fields ) ) { 246 246 $data['rest_namespace'] = $namespace; 247 } 248 249 if ( rest_is_field_included( 'template', $fields ) ) { 250 $data['template'] = $post_type->template ?? array(); 251 } 252 253 if ( rest_is_field_included( 'template_lock', $fields ) ) { 254 $data['template_lock'] = ! empty( $post_type->template_lock ) ? $post_type->template_lock : false; 247 255 } 248 256 … … 408 416 'readonly' => true, 409 417 ), 418 'template' => array( 419 'type' => array( 'array' ), 420 'description' => __( 'The block template associated with the post type.' ), 421 'readonly' => true, 422 'context' => array( 'view', 'edit', 'embed' ), 423 ), 424 'template_lock' => array( 425 'type' => array( 'string', 'boolean' ), 426 'enum' => array( 'all', 'insert', 'contentOnly', false ), 427 'description' => __( 'The template_lock associated with the post type, or false if none.' ), 428 'readonly' => true, 429 'context' => array( 'view', 'edit', 'embed' ), 430 ), 410 431 ), 411 432 ); -
trunk/tests/phpunit/tests/rest-api/rest-post-types-controller.php
r56746 r58452 78 78 } 79 79 80 /** 81 * @ticket 61477 82 */ 83 public function test_get_item_template_cpt() { 84 register_post_type( 85 'cpt_template', 86 array( 87 'show_in_rest' => true, 88 'rest_base' => 'cpt_template', 89 'rest_namespace' => 'wordpress/v1', 90 'template' => array( 91 array( 'core/paragraph', array( 'placeholder' => 'Content' ) ), 92 ), 93 'template_lock' => 'all', 94 ) 95 ); 96 $request = new WP_REST_Request( 'GET', '/wp/v2/types/cpt_template' ); 97 $response = rest_get_server()->dispatch( $request ); 98 $this->check_post_type_object_response( 'view', $response, 'cpt_template' ); 99 } 100 80 101 public function test_get_item_page() { 81 102 $request = new WP_REST_Request( 'GET', '/wp/v2/types/page' ); … … 166 187 $properties = $data['schema']['properties']; 167 188 168 $this->assertCount( 1 4, $properties, 'Schema should have 14properties' );189 $this->assertCount( 16, $properties, 'Schema should have 16 properties' ); 169 190 $this->assertArrayHasKey( 'capabilities', $properties, '`capabilities` should be included in the schema' ); 170 191 $this->assertArrayHasKey( 'description', $properties, '`description` should be included in the schema' ); … … 181 202 $this->assertArrayHasKey( 'visibility', $properties, '`visibility` should be included in the schema' ); 182 203 $this->assertArrayHasKey( 'icon', $properties, '`icon` should be included in the schema' ); 204 $this->assertArrayHasKey( 'template', $properties, '`template` should be included in the schema' ); 205 $this->assertArrayHasKey( 'template_lock', $properties, '`template_lock` should be included in the schema' ); 183 206 } 184 207 … … 231 254 $this->assertSame( $post_type_obj->rest_namespace, $data['rest_namespace'] ); 232 255 $this->assertSame( $post_type_obj->has_archive, $data['has_archive'] ); 256 $this->assertSame( $post_type_obj->template ?? array(), $data['template'] ); 257 $this->assertSame( ! empty( $post_type_obj->template_lock ) ? $post_type_obj->template_lock : false, $data['template_lock'] ); 233 258 234 259 $links = test_rest_expand_compact_links( $links ); -
trunk/tests/qunit/fixtures/wp-api-generated.js
r58340 r58452 13015 13015 "rest_base": "posts", 13016 13016 "rest_namespace": "wp/v2", 13017 "template": [], 13018 "template_lock": false, 13017 13019 "_links": { 13018 13020 "collection": [ … … 13045 13047 "rest_base": "pages", 13046 13048 "rest_namespace": "wp/v2", 13049 "template": [], 13050 "template_lock": false, 13047 13051 "_links": { 13048 13052 "collection": [ … … 13075 13079 "rest_base": "media", 13076 13080 "rest_namespace": "wp/v2", 13081 "template": [], 13082 "template_lock": false, 13077 13083 "_links": { 13078 13084 "collection": [ … … 13107 13113 "rest_base": "menu-items", 13108 13114 "rest_namespace": "wp/v2", 13115 "template": [], 13116 "template_lock": false, 13109 13117 "_links": { 13110 13118 "collection": [ … … 13139 13147 "rest_base": "blocks", 13140 13148 "rest_namespace": "wp/v2", 13149 "template": [], 13150 "template_lock": false, 13141 13151 "_links": { 13142 13152 "collection": [ … … 13169 13179 "rest_base": "templates", 13170 13180 "rest_namespace": "wp/v2", 13181 "template": [], 13182 "template_lock": false, 13171 13183 "_links": { 13172 13184 "collection": [ … … 13199 13211 "rest_base": "template-parts", 13200 13212 "rest_namespace": "wp/v2", 13213 "template": [], 13214 "template_lock": false, 13201 13215 "_links": { 13202 13216 "collection": [ … … 13229 13243 "rest_base": "global-styles", 13230 13244 "rest_namespace": "wp/v2", 13245 "template": [], 13246 "template_lock": false, 13231 13247 "_links": { 13232 13248 "collection": [ … … 13259 13275 "rest_base": "navigation", 13260 13276 "rest_namespace": "wp/v2", 13277 "template": [], 13278 "template_lock": false, 13261 13279 "_links": { 13262 13280 "collection": [ … … 13289 13307 "rest_base": "font-families", 13290 13308 "rest_namespace": "wp/v2", 13309 "template": [], 13310 "template_lock": false, 13291 13311 "_links": { 13292 13312 "collection": [ … … 13319 13339 "rest_base": "font-families/(?P<font_family_id>[\\d]+)/font-faces", 13320 13340 "rest_namespace": "wp/v2", 13341 "template": [], 13342 "template_lock": false, 13321 13343 "_links": { 13322 13344 "collection": [ … … 13353 13375 ], 13354 13376 "rest_base": "posts", 13355 "rest_namespace": "wp/v2" 13377 "rest_namespace": "wp/v2", 13378 "template": [], 13379 "template_lock": false 13356 13380 }; 13357 13381
Note: See TracChangeset
for help on using the changeset viewer.