Introduce generic entity template with standard preprocess and theme suggestions

Created on 29 September 2016, about 8 years ago
Updated 14 October 2023, about 1 year ago

Problem/Motivation

Right now, EntityViewBuilder always uses $entity_type_id as #theme. #2698909: EntityViewBuilder uses non-existing #theme hooks corrects that a bit and doesn't use it when no such template exists.

However, to view an entity, you still need to implement hook_theme(), define a template, provide a default template and if you want to do it like node, implement quite some preprocess logic, theme suggestions and so on.

Proposed resolution

This proposes to introduce a standard template, with the common preprocess stuff and theme suggestions.

Instead of node.html.twig, you would then use entity--node.html.twig and so on.

That removes all the unecessary glue code that is currently necessary to have useful entity templates.

Previous attempts at standardizing this failed ( #2023571: Support preprocessing in EntityViewBuilder , #2270883: Automatically add theme hook suggestions for all entity types ), this basically replaces those issues. Those issues were complicated because it affects existing templates, so there is a risk of changes and BC breaks.

Remaining tasks

User interface changes

None

API changes

A new template.

Data model changes

Feature request
Status

Needs work

Version

11.0 🔥

Component
Entity 

Last updated about 17 hours ago

Created by

🇨🇭Switzerland berdir Switzerland

Live updates comments and jobs are added and updated live.
  • Needs reroll

    The patch will have to be re-rolled with new suggestions/changes described in the comments in the issue.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024