Update Edit control for template field#75518
Conversation
|
Size Change: -446 B (-0.01%) Total Size: 3.03 MB
ℹ️ View Unchanged
|
5dc4e6e to
75f46ec
Compare
I've implemented this at 75f46ec Note this works like the editor inspector: if the page is set as the "posts page" template, users cannot change the template. Any other case (including the page that is set as homepage) can change the template. For reference, in trunk, QuickEdit added an extra restriction to prevent the pages set as homepage to change its template. Not sure why that is, but wanted to brought it up.
|
| // TODO: this template id is computed differently than the templateId in the editor inspector | ||
| // Compare with | ||
| // https://github.com/WordPress/gutenberg/blob/8c2a7c775f5b5fb19d8dca66a09d18977cf42b7d/packages/editor/src/components/post-template/panel.js#L21 | ||
| // The editor inspector computes it from the editor store (that we cannot use in this package), | ||
| // that ends up being using the getTemplateId private selector from core data. | ||
| const templateId = await resolveSelect( | ||
| coreDataStore | ||
| ).getDefaultTemplateId( { | ||
| slug: slugToCheck, | ||
| } ); |
There was a problem hiding this comment.
This has ported the existing logic from template-edit and in doing so it raised a bug: the templateId computed here is different from the one computed in the editor inspector (which ends up using the private selector getTemplateId). As a result, the template for the posts page is "Pages" and not "Blog post".
|
In discussing this PR with @ntsekouras he raised some questions about introducing the item param to getElements. We also considered related problems (e.g., fields whose elements depend on other field's values – such as a country/region relationship) where we'd benefit from having access to the data as well. Given the tight timeline, I've prepared #75565 that does not modify any API, and enables us to fix the issue with the template field (which is blocking QuickEdit from becoming stable). |


Alternative to #75421
Follow-up to #75290
What?
This PR updates the template edit component to rely on the field elements. In doing so, it also updates the rendered value of the template in DataViews.
Why?
The template field was rendered as a regular field with a custom button, but that interaction and the visuals are at odds with the new trigger mechanism for the panel introduced at #75290. That's the primary aspect this PR is trying to solve.
Additionally, as a bonus, by leveraging the field elements, this PR displays the template name in the DataViews layout.
How?
itemas a new parameter togetElements, so fields can calculate elements based on the data.Testing Instructions
Visit the Site Editor's Pages screen, and interact with the template field. Verify that it's always displaying the proper value of the template (e.g., go to the pages editor and compare with the value there).
TODO
2. Make the template not editable if the page is set as the "blog page", like in the editor inspector.Fix #75518 (comment)There was some logic to making the page not editable if it was the homepage as well, but the editor inspector allows users to change it — so there's no reason for QuickEdit not to. wp-admin allows editing the template for both.
Edit the template of the posts page:
Screen.Recording.2026-02-13.at.14.13.03.mov
Edit the template of the homepage:
Screen.Recording.2026-02-13.at.14.12.39.mov
Edit the templates for the posts page & homepage via wp-admin:
Screen.Recording.2026-02-13.at.14.12.11.mov