Loading
Issue #3628774: Let themes and modules provide content type templates
Closes #3628774. Builds on #3628772 (!288 (merged)).
Themes and modules can provide content type templates, which the content type form offers as its template source.
Declaring templates
In *.gutenberg.yml, each template points to a JSON file in the format of the Template field:
templates:
article-hero:
label: 'Article with a hero'
description: 'A cover with the title and an introduction, then the article.'
file: gutenberg/templates/article-hero.json
template_lock: none # Optional, the lock the form suggests.- Where they come from: the default theme and its base themes, and modules.
- Not tied to content types: a template isn't tied to a content type machine name, so any template can be used for any content type.
- Invalid templates: a template is logged and left out when its definition, its file or its JSON is invalid, or when the file is outside the theme or module.
Content type form
- Template source select: "Custom" (the content type's own JSON, as before) or a provided template, grouped by theme and module. It only shows when there are provided templates.
- Referenced, not copied: changes to the theme's template reach the content type. The JSON editor shows the template read-only with its description. Customize copies it into the custom template.
- Template lock: selecting a template pre-fills the lock it suggests. A provided template can be locked without a custom template.
- Unavailable template: when the template isn't available anymore, e.g. with another default theme or after uninstalling the module, new content starts with the custom template, and the form says so.
Gutenberg Base
Ships two templates, "Article with a hero" and "Landing page". Both start with a cover that holds the entity title, which the site header overlays.
Notes for review
- Data model: a new setting,
<bundle>_template_source,''for custom. It's in the dynamic schema and cleared when Gutenberg is disabled. - New
TemplateManagermethods:getProvidedTemplates();getTemplate()resolves the source first. - Existing issue, not changed here: the cached theme definitions of
GutenbergLibraryManageraren't cleared when the default theme changes without installing a theme. That affects provided templates like the rest of*.gutenberg.yml.
Tests
- PHPUnit,
ContentTypeEditTest::testTemplateSource(): invalid templates are left out, a provided template is saved with its lock, the node form template, the fallback after uninstalling, and clearing. - Playwright,
provided-templates.spec.mjs: the base theme templates (read-only view, saving, new content, Customize, no invalid blocks) and a test module template (its lock, invalid templates left out, uninstalling).