Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 292371

Field rendering should respect configurable field display

$
0
0

Problem

As discussed in #2353867: [META] Expose Title and other base fields in Manage Display, sitebuilders cannot configure the display of node's title even though they often want to.

Worse, even if developers use a hook to modify the node's title field adding ->setDisplayConfigurable('view', TRUE), and a sitebuilder then enables the title field in a view mode, it makes no difference. The template_preprocess_node and the node.html.twig take over the rendering of the node's title, ignoring the configured view displays.

The same problem applies to node 'created', node 'uid', taxonomy term 'name' and aggregator feed 'title' fields.

This issue has been split from #2353867: [META] Expose Title and other base fields in Manage Display to contain minimal, back-compatible changes to core in order to allow setDisplayConfigurable to be usable in contrib. The changes here are also a necessary prerequisite to solving the original issue in core.

A related problem is that the node title field template is used both when the node title is used for the page title in the page title block, and when the field is made configurable and displayed as part of an entity display.

Solution

1) Modify the logic of template_preprocess_* and templates so that they only usurp rendering if the field's display is not configurable.

2) Add an '#inline_field' variable to field templates so that the can distinguish whether they are called in a context where they should return block markup or inline markup. Use this for node title, uid and created fields.

3) Add an 'inline-field.html.twig' helper template to help themers developing field templates, and remove the duplicate core templates for node title, uid and created.

Results

If a developer makes these fields configurable, then a sitebuilder can configure them and the configuration will take effect.

The exception is when the entity is viewed on it's "own page" (in particular at its canonical route as the main display or potentially other cases such as the preview page). In that situation, there are a variety of problems related to EntityViewController's buildTitle method which are covered in #2941208: Title formatting broken due to flawed EntityViewController->buildTitle.

In general these changes are fully back-compatible provided that a developer has not previously used setDisplayConfigurable to enable configurable display of the relevant fields. This is discussed further in the change record.

Review/test Status

  • Sub-system maintainer review by @lauriii in #97
  • Expert review by @Berdir in #83
  • Various community reviewers and testers (also see recent comments on #2353867)

Viewing all articles
Browse latest Browse all 292371

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>