Until now, a Canvas content template (ContentTemplate config entity) could only be created for content types (node bundles). A content template can now be created for every content entity type that meets all of these requirements:
- It opted into Field UI (
field_ui_base_route). - It is stored (non-NULL storage).
- It does not have a Canvas component tree of its own (that is: not a
ComponentTreeEntityInterface; this excludes Canvas'Page).
In Drupal core these are content, taxonomy terms, users, media and content blocks. Contact messages are not eligible, and comments are excluded. Entity types of contributed modules qualify the same way, for example commerce_product and paragraph.
The requirements and the reason for each are documented in docs/config-management.md, section 3.5.
For site builders
The "Add new template" dialog in the Templates panel has a new "Entity type" dropdown. The Templates panel groups templates by entity type and bundle.
A content template targets a view mode that exists as configuration. The "Default" display is not a view mode, so it cannot have a template. An entity's own page is rendered in the "Full content" view mode: if an entity type does not have that view mode, create it first (this is the case for example for commerce_product).
For module developers
Modules providing content entity types
- A content entity type of a contributed or custom module becomes eligible when it meets the requirements above. No opt-in in Canvas is needed.
- Canvas replaces the view builder of every eligible entity type with
\Drupal\canvas\EntityHandlers\ContentTemplateAwareViewBuilder. Without an enabled content template for an entity's bundle and view mode, the original view builder renders the entity. \Drupal\canvas\ContentTemplateRepository::isSupportedEntityType()returns whether an entity type is eligible.- When a content template renders an entity, the component instances in the template decide how it looks. What the entity type's own view builder adds for presentation is not applied to that entity. For example, a paragraph type's behavior plugins have no effect on a paragraph that is rendered via a Canvas content template.
- If the page of your entity type should be able to get a content template, ship a
fullview mode (core.entity_view_mode.[entity type].full).
Modules that alter Canvas' UI
drupalSettings.canvas.contentTemplateEntityTypeslists the eligible entity types for the Canvas UI.- In the HTTP API,
suggestedPreviewEntityIdof a content template can now be a string, for entity types with string IDs. It stays an integer for entity types with integer IDs.
Sites that use Canvas Paragraphs
Canvas Paragraphs made content templates possible for paragraphs and taxonomy terms. Canvas now does that itself, and is not compatible with that module: uninstall it when you update.