When Drupal displays a field, the template is field.html.twig, which generates block-level markup including optional labels, attributes, and supports multiple values.
For the node title
, uid
and created
fields Drupal supplies an overridden template (e.g. field--node--title.html.twig) that generates simplified inline markup without label or title_attributes.
If the site owner has hooked the node title to setDisplayConfigurable()
, then the inline display is incorrect. The label is missing, markup is inline, and the markup might not match normal CSS selectors for fields (for example if the CSS selector specifically matches on div). For the node created field, also the metadata rel="schema:author"
is missing.
Solution
Add a '#inline_field' variable to the field templates so that they can distinguish whether they are called in a context where they should return block markup or inline markup.
The detailed rules for inline markup are as follows:
- The page title is always inline.
- The node title, uid and created fields are inline except if
setDisplayConfigurable()
has been called. - To preserve back-compatibility, rule 2) only applies if an additional entity type property has been set - reusing the mechanism from #2923701: Mechanism to disable preprocessing of node base fields so they can be configured via the field UI.
Workaround
/**
* Implements hook_theme_registry_alter().
*/
function XXX_theme_registry_alter(&$theme_registry) {
// Disable the 'inline' versions of node base field templates to workaround
// https://www.drupal.org/node/2993647.
unset($theme_registry['field__node__title']);
unset($theme_registry['field__node__uid']);
unset($theme_registry['field__node__created']);
}