Skip to content

saveEntityRecord() returns 404 when trying to save a template given its id and content #71765

@Aljullu

Description

@Aljullu

Description

Using saveEntityRecord() to save a template stopped working in a recent update of Gutenberg.

I believe the issue was introduced in #67125 (cc @ellatrix), specifically where the wp_template rest_base is modified:

// How does this work?
// 1. For wp_template, we remove the custom templates controller, so it becomes
// a normal posts endpoint, modified slightly to allow auto-drafts.
add_filter( 'register_post_type_args', 'gutenberg_modify_wp_template_post_type_args', 10, 2 );
function gutenberg_modify_wp_template_post_type_args( $args, $post_type ) {
if ( 'wp_template' === $post_type ) {
$args['rest_base'] = 'wp_template';
$args['rest_controller_class'] = 'Gutenberg_REST_Templates_Controller';
$args['autosave_rest_controller_class'] = null;
$args['revisions_rest_controller_class'] = null;
}
return $args;
}

Step-by-step reproduction instructions

  1. Switch your theme to TT4.
  2. Add this code snippet somewhere in your site/plugin:
const { saveEntityRecord } = dispatch( coreStore );
saveEntityRecord(
	'postType',
	'wp_template',
	{
		id: 'twentytwentyfour//home',
		content: 'test',
	},
	{
		throwOnError: true,
	}
);
  1. With Gutenberg disabled, notice a query to /wp-json/wp/v2/templates/twentytwentyfour//home is done, and it works. With Gutenberg enabled, the query is done to /wp-json/wp/v2/wp_template/twentytwentyfour//home and it returns this error: No route was found matching the URL and request method..

Screenshots, screen recording, code snippet

No response

Environment info

  • Gutenberg nightly or trunk.
  • WP 6.8.2.

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Metadata

Metadata

Assignees

Labels

[Feature] Templates APIRelated to API powering block template functionality in the Site Editor[Status] In ProgressTracking issues with work in progress[Type] BugAn existing feature does not function as intended[Type] RegressionRelated to a regression in the latest release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions