Problem/Motivation

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 the 'created' and 'uid' fields.

This issue has been split from #2353867: [META] Expose Title and other base fields in Manage Display to contain minimal, back-compatible changes providing an important first step to solving the original problem.

Proposed resolution

Use an additional entity type property to allow disabling of extra preprocessing of node base fields (title, created and uid).

Remaining tasks

None.

This issue has been thoroughly reviewed including:

  • 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)

User interface changes

None

API changes

Node title, uid and created fields are subject to special preprocessing that obstructs developers who wish to enable these fields to be configurable via the field UI. A module can now disable this preprocessing by means of an additional entity type property:

function XXX_entity_type_build(array &$entity_types) {
  $entity_types['node']->set('enable_base_field_custom_preprocess_skipping', TRUE);
}

Using this feature requires an update to the node template to treat related variables as optional (label, author_name, date). Theme developers should update their themes to match the changes made in core. No changes are required for sites that do not use this feature.

Background explanation for API changes

We considered solving this issue without an additional entity type property. Earlier patches disabled the special preprocessing conditional on whether ->setDisplayConfigurable() had been called. The problem is that there are likely to be existing sites that call ->setDisplayConfigurable(), and workaround the existing bugs in a way that relies on the special preprocessing. By creating an additional entity type property, we guarantee not to break existing sites.

A second motivation for the additional entity type property is a wider goal for D9 and beyond to remove special cases as much as possible. We are aiming to have direct support in core for base fields configurable via the field UI. However it would still be possible for sites to override that if they preferred a hard-coded layout. So in D9 we want to remove the special preprocessing of base fields, yet retain the ability for sites to call ->setDisplayConfigurable(). Therefore the earlier patch that tied "special preprocessing" directly to "configurable via the field UI" was actually creating a problem for the future. The new approach allows D9 to remove the additional entity type property and corresponding special preprocessing yet retain ->setDisplayConfigurable().

Data model changes

None

Release notes snippet

It is now easier to make node base fields configurable via the field UI due to a mechanism to disable preprocessing of node base fields. This a step towards making title display configurable in Drupal Core and in the meantime there is a contrib module to enable it. These changes are fully back-compatible.

CommentFileSizeAuthor
#315 title.display-D8.6-2923701-305.patch27.46 KBadamps
#2 2923701-2.patch0 bytesjonathanshaw
#3 2923701-3.patch7.03 KBjonathanshaw
#7 2923701-4.patch3.44 KBjonathanshaw
#17 title.display-2923701-17.patch13.64 KBadamps
#17 interdiff-2923701-4-17.txt13.53 KBadamps
#19 title.display-2923701-19.patch13.69 KBadamps
#19 interdiff-2923701-17-19.txt1.93 KBadamps
#21 title.display-2923701-21.patch13.7 KBadamps
#21 interdiff-2923701-19-21.txt983 bytesadamps
#24 title.display-2923701-24.patch14.14 KBadamps
#24 interdiff-2923701-21-24.txt9.53 KBadamps
#34 title.display-2923701-33.patch18.3 KBadamps
#34 interdiff-2923701-24-33.txt4.64 KBadamps
#36 title.display-2923701-36.patch21.71 KBadamps
#36 interdiff-2923701-33-36.txt2.89 KBadamps
#38 title.display-2923701-38.patch25.53 KBadamps
#38 interdiff-2923701-36-38.txt3.71 KBadamps
#39 title.display-2923701-39.patch25.63 KBadamps
#39 interdiff-2923701-38-39.txt1.69 KBadamps
#47 title.display-2923701-47.patch25.56 KBadamps
#52 title.display-2923701-52.patch25.72 KBadamps
#52 interdiff-2923701-47-52.txt794 bytesadamps
#53 title.display-2923701-53.patch26.27 KBadamps
#53 interdiff-2923701-47-53.txt626 bytesadamps
#56 title.display-2923701-56.patch26.6 KBadamps
#56 interdiff-2923701-47-56.txt3.44 KBadamps
#60 title.display-2923701-60.patch26.14 KBadamps
#60 interdiff-2923701-56-60.txt2.66 KBadamps
#62 title.display-2923701-62.patch26.14 KBadamps
#67 title.display-2923701-67.patch21.31 KBadamps
#67 interdiff-2923701-62-67.txt13.47 KBadamps
#70 title.display-2923701-70.patch21.09 KBadamps
#70 interdiff-2923701-67-70.txt4.28 KBadamps
#75 title.display-2923701-75.patch21.52 KBadamps
#75 interdiff-2923701-70-75.txt1.09 KBadamps
#76 title.display-2923701-76.patch19.81 KBadamps
#76 interdiff-2923701-75-76.txt1.52 KBadamps
#77 title.display-2923701-77.patch20.07 KBadamps
#77 interdiff-2923701-75-77.txt2.3 KBadamps
#88 title.display-2923701-88.patch20.07 KBadamps
#88 interdiff-2923701-77-88.txt580 bytesadamps
#94 title.display-2923701-94.patch20.07 KBadamps
#94 interdiff-2923701-88-94.txt1.73 KBadamps
#99 title.display-2923701-99.patch28.31 KBadamps
#99 title.display-2923701-interdiff-94-99.txt15.89 KBadamps
#103 title.display-2923701-103.patch24.69 KBadamps
#103 title.display-2923701-interdiff-99-103.txt3.67 KBadamps
#129 title.display-2923701-129.patch28.47 KBadamps
#131 title.display-2923701-131.patch41.45 KBadamps
#131 title.display-2923701-interdiff-129-131.txt14.29 KBadamps
#133 title.display-2923701-133.patch45.6 KBadamps
#133 title.display-2923701-interdiff-131-133.txt6.87 KBadamps
#133 submitted.png2.79 KBadamps
#138 title.display-2923701-138.patch46.05 KBadamps
#138 title.display-2923701-interdiff-133-138.txt9.2 KBadamps
#140 title.display-2923701-140.patch46.05 KBadamps
#140 title.display-2923701-interdiff-138-140.txt971 bytesadamps
#141 title.display-2923701-141.patch48.27 KBadamps
#141 title.display-2923701-interdiff-140-141.txt2.24 KBadamps
#143 title.display-2923701-143.patch49.35 KBadamps
#143 title.display-2923701-interdiff-141-143.txt4.72 KBadamps
#147 title.display-2923701-147.patch46.52 KBadamps
#147 title.display-2923701-interdiff-143-147.txt5.08 KBadamps
#155 title.display-2923701-155.patch47.01 KBadamps
#155 title.display-2923701-interdiff-147-155.txt3.28 KBadamps
#156 title.display-2923701-156.patch48.85 KBadamps
#156 title.display-2923701-interdiff-155-156.txt5.86 KBadamps
#161 title.display-2923701-161.patch49.98 KBadamps
#161 title.display-2923701-interdiff-156-161.txt7.1 KBadamps
#174 title.display-2923701-174.patch49.97 KBadamps
#174 title.display-2923701-interdiff-161-174.txt496 bytesadamps
#181 2923701-181.patch49.99 KBjofitz
#191 title.display-2923701-191.patch51.32 KBadamps
#191 title.display-2923701-interdiff-181-191.txt2.1 KBadamps
#195 title.display-2923701-195.patch48.87 KBadamps
#195 title.display-2923701-interdiff-191-195.txt1.96 KBadamps
#197 title.display-2923701-197.patch30.66 KBadamps
#197 title.display-2923701-interdiff-195-197.txt16.7 KBadamps
#199 title.display-2923701-199.patch28.54 KBadamps
#200 title.display-2923701-200.patch46.32 KBadamps
#200 title.display-2923701-interdiff-199-200.txt17.17 KBadamps
#205 title.display-2923701-205.patch25.9 KBadamps
#205 title.display-2923701-interdiff-199-205.txt3.91 KBadamps
#212 title.display-2923701-212.patch27.23 KBadamps
#212 title.display-2923701-interdiff-205-212.txt5.91 KBadamps
#213 title.display-2923701-213.patch30.38 KBadamps
#213 title.display-2923701-interdiff-212-213.txt9.99 KBadamps
#215 title.display-2923701-215.patch30.38 KBadamps
#215 title.display-2923701-interdiff-213-215.txt328 bytesadamps
#222 title.display-2923701-222.patch25.8 KBadamps
#222 title.display-2923701-interdiff-212-222.txt3.68 KBadamps
#229 title.display-2923701-229.patch26.01 KBadamps
#229 title.display-2923701-interdiff-222-229.txt1.77 KBadamps
#234 title.display-2923701-234.patch25.94 KBadamps
#234 title.display-2923701-interdiff-229-234.txt1.37 KBadamps
#236 title.display-2923701-236.patch25.94 KBadamps
#236 title.display-2923701-interdiff-234-236.txt1.66 KBadamps
#256 title.display-2923701-256.patch26.8 KBadamps
#256 title.display-2923701-interdiff-236-256.txt2.78 KBadamps
#258 title.display-2923701-258.patch27.21 KBadamps
#258 title.display-2923701-interdiff-256-258.txt3.39 KBadamps
#260 2923701-250.patch27.19 KBjofitz
#260 interdiff-2923701-258-260.txt1.45 KBjofitz
#261 title.display-2923701-261.patch27.19 KBadamps
#261 title.display-2923701-interdiff-260-261.txt895 bytesadamps
#272 261-272-interdiff.txt8.46 KBalexpott
#272 2923701-272.patch27.46 KBalexpott
#276 title.display-2923701-276.patch27.14 KBadamps
#276 title.display-2923701-interdiff-272-276.txt462 bytesadamps
#285 title.display-2923701-285.patch27.47 KBadamps
#285 title.display-2923701-interdiff-276-285.txt5.89 KBadamps
#286 title.display-2923701-286.patch27.47 KBadamps
#286 title.display-2923701-interdiff-285-286.txt885 bytesadamps
#300 title.display-2923701-300.patch27.58 KBpancho
#300 2923701_286-300_interdiff.txt4.42 KBpancho
#301 title.display-2923701-301.patch27.7 KBpancho
#301 2923701_300-301_interdiff.txt1.66 KBpancho
#313 title.display-D8.6-2923701-305.patch28.16 KBadamps
#305 title.display-2923701-305.patch27.91 KBadamps
#305 title.display-2923701-interdiff-301-305.txt2.8 KBadamps

Comments

jonathanshaw created an issue. See original summary.

jonathanshaw’s picture

Issue summary: View changes
Status: Active » Needs review
Issue tags: +Needs tests
StatusFileSize
new0 bytes
jonathanshaw’s picture

StatusFileSize
new7.03 KB

Sorry, previous patch malformed.

jonathanshaw’s picture

jonathanshaw’s picture

StatusFileSize
new3.44 KB

Aargh, first time using Windows powershell.

adamps’s picture

@jonathanshaw great, that looks like the right way to do it. First I have some comments on the code in your patch.

1) In the template I think it would be clearer to name the new variable 'display_title'. This matches the existing 'display_submitted', and template writers and hook writers can see what the variable is for.

2) Templates don't need to test if the variable is defined as it will always be defined.

3) In this code

+  // If the title's display is not configurable, take control of rendering it.
+  $variables['label'] = isset($variables['elements']['title']) ? $variables['elements']['title'] : $variables['node']->getTitle();
+  $variables['title_configurable'] = TRUE;
+  if (!$variables['node']->title->getFieldDefinition()->isDisplayConfigurable('view')) {
+    $variables['title_configurable'] = FALSE;
+    unset($variables['elements']['title']);
+  }

I propose to tidy up the =TRUE and =FALSE and tweak the comment.

+  // If the title's display is configurable, then render it as part of the content array.  If not, render it separately.
+  $variables['label'] = isset($variables['elements']['title']) ? $variables['elements']['title'] : $variables['node']->getTitle();
+  $variables['display_title'] = !$variables['node']->title->getFieldDefinition()->isDisplayConfigurable('view');
+  if ($variables['display_title']) {
+    unset($variables['elements']['title']);
+  }

4) Indent looks wrong

-    {% if not page %}
+      {% if not page and (title_configurable is not defined or not title_configurable) %}

5) I think it's better not to fix the alignment of unrelated lines as it makes the patch harder to read

-  $variables['date'] = \Drupal::service('renderer')->render($variables['elements']['created']);
+  $variables['date'] = \Drupal::service('renderer')
+    ->render($variables['elements']['created']);
   unset($variables['elements']['created']);
-  $variables['author_name'] = \Drupal::service('renderer')->render($variables['elements']['uid']);
+  $variables['author_name'] = \Drupal::service('renderer')
+    ->render($variables['elements']['uid']);
adamps’s picture

Secondly I would like to comment on what more code we might need to add.

  1. There is another copy of the template in the classy theme.
  2. I think we should fix the problem of label display for the title field. In all 3 copies of field--node--title.html.twig must obey label_hidden same as in field.html.twig (but still don't need the bit for multiple), so something like the code below.
  3. The exact same logic exists for taxonomy - it might make sense to fix that too.
{% if label_hidden %}
  {% for item in items %}
    <div{{ attributes }}>{{ item.content }}</div>
  {% endfor %}
{% else %}
  <div{{ attributes }}>
    <div{{ title_attributes }}>{{ label }}</div>
    {% for item in items %}
      <div{{ item.attributes }}>{{ item.content }}</div>
    {% endfor %}
  </div>
{% endif %}
adamps’s picture

Or except for classy I wonder if could we just delete field--node--title.html.twig? It's not clear to me how it gives different output from the base template.

adamps’s picture

Also template_preprocess_node does

  $variables['date'] = \Drupal::service('renderer')->render($variables['elements']['created']);
  unset($variables['elements']['created']);
  $variables['author_name'] = \Drupal::service('renderer')->render($variables['elements']['uid']);
  unset($variables['elements']['uid']);

I guess we could consider fixing those in the same way??

adamps’s picture

Sorry in #9 and #10 I've not got it right for the label - there are subtle differences between the ordinary field and the title field, so it will need a bit of juggling.

adamps’s picture

Unfortunately another complication.

In \Drupal\Core\Entity\Controller\EntityViewController::buildTitle

$page['#title'] = $this->renderer->render($page[$label_field]);

So our customer display output ends up in $page['#title'] which means it goes into the title block, which tags, labels and everything. I guess you normally would hide the title block when overriding the title display for the full display mode, which would avoid the problem.

As an alternative you might hide the title display for the full display mode and keep the block. This mostly works, but it has missed out on the purpose of EntityViewController::buildTitle:

This allows attributes set on the field to propagate correctly (e.g. RDFa, in-place editing)

Well I've got to dash now, but it's another thing to think about.

jonathanshaw’s picture

#9/#10 - labels: hoping you can figure this out

#11 - other variables unset: let's push that to a follow-up and check all entities not just node.

#13 - the block.

So our customer display output ends up in $page['#title'] which means it goes into the title block, which tags, labels and everything.

Does this matter? What negative effect?

adamps’s picture

#11 I feel enthusiastic to do it myself
#13 I think I have a solution.

@jonathanshaw Why don't you make all the changes that you can then I'll add my bit after.

jonathanshaw’s picture

I might not be able to for a few days, do move ahead if you can

adamps’s picture

Title: Have node rendering respect configurable title field display » Node/taxonomy rendering should respect configurable field display
Status: Needs work » Needs review
StatusFileSize
new13.64 KB
new13.53 KB

Here's a new patch

After careful consideration, I have decided to have a clean split: if isDisplayConfigurable then don't do any special processing at all. In this case, the derived variables such as 'label' will be blank. Three reasons:

  1. It should reduce the instances of sites with double title display because the title is now only supplied in one variable, never duplicated in a second one.
  2. To reach the goal of this issue, the code in template_preprocess_node should 100% respect the configuration, and not alter anything. For example, calling render would set the #printed flag and prevent display.
  3. I'm not really convinced about using a default of $variables['node']->getTitle() - normally this variable is set to the a render array which can have a span and attributes.

Changes from #7:

  • Add other node fields: 'created' and 'uid'
  • Add taxonomy term 'name'
  • Add Templates missing from last patch
  • Add page title interaction (see #13). I really like the way this works out - the Formatter can now have full control of whether to let the title block render, or cause the title block to be hidden. Tested with "Quick edit" in various scenarios.
  • Done my comments from #8

Not yet included: field--node--title.html.twig. I don't know the template system well. This template displays a string in a span which is only suitable if !isDisplayConfigurable. Ideally I'd like to make some magic call to discount this template suggestion when the display is configurable and fallback to the default field template. Status: at the moment, enabling label for a title field only works with a customised template.

adamps’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new13.69 KB
new1.93 KB

Corrected version

adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new13.7 KB
new983 bytes

Fix again

jonathanshaw’s picture

  1. +++ b/core/modules/node/templates/node.html.twig
    @@ -15,7 +15,7 @@
    + * - label: The title of the node (blank if data should not be shown).
    

    This comment seems wrong. I'm not sure what 'blank' is as a technical term. Elsewhere in core it seems to use "(optional)" for for optional twig arguments. How about
    + * - label: (optional) The title of the node, if its display is not configurable.

  2. +++ b/core/modules/node/templates/node.html.twig
    @@ -75,14 +75,14 @@
    +  {% if not page and label %}
    

    This confuses me. Could it be {% if label and not page %}?

  3. +++ b/core/lib/Drupal/Core/Entity/Controller/EntityViewController.php
    @@ -70,7 +70,25 @@ public function buildTitle(array $page) {
    +          // The title formatter has provided markup for use in the page title
    
    +++ b/core/modules/node/node.module
    @@ -605,16 +605,28 @@ function template_preprocess_node(&$variables) {
    +  if (!$node->title->getFieldDefinition()->isDisplayConfigurable('view')) {
    

    Could we move this hunk to be in the same block as the new comment about date, author_name and title?

  4. +++ b/core/lib/Drupal/Core/Entity/Controller/EntityViewController.php
    @@ -70,7 +70,25 @@ public function buildTitle(array $page) {
    +          // The title formatter has provided markup for use in the page title
    

    This comment can't be quite right as we don't have a title formatter in core. How about "The formatter for the title field has provided ...". Or could this markup come from a somewhere other than a formatter, like a hook of some kind?

  5. +++ b/core/lib/Drupal/Core/Entity/Controller/EntityViewController.php
    @@ -70,7 +70,25 @@ public function buildTitle(array $page) {
    +            $page[$label_field] = $page[$label_field]['#page_title'] + $page[$label_field];
    

    I don't get the purpose of this. Is it worth a comment?

  6. +++ b/core/lib/Drupal/Core/Entity/Controller/EntityViewController.php
    @@ -70,7 +70,25 @@ public function buildTitle(array $page) {
         elseif ($entity->hasField($label_field)) {
           // The title field exists and has been explicitly hidden.
           $page['#title'] = '';

    I'm concerned about BC here. AFAICS if someone has enabled setDisplayConfigurable for the title field, but has not set #page_title (which they couldn't have known to do as it's new) then this change will hide their page title.

  7. #17.3

    I'm not really convinced about using a default of $variables['node']->getTitle

    Agreed, your isDisplayConfigurable preserves BC and does not require a default. This is because if someone else had already enabled isDisplayConfigurable, they must have already have added ['label'] in their own preprocess or removed the need for it from their template - we don't have to worry about that.

  8. .

adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new14.14 KB
new9.53 KB

Thanks, good feedback, all done, except:

1) I propose that we go with
* - label: (optional) The title of the node.

  • I think "if its display is not configurable" is a bit of a comprehension leap for a template designer without any background.
  • Whilst you are right that this patch a) makes label optional, and b) passes a label "if its display is not configurable" I would say that hook code is entitled to alter this behaviour and hide/pass the label for some other reason.

4/5) I hope the comments are clearer now. The phrase "title field formatter" occurs in the existing code just a few lines earlier, meaning simply 'the formatter that is being used for the title field'. I changed my wording to match that.

6) No I think it's OK. The code only hides the title in two cases

  • line 85: #page_title exists and is empty
  • line 96: title field display has been explicitly set to disabled
adamps’s picture

Issue summary: View changes

I have expanded the issue summary to include

  • "Remaining Tasks" - in particular I can't figure out the one broken test
  • "Increase the Scope??" - please comment to let me know your views
jonathanshaw’s picture

#23.6

No I think it's OK. The code only hides the title in two cases
line 85: #page_title exists and is empty
line 96: title field display has been explicitly set to disabled

It's precisely the second case that worries me. Existing sites may already have explicitly disabled the title field, without expecting it to hide the title in the title block. In fact, wouldn't this be quite a normal existing case:
- setDisplayConfigurable to TRUE for title
- explicitly hide title on full view mode
- expect title to still appear in title block on full page view

Maybe I'm not understanding the purpose of this prerender callback properly.

I remain concerned about the scope creep in the introduction of taxonomy fixes in this patch. At the very least I think this needs a change of issue title, a mention in the IS, and a statement that we've searched the codebase to make sure the same issue is not present on any other core content entity. We either need to be node-only, or whole-of-core.

jonathanshaw’s picture

#25 "I can't figure out the one broken test"

I tried it manually with the patch and can confirm it's broken (although didn't try without the patch):
- enable Aggregator
- create a feed like http://rss.cnn.com/rss/cnn_topstories.rss
- place a block of the feed
- run cron
- view the block
- click the "read more" link at bottom of block
- See no title on feed page :(

adamps’s picture

Issue tags: +Needs change record

Existing sites may already have explicitly disabled the title field, without expecting it to hide the title in the title block.

OK I understand now. However:

  • If you hide the title block now then you get warnings in template_preprocess_node and a partially broken title block (missing classes for quickedit etc).
  • From a UX perspective I can see no other sensible model than "disabled" => "hidden entirely, no block".

So I think we need to leave the code as in and cover it in the CR: up until now setDisplayConfigurable was not supported and the existing behavior "disabled" => "hidden from content, but get title block" was just chance and never intended.

At the very least I think this needs a change of issue title, a mention in the IS

I think I had already done both:-)

We either need to be node-only, or whole-of-core.

I agree. I am aiming for the whole-of-core, but there might be edge-cases we ignore for specialist entities with unusual display. I have done some rough searching for other problems and didn't find any. However I didn't come up with a good strategy to find the problems. I would welcome anyone else searching, and am in favour of fixing them.

I tried it manually with the patch and can confirm it's broken

Good thinking, I'll try that way.

adamps’s picture

Issue tags: -Needs change record

Existing sites may already have explicitly disabled the title field, without expecting it to hide the title in the title block.

Apologies you are right I was wrong. I was thinking about nodes, but there are many other entity types, such as, erm, Aggregators:-) I'll fix it tomorrow.

jonathanshaw’s picture

If you hide the title block now then you get warnings in template_preprocess_node and a partially broken title block (missing classes for quickedit etc).

For node, I'm concerned that developers might have ignored / not cared about / not noticed these issues, so could be completely ambushed by the title disappearing altogether.

From a UX perspective I can see no other sensible model than "disabled" => "hidden entirely, no block".

My perspective is completely opposite. For me disabled on an entity view mode means disabled just in that rendered view mode; the title block is a completely different thing from the rendered view mode. In my mind the less they are entangled the better.

For example, I'm currently working on a contrib that allows you to specify a view mode to use in the title block. So that on a page I couldbe controlling the content of the title block using one view mode using the 'title' view mode and the content block using the 'full' view mode. Handy for something like events where the event date is crucial identifying information that should be shown right with the title.

adamps’s picture

Other entity types

I did a search for {{ title_prefix }} that seemed quite useful and we may need to look at:

  • aggregator-feed
  • aggregator-item
  • search-result

Page titles

They are built as a render array into $page['#title'].

  1. HtmlRenderer::renderResponse sets #title to getTitle()
  2. EntityViewController::buildTitle (checked in code) overrides this for FieldableEntityInterface based on label field
  3. I am trying allow the Formatter to set a higher-priority override (to avoid tags and optionally set no markup)
  4. You are trying to allow a module hook to set a higher-priority override based to invoke the formatter with different view mode

So we need a system for code to register callbacks for "entityPageTitle". It could get a bit complicated to manage the interactions - what if modules for both 3) and 4) are installed? You might say that ideally TitleFormatter would run it's special processing but based on the 'title' view mode.

Would it be easiest if we had an online chat do you think?

jonathanshaw’s picture

I searched for instances of template_process_ for entities that used ContentEntityInterface and found none apart from node and term that unset anything, so I think you've succeeded in covering core. Yay!

Re #31/32.4 in my example case I'm planning to replace the default title block not modify it with a hook, so I can take over its logic. It's not something we have to worry about here. I was just questioning the logic of

From a UX perspective I can see no other sensible model than "disabled" => "hidden entirely, no block".

I can now see where you are coming from in terms of SBX - it might seem weird that moving the title to the disabled region doesn't make it disappear from the page. OTOH it's not any weirder than the fact that the title shows at the top of the page regardless of where you position it amidst the other fields.

My thinking is that the only really clean solution (way out of scope, D9 probably) would seem to be to add a title region to the full display mode and put the title in that. For this issue I suggest we keep things as minimal and BC as possible. After all we're not making the title field display configurable here - we're just removing the nastiest obstacles to that in core. If someone wants to set DisplayConfigurable and have the configured title field interact with the block title in some excellent way, they can make their own custom title block for that.

I'm happy to chat, though not sure it's needed. You can message me through d.o

adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new18.3 KB
new4.64 KB

I'll respond properly to that last comment tomorrow, but I agree it sounds like in fact we don't need to chat. In the meantime I have a new patch that should fix the last test.

we're not making the title field display configurable here

I agree, but I'm keen to make the final step for a module to get configurable titles as easy as possible. The latest patch now includes the TitleFormatter class which I feel is generic, slightly tricky and we don't want each module to have to reinvent the wheel. I think that now all it takes to get configurable titles is a single call to setDisplayConfigurable.

adamps’s picture

Issue summary: View changes

In this comment I'll answer the UX for the default scenario - setting aside legacy, module hooks and so on. I have tried quite a few different options and the current UX seems by far the best. To test out this experience either hook setDisplayConfigurable or install Manage Display module.

For the page title, the site-builder can choose from three options:

  1. Hide it completely
  2. Use the block
  3. Hide the block and show with the content

Two UX questions related to each other:

  • How to signal (1) other than "Move title to disabled region"?
  • What does "Move title to disabled region" do if not (1)?

Some technical problems:

  • Once the title is in the disabled region, the markup is no longer generated, so it's not practical to display it correctly (e.g. including attributes for quick edit)
  • There should not be two titles - which is what happens easily if the user can separately hide-unhide the block and hide-unhide the content.
  • Can't assume any correspondence between "Display Mode = Full" and "Show as page". In preview mode a teaser is shown as a page, and the site-admin is free to make up a view of full display modes.

So absolutely feel free to suggest modifications to the UX, but they need to encompass all of the above, and bear in mind that I have tried a lot of different things already:-)

adamps’s picture

StatusFileSize
new21.71 KB
new2.89 KB

I searched for instances of template_process_ for entities that used ContentEntityInterface and found none apart from node and term that unset anything

@jonathanshaw Thanks for that check.

I concluded that aggregator-feed did need handling even though it didn't have an unset, so this latest patch adds that in.

adamps’s picture

Please can someone review the change record [2925634]

adamps’s picture

StatusFileSize
new25.53 KB
new3.71 KB

I nearly forgot the node title templates. Up until now there was bad markup with h2 inside span, and the label would not display.

This patch fixes that, falling back to field.html.twig if the title is a "real field" that has come from "Manage Display".

adamps’s picture

StatusFileSize
new25.63 KB
new1.69 KB

Oops fix some warnings

eelkeblok’s picture

I've been checking out the patch and the manage_display module in the last few days and I must say I very much like where this is going. I was struggling a bit with the behaviour of the submitted block. It seems that it is only available when the "Display author and date information" option is enabled for the node type, but when it is, it does not take into account whether the pseudo field is actually hidden.

Does it make sense to drop the checkbox completely and allow the pseudo field to control whether the submiited data is shown at all? If not, at least I think moving the field to disabled should also hide it.

Edit: Actually, the checkbox seems to now only control whether the pseudo field is shown, not whether the information is printed. WIth the patch and module installed, I can't seem to get rid of the submitted data that is added by the module.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

adamps’s picture

@eelkeblok Thanks for taking a look. The submitted data is awkward because it has information from two fields interleaved, so it didn't really fit the pattern all the other fields follow. Please do raise an issue on the manage_display queue and we can take it forward there.

The manage_display module is still a rough first go at the moment, with my intention being to have something that can be used to test out this patch. Until this patch is accepted, or at least it seems likely that it will be accepted, then the module isn't much use! Hence I don't plan to work on manage_display issues until the patch has been looked at by the core committers.

adamps’s picture

Please can someone set the status to RTBC?

The code is complete as far as I know, has been reviewed by @jonathanshaw, and tested by several people. Of course I am aware that there are no tests yet. However I think we have reached the stage where we should get input from the core committers to check they are willing to accept a patch like this and that there are no major flaws.

rootwork’s picture

Status: Needs review » Reviewed & tested by the community

So excited for this. Thanks for all your hard work here @AdamPS and @jonathanshaw!

adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new25.56 KB

Fix the coding standard problem as per codesniffer patch.

I suspect the test failures might be unrelated to this patch to hopefully they will go away.

jonathanshaw’s picture

The test failures seem to be about the title on media entities, probably a useful indication of a BC oversight in the patch.

adamps’s picture

I still can't see any connection with the patch. I get strange errors when I try to run on my server. If anyone else can figure it out that would be a big help.

I still think it might be just an odd random error, so I will try to re-test it.

adamps’s picture

OK, so I have made some progress.

Firstly there seems to be a bug in 8.6.x. If a test fails, then the code crashes when trying to display the error. This is unrelated to the patch here.

Notice: Undefined index: error in Drupal\simpletest\Form\SimpletestResultsForm::addResultForm() (line 317 of core/modules/simpletest/src/Form/SimpletestResultsForm.php).
Notice: Undefined index: #error in Drupal\simpletest\Form\SimpletestResultsForm::addResultForm() (line 325 of core/modules/simpletest/src/Form/SimpletestResultsForm.php).
Notice: Undefined index: #error in Drupal\simpletest\Form\SimpletestResultsForm::addResultForm() (line 326 of core/modules/simpletest/src/Form/SimpletestResultsForm.php).

Secondly, there is a BC problem with the media entity tests. The media entity currently has a configuration directly in conflict with the strategy of this issue.

  • It has called setDisplayConfigurable(TRUE) for the 'name' field (which is the label).
  • The 'name' field display is set to disabled.
  • But even so it expects the title to be displayed.

That seems wrong to me.

  • Poor UI as the user has a manage display element for the name, but it does nothing.
  • I believe also that this approach will ignore the output from the field formatter that EntityViewController::buildTitle carefully checks for as per the comment at line 66.

Next steps:

  • I will post a patch that has a hack specifically to exclude media entity
  • I will raise an issue against media entity
adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new25.72 KB
new794 bytes

Updated patch with a hack for media. I am aware that it cannot be committed like this. The current goal is to get an initial review from a core committer that the general approach is valid and find any significant problems in the code. Please can someone set RTBC to bring this to the attention of the core committers?

adamps’s picture

StatusFileSize
new26.27 KB
new626 bytes

The media problems were introduced in #2930788: Do not show name by default in media displays.

Here is an updated patch that is a much more plausible actual solution. I have changed the Media Entity to use the new title formatter by default.

adamps’s picture

Status: Needs work » Needs review

OK, I'll hide #53 for now, and ask for review of #52.

adamps’s picture

StatusFileSize
new26.6 KB
new3.44 KB

OK, with a bit more time to consider it I think @jonathanshaw is right about the BC problem he raised particularly in #27. On the other hand, I still think I was right with my answer about how the obvious alternatives didn't really work either. Hopefully my new solution is the best of both worlds.

I have removed the risky else case from EntityViewController and add code in TitleFormatter to compensate. There is a new checkbox to allow the "normal" output to be disabled independently of the block.

  1. Media Entity default setting is to disable normal output, but keep the title block. That's the same as before, but more explicit in the UI, and it works better because it will pass attributes through.
  2. If an entity needs no normal output and no title block, that's also available as an option.

Review comments welcome please. Interdiff is still against #47 which is the last version that anyone removed, and seems the clearest (the intervening patches basically adding stuff then discarding it again).

samvel’s picture

Status: Needs review » Needs work

Hi guys,

$display = $this->t('Display as @tag', ['@tag' => $settings['tag']]);
if ($settings['linked']) {
  $display .= $this->t(', linked to content');
}

It looks strange. May be better use next way:

$text_message = 'Display as @tag';
if ($settings['linked']) {
  $text_message .= ', linked to content';
}
$display = $this->t($text_message, ['@tag' => $settings['tag']]);

samvel’s picture

I mean that it looks strange in translation interface. Better use whole phrases.

eelkeblok’s picture

Issue summary: View changes

Both are not correct. When you tack on a part of a sentence like this, you are making assumptions about word order, which may not be valid in other languages. You need to have two distinct versions of the translatable string, i.e.:

$replacements =  ['@tag' => $settings['tag']];
if ($setting['linked']) {
  $display = $this->t('Display as @tag, linked to content.');
}
else {
  $display = $this->t('Display as @tag.');
}

Although I haven't looked at the code in context, you might also need a period in the string (I've added one, it looks like the sort of string that needs one), which is trivial in this new form, but troublesome in the old.

Edit: I just realised samvel's version has more or less the same effect for the original strings. However, this goes against another translation guideline which says you should not pass variables as translatable strings, because it prevents automatic extraction tools from finding the translatable string.

adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new26.14 KB
new2.66 KB

New patch:

  • Translation fixed, thanks
  • Added conditional fields using #states
  • Remove the changes to media - potentially the defaults there need to stay as they are for BC; it's easy for site-builders to change to use the title formatter if desired.
adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new26.14 KB

New patch fixes coding standards. Surely the ContextualLinksTest failure can't be related to this patch?? I'm finding the tests don't work well in 8.6.x on my server right now.

jonathanshaw’s picture

You've steered this issue so it now tackles two problems:
A. allowing more entity display fields to be fully configurable (so that node titles can be configured like other fields)
B. making the behavior of page titles not too confusing when title fields are configurable (so there aren't duplicate titles in the block and the field)

The problem of the page title is hard. I can't see a truly good solution, it's like an intrinsic weak spot in Drupal's site-building model.

Possible solutions include:

1. Control the page title via settings on the title formatter on the entity display UI
2. Require the existence of a "page title" region on full/default view modes
3. Require the existence of a "page title" display mode
4. Present additional "page title" settings, either at the top of the UI for the full/default view modes, or in the settings at the bottom of all view modes.

You've done a great proof-of-concept job at showing how the first approach would work. This approach has the great virtues of being hard for sitebuilders to misconfigure and not increasing UI complication.

It also has a lot I don't like. It relies on an invisible magic snowflake to link the page title block and the canonical entity display, unrelated things from different region; someone who knew Drupal architecture from first principles would never guess it worked this way, and would it confuse the mental model of learning site builders. Furthermore the snowflake further complicates the overall situation, deepening the kind of tangle that caused this issue in the first place.

I'm not saying I know a better solution. But because of the problems with the proposed solution, and way the solution touches on a complex intersection of entity, theming, usability and backwards compatibility, it's going to be very very hard to get someone to commit it. I think you'll be here for years and years.

I suggest a 2 pronged approach:

- Spin up a new issue dedicated to the first of the two problems (the one I originally opened this issue to address), and tackle in core the bare minimum that is necessary to make custom development easier and to allow contrib to satisfactorily solve the second problem.

- Try to get people from the layout initiative interested in engaging with this question. It's very very close to the kind of concerns they have. #2884601: Add a Layout Builder to core

I'm really glad you're pursuing this question - I think this is a big Drupal WTF. I'm just trying to suggest how to get the best progress based on what I observe of core development.

I'll try tagging this for product manager review on the off-chance that attracts some direction.

adamps’s picture

@jonathanshaw Wow #63 comes as a big surprise. I had the impression that we were more closely aligned in our thinking.

1 Scope

Spin up a new issue dedicated to the first of the two problems

Please - no new issues. I am 100% with you on your original purpose for this issue:

the bare minimum that is necessary to make custom development easier and to allow contrib to satisfactorily solve the second problem.

Hence I claim that "get people from the layout initiative interested" and your points starting "Possible solutions include" are firmly out of scope.

If you feel some parts of the patch don't belong then please give specific review feedback i.e. identifying files and line numbers. If you haven't already looked at the manage_display module then I strongly encourage you to do so. Each of the bits of code in the current patch comes from a specific way in which core blocked writing of the module.

Note that the issue summary lays out the solution in 3 parts.

  1. I'm guessing the template changes are non-contentious.
  2. Some change to EntityViewController is required as (a) otherwise you get h2 inside span in the title block and (b) the title field fails to show on a page because it been written into #title (which occurs even if the title block has been disabled). The current patch is the best I found after quite a lot of research, but I agree isn't especially neat and would be delighted to learn of a better way.
  3. We could remove TitleFormatter (putting it back into contrib) if that is causing a problem.

2 Goals and timescales

You've done a great proof-of-concept job at showing how the first approach would work ... It also has a lot I don't like ... because of the problems with the proposed solution ... I think you'll be here for years and years.

My intention here is to create a working non-contentious fully BC patch that can be committed to D8.6. I think this is feasible given the scope - we are not trying to set out the next generation correct solution to the wider problem, but rather removing some very specific obstacles in an entirely BC way as an interim working position.

Please review it on that basis and give specific feedback (rather than vague and discouraging essays about snowflakes:-)).

3 Wider review

I'll try tagging this for product manager review on the off-chance that attracts some direction.

I believe that once we have RTBC status we can get attention from a core committer. I feel it's best to leave the setting of that sort of tag to the small group of people whom it primarily concerns.

jonathanshaw’s picture

Thanks for laying that rationale out again Adam - it really helped me to get much closer to being on board with you here.

I'm guessing the template changes are non-contentious.

Yes, I think they're awesome.

Some change to EntityViewController is required as (a) otherwise you get h2 inside span in the title block and (b) the title field fails to show on a page because it been written into #title (which occurs even if the title block has been disabled).

This is where I begin to get nervous, but I believe you that it's necessary to do something. I think it would help me and other reviewers if you spelled out in the IS in what circumstances these problems arise, what the code chain is that triggers them, and why your solution is the minimal effective one. Also why these problems must be tackled at the same time as the template problems, not in a separate issue.

We could remove TitleFormatter (putting it back into contrib) if that is causing a problem.

I would definitely recommend punting it to a follow-up issue or contrib. The bigger the issue, the harder to get reviewed and committed.

  1. +++ b/core/lib/Drupal/Core/Entity/Controller/EntityViewController.php
    @@ -70,7 +70,26 @@ public function buildTitle(array $page) {
    +        }
    

    This logic flow is really difficult to understand. Can it be re-engineered to remove the $skip_render? I think it could if the last line was moved to the top. This might also allow the comment to be broken up to explain things more step-by step.

  2. +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TitleFormatter.php
    @@ -0,0 +1,162 @@
    +      '#description' => $this->t('Use this setting instead of disabling the title field entirely as it correctly handles the entity shown as a page.'),
    ...
    +      '#description' => $this->t('Behavior when the entity is shown as a page.'),
    

    I can't immediately understand the purposes of these two settings based on these descriptions.

  3. +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TitleFormatter.php
    @@ -0,0 +1,162 @@
    +    $form['classes'] = [
    +      '#title' => $this->t('Classes'),
    +      '#type' => 'textfield',
    +      '#default_value' => $this->getSetting('classes'),
    +      '#states' => $if_enabled,
    +    ];
    +    return $form;
    

    Core is very minimal in the settings it provides on it's formatters. Both class and tag should probably be removed.

  4. +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TitleFormatter.php
    @@ -0,0 +1,162 @@
    +        $summary[] = $this->t('Display as @tag, linked to content', $replacements);
    

    I suggest checking the entity reference formatter for what summary it uses when linking.

  5. +++ b/core/modules/aggregator/aggregator.theme.inc
    @@ -46,5 +46,10 @@ function template_preprocess_aggregator_feed(&$variables) {
    +  // For the 'title' field, if there are configured display settings then
    +  // handle as a normal field.  If not, then pull the information out into a
    +  // separate variable.
    +  if (!$feed->title->getFieldDefinition()->isDisplayConfigurable('view')) {
    +    $variables['title'] = $feed->label();
    +  }
    

    The comment feels confusing. Presumably the field's machine name is not title? In which case, let's use that.

  6. +++ b/core/modules/node/node.module
    @@ -605,16 +605,33 @@ function template_preprocess_node(&$variables) {
    +  // For the fields 'date', 'author_name' and 'title', if there are configured
    +  // display settings then handle as a normal field.  If not, then pull the
    +  // information out into separate variables.
    +  if (!$node->created->getFieldDefinition()->isDisplayConfigurable('view')) {
    

    Again, better to use field's machine name.

  7. +++ b/core/modules/node/node.module
    @@ -605,16 +605,33 @@ function template_preprocess_node(&$variables) {
    +  // By default, the node title template uses a short form inside a span.
    +  // The output from a generic formatter is likely to contains tags such as
    +  // headings, so make sure to display the title as a normal field
    +  // in that case.
    +  $variables['elements']['title']['#title_as_field'] = $node->title->getFieldDefinition()->isDisplayConfigurable('view');
    

    I think both the comment, and the name #title_as_field, show a problem. They make sense now when we feel like we're wrestling with an existing way of doing things. But they're not optimal for someone in the future who doesn't have that history. It's the page title that's really the special case. Is it possible to present things that way?

    Also referencing the way the template works from inside the preprocess seems wrong. If we're doing a weird dance with the template for BC reasons, let's say that explicitly.

  8. +++ b/core/modules/node/templates/node.html.twig
    @@ -75,14 +75,14 @@
    +  {% if display_submitted and author_name and date %}
    
    +++ b/core/modules/taxonomy/taxonomy.module
    @@ -273,9 +273,14 @@ function template_preprocess_taxonomy_term(&$variables) {
    +  // For the 'name' field, if there are configured display settings then handle
    +  // as a normal field.  If not, then pull the information out into a separate
    +  // variable.
    

    "If the name field is not configurable, make it available separately."

  9. +++ b/core/themes/classy/templates/field/field--node--title.html.twig
    @@ -15,20 +15,26 @@
    + *   If false, display a compact form, typically using inline elements.
    

    Let's not use the word 'form' in this context.

  10. +++ b/core/themes/stable/templates/content/node.html.twig
    @@ -15,7 +15,7 @@
    + * - label: The title of the node (blank if data should not be shown).
    

    Regression/omission: you fixed this before for another template. Should be '(optional)' not '(blank)'?

adamps’s picture

Issue summary: View changes

@jonathanshaw Thanks for detailed comments, good ideas. I have update the IS, hopefully that is clearer now.

1 There are two detailed comments already but nevertheless I have added some more. I cannot see how to avoid $skip_render except by confusing duplication of the line of code with the call to render - NB it is vital not to call render in the $skip_render case. I don't really grasp your objection - there is a simple boolean variable skip_render that has an obvious effect. The variable is needed because of nested ifs.
2-4 I have removed TitleFormatter.php.
5-6 I was already using the field's machine name - it was simply that I had chosen to put the field name in quotes. I am no longer doing that, and I have also applied your wording from 8 here too.
7 I had a go to rework it (in module and templates).
8 Done
9 I had a go to reword (same for two other files).
10 Done, well spotted (fixed in several places in that file).

Especially for 1,7,9 if you don't think I've got it right, please can you be exact about what you would prefer so I don't have to just keep guessing.

why these problems must be tackled at the same time as the template problems, not in a separate issue.

It would be feasible to create a separate issue, but I don't prefer it. It seems simpler and clearer to tackle the entirety of the problem in one go. The one case where I would agree to split the issue is if a core committer agreed to commit some but not all of the patch - I agree something would be better than nothing. However I don't see how we can know that this will occur, and if so exactly which parts to include.

adamps’s picture

StatusFileSize
new21.31 KB
new13.47 KB

New patch uploaded for review. Would be amazing to get this to RTBC.

jonathanshaw’s picture

  1. +++ b/core/lib/Drupal/Core/Entity/Controller/EntityViewController.php
    @@ -70,7 +70,28 @@ public function buildTitle(array $page) {
    -        $page['#title'] = $this->renderer->render($page[$label_field]);
    +        if (isset($page[$label_field]['#page_title'])) {
    +          // The desired markup for use in the page title may be different from
    +          // that to use when displaying the title field as content.
    +          // Allow the title field formatter to provide separate markup for the
    +          // first case using the #page_title array property, which should be
    +          // set to a render array of child elements.
    +          if ($page[$label_field]['#page_title']) {
    +            // Combine the two arrays, giving preference to #page_title, but
    +            // also preserving the #properties from the base field array.
    +            $page[$label_field] = $page[$label_field]['#page_title'] + $page[$label_field];
    +          }
    +          else {
    +            // No title.
    +            $page['#title'] = '';
    +            $skip_render = TRUE;
    +          }
    +        }
    +
    +        // Render the title, except in the case where it was set to blank.
    +        if (!isset($skip_render)) {
    +          $page['#title'] = $this->renderer->render($page[$label_field]);
    +        }
    

    It took me half and hour to figure out why we had both if (isset($page[$label_field]['#page_title'])) and if ($page[$label_field]['#page_title']).

    The way you're using #page_title to hold either an alternate render array or an instruction to suppress the title's rendering altogether surprised me.

    Maybe this is easier to understand:

    +++ b/core/lib/Drupal/Core/Entity/Controller/EntityViewController.php
    @@ -70,7 +70,28 @@ public function buildTitle(array $page) {
    -        $page['#title'] = $this->renderer->render($page[$label_field]);
    +          // The #page_title property allows the label field render array to specify how 
    +         // the page title should be rendered. It should be empty or a render array.
    +        $showTitle = TRUE; 
    +        if (isset($page[$label_field]['#page_title'])) {
    +          if (empty($page[$label_field]['#page_title']) ) {
    +            // The page title should be suppressed.
    +            $showTitle = FALSE;
    +          }
    +          else {
    +            // The label field has provided an alternate render array for this circumstance.
    +            // Fill out any missing properties in it by merging in the usual label render array.
    +            $page[$label_field] = $page[$label_field]['#page_title'] + $page[$label_field];
    +          }
    +        }
    +
    +        // Render the page title if it is wanted.
    +        if ($showTitle) {
    +          $page['#title'] = $this->renderer->render($page[$label_field]);
    +        }
    +        else {
    +          $page['#title'] = '';
    +         }
    
  2. +++ b/core/modules/node/node.module
    @@ -605,16 +605,36 @@ function template_preprocess_node(&$variables) {
    +  // If the date, author_name and title fields are not configurable, make them
    ...
    +  if (!$node->created->getFieldDefinition()->isDisplayConfigurable('view')) {
    ...
    +  if (!$node->uid->getFieldDefinition()->isDisplayConfigurable('view')) {
    

    I thought the field's machine names were 'created' and 'uid' not 'date' and 'author_name'?

  3. +++ b/core/modules/node/node.module
    @@ -617,15 +616,19 @@
    +  if ($node->title->getFieldDefinition()->isDisplayConfigurable('view')) {
         $variables['label'] = $variables['elements']['title'];
         unset($variables['elements']['title']);
    +    // The field template (field--node--title.html.twig) must generate inline
    +    // elements that the node template wraps in a header tag.
    +    // @todo It is unfortunate that the field template has to handle this
    +    // special case, but for back-compatibility reasons it is not possible
    +    // to change the behavior until D9.
    +    $variables['elements']['title']['#inline_title'] = TRUE;
    +  }
    +  else {
    +    // The title field must be displayed as a normal field.
    +    $variables['elements']['title']['#inline_title'] = FALSE;
       }
    

    This seems wrong; it makes isDisplayConfigurable=TRUE lead to #inline_title=TRUE. And shouldn't we be setting #inline_title on $variables['label']?

    How about something like:

    + if (!$node->title->getFieldDefinition()->isDisplayConfigurable('view')) {
    + $variables['label'] = $variables['elements']['title'];
    + unset($variables['elements']['title']);
    + // The node template will apply its own markup around the label.
    + // Therefore the node title template needs to be instructed to only
    + // generate inline markup in this situation.
    + // @todo Simplify the node template in D9
    + $variables['label']['#inline_title'] = TRUE;
    + }

    Is it OK to leave #inline_title unset when it's not needed?

    I'm a bit worried about BC here. What happens if someone has currently has a custom node title template? And a custom node template and custom node title template. Needs thinking through.

adamps’s picture

StatusFileSize
new21.09 KB
new4.28 KB

@jonathanshaw Thanks 1-3 done with minor tweaks to comment wording. Fixing (3) fixes the tests.

Is it OK to leave #inline_title unset when it's not needed?

Yes looks like we can - done

I'm a bit worried about BC here. What happens if someone has currently has a custom node title template? And a custom node template and custom node title template. Needs thinking through.

Good point, and I believe have already thought it through. That person is 100% fine provided that they don't enable setDisplayConfigurable on the node title. If they want the new function then they need to fix their custom templates in line with core. There is a CR draft attached to this issue with text explaining this.

adamps’s picture

Status: Needs work » Needs review

I have asked on drupal answers to see if anyone can help simply the awkward code in EntityViewController.

jonathanshaw’s picture

Some change to EntityViewController is required as (a) otherwise you get h2 inside span in the title block and (b) the title field fails to show on a page because it been written into #title (which occurs even if the title block has been disabled).

I'm still not properly understanding these two issues. What causes them and why there are no other solutions.

Seems like we've got 2 problems we're working on:
1. Controlling the title outside of full page contexts
2. Controlling the title inside full page routes

We got the first one sorted. The second one is harder.

I'm not at all convinced that we should be influencing the page title from the entity display mode UI. But I take your point that buildTitle is suppressing further display of the label indiscriminately, regardless of the how the title block is set up. The code stems back to #2498849: Entity view controller title rendering is expensive.

One possible solution:
- reset #printed after rendering in buildTitle (or render a clone to avoid it).
- have an entity preprocess hook or prerender callback, such that any time an entity is being rendered checks if this is a full page context, and sets #printed on the label field if it is.

My favorite solution is: do nothing. If you need to render the title amongst other fields in the main content region on a full page display, then you'll need to have a custom entity preprocess hook that sets #printed=false. Would that work?

Regarding the "h2 inside span in the title block", could we fix that by a custom buildTitle on the NodeViewController that added the #inline_title property?

adamps’s picture

@jonathanshaw: why are there no other solutions

On the contrary, I hope there are, and the IS states: This is the best solution we can see given the BC requirement - we would welcome any neater suggestion.

@jonathanshaw I think you need to actually start trying some of your candidate solutions in code and then you will start to understand it more fully. At the moment it seems to me that your alternatives either won't work, or are much more hacky than the current solution.

For b) you are along the right lines that the problem relates to #printed. You cannot arbitrarily reset it though or you will start to get double titles in other cases. I feel that manually setting #printed is a big hack to be avoided. The currently solution is carefully to do the better thing which is to avoid rendering the field and needless triggering #printed.

I'm not at all convinced that we should be influencing the page title from the entity display mode UI

Thanks to your suggestion to move the TitleFormatter out, this patch no longer contains the code that does that.

Regarding the "h2 inside span in the title block", could we fix that by a custom buildTitle on the NodeViewController that added the #inline_title property?

Don't forget that this issue applies to all entity types, not just nodes.

adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new21.52 KB
new1.09 KB

Fixed one further remaining bug introduced with the recent code simplifications - I had forgotten one case with #inline_title.

adamps’s picture

StatusFileSize
new19.81 KB
new1.52 KB

OK, I have become convinced to split off the changes in EntityViewController to a separate issue #2941208: Title formatting broken due to flawed EntityViewController->buildTitle. This means we have separated off the remaining complicated/untidy part as @jonathanshaw requested.

The extra information that persuaded me that this is a good split is that I discovered the problems now in the other issue are wider than what we are doing here - i.e. it affects people even if they aren't trying to hook setDisplayConfigurable.

The downside is that users wanting to use the manage_display module will need to take patches from both issues. I'll update manage_display documentation to make that clear once I have all the patches in place.

@jonathanshaw - I hope this means that you will now be willing to set RTBC,

adamps’s picture

StatusFileSize
new20.07 KB
new2.3 KB

Minor addition to #76 patch to flag lines that can hopefully later be removed.

adamps’s picture

Status: Needs work » Needs review

That last test fail was just a glitch

jonathanshaw’s picture

Title: Node/taxonomy rendering should respect configurable field display » Field rendering should respect configurable field display
Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Obviously we still need tests, but it seems fair to ask a committer to sanction the basic approach before the tests are written.

I'm leaving this set to the 'node' component as this is the most heavily affected.

adamps’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs review

@jonathanshaw Excellent thanks. I updated the IS somewhat.

(essentially to remove detail and leave the reader to refer to the related issue. The detail that was previously present was only part of the problem and the reference to view modes was a slight red herring - view modes are entity-type specific and there is not a guaranteed correspondence with "own-page").

adamps’s picture

Status: Needs review » Reviewed & tested by the community

Oops sorry accidentally changed the status from browser caching field values - reverting.

berdir’s picture

  1. +++ b/core/modules/aggregator/aggregator.theme.inc
    @@ -46,5 +46,8 @@ function template_preprocess_aggregator_feed(&$variables) {
    +  if (!$feed->title->getFieldDefinition()->isDisplayConfigurable('view')) {
    

    Lets not rely on __get() for those fields, $feed->getFieldDefinition('title') is IMHO nicer and even a bit shorter.

  2. +++ b/core/modules/node/node.module
    @@ -605,16 +605,37 @@ function template_preprocess_node(&$variables) {
    +  if (!$node->uid->getFieldDefinition()->isDisplayConfigurable('view')) {
    +    $variables['author_name'] = \Drupal::service('renderer')->render($variables['elements']['uid']);
    +    unset($variables['elements']['uid']);
    +  }
    

    what does this mean for $variables['display_submitted'] = $node_type->displaySubmitted(); exactly?

    I see that you in the template check for all three variables now.

    We have two existing related issues, one is #1399990: Remove "Display author and date information" in Display Settings in favor of listing Author and Date in Manage Displays and the other is #1884094: Split "Display author and date information" into 2 vars/options, which I just closed as a duplicate of the first. maybe we should leave those two fields out of this and let the other issue figure out what to do about them and focus on title here?

  3. +++ b/core/modules/node/templates/node.html.twig
    @@ -75,14 +75,14 @@
       {{ title_prefix }}
    -  {% if not page %}
    +  {% if label and not page %}
         <h2{{ title_attributes }}>
           <a href="{{ url }}" rel="bookmark">{{ label }}</a>
         </h2>
       {% endif %}
       {{ title_suffix }}
    

    One problem that this doesn't solve is the problem with title prefix/suffix.

    Mabye it doesn't need to, not sure. But it's also about the position, if you customize title but not display_submitted, then you would not be able to get the title to show up above. Of course, without removing that hardcoded position, we can also not easily move a field above the title.

    Since core does not yet allow to configure this, might be acceptable. But I guess we eventually want to remove title and similar variables completely for 9.x, and the question is what exactly we need to do to achieve that.

  4. +++ b/core/themes/stable/templates/content/node.html.twig
    @@ -15,7 +15,7 @@
      *   methods for the node object.
    - * - label: The title of the node.
    + * - label: (optional) The title of the node.
    

    To be honest, I still don't quite understand the purpose of the stable theme. In theory, we're not allowed to change it, but with a change like this, we kind of have to.

    This needs to be reviewed by a frontend maintainer to confirm those changes are OK.

jonathanshaw’s picture

Status: Reviewed & tested by the community » Needs work

Thanks so much for the review @berdir!

#83.2

what does this mean for $variables['display_submitted'] = $node_type->displaySubmitted(); exactly? I see that you in the template check for all three variables now.

I think you have a point this needs more thought. We have may have a BC breach here. Someone may have set isDisplayConfigurable for the uid field in order to modify the output with a formatter, while still expecting it to render as part of the display_submitted area.

I suggest we preserve the existing behavior if someone is using it, so:

+  if (!$node->getFieldDefinition('uid')->isDisplayConfigurable('view') && !$variables['display_submitted']) {
+    $variables['author_name'] = \Drupal::service('renderer')->render($variables['elements']['uid']);
+    unset($variables['elements']['uid']);
+  }

I suggest we leave it in this issue, as this is about a single concern across a wide range of entity and field types, trying to ensure people can customise things if they want to. The other issue OTOH is a good place to discuss changing the OOTB behavior of those particular node fields.

Nothing in this issue makes an immediate difference unless you use a hook to modify the entity types's base field definition to set isDisplayConfigurable=TRUE.

#83.3
I don't understand what title_prefix is all about. But maybe this is slightly more BC preserving:

  {% if label %}
    {{ title_prefix }}
    {% if not page %}
       <h2{{ title_attributes }}>
         <a href="{{ url }}" rel="bookmark">{{ label }}</a>
       </h2>
   {% endif %}
   {{ title_suffix }}
 {% endif %}

And at the same time we add the suffix to the node title templates:

+{% else %}
+   {{ title_prefix }}
+   {% include "field.html.twig" %}
+   {{ title_suffix }}
+{% endif %}
berdir’s picture

I think the only thing that uses those prefix/suffix things in core is contextual links, those would no longer work. And we can't just move them because they wouldn't get populated in a different template. See contextual_preprocess() it needs to be on the entity template.

jonathanshaw’s picture

Thanks for the pointer. It seems like {{title_prefix}} and {{title_suffix}} are also used for RDF metadata and shortcut creation.

All these uses cases seem to work fine on full view modes, when $page=FALSE and there is no content between {{title_prefix}} and {{title_suffix}}. The pencil icon appear in line with the top content (the 'submitted' info in that case).

Therefore it looks like the patch as stands should work fine in this regard.

adamps’s picture

Status: Needs work » Reviewed & tested by the community

Thanks @Berdir for #83.

To give us some means of talking about stuff:

  • in the "old way" titles and some other fields are hard-coded into templates
  • in the "new way" everything is done with setDisplayConfigurable and field formatters

1) Good idea

2) Answers below - net I do not currently perceive any need to change code - please feel free to correct me.

  • "Display submitted" is part of the "old way", and you would not set it in the "new way" - you would instead disable the fields in manage display. A module that hooks setDisplayConfigurable could also hook to disable "display submitted" in the UI but that's out of scope of this issue.
  • I would say that the other issue has a different goal and emphasis: it aims to change the UI in Core for 2 specific fields in a non-BC way. This issue aims to fix all places where Core prevents modules from customising the UI, but with BC preserving the existing UI by default. To achieve that, we must wrap an if (isDisplayConfigurable) around any call to unset a variable. If the other issue lands after this one, it can simply remove the whole if statement and contained code relating to those fields.
  • #84 @jonathanshaw

    Someone may have setDisplayConfigurable for the uid field in order to modify the output with a formatter, while still expecting it to render as part of the display_submitted area.

    Well they might, but they would have a confusing UI as the site builder can move the field up and down in the order but nothing happens. Don't forget our initial discussions on BC and the wording of the change notice: behavior may change on a heavily customised site, in particular one that already calls setDisplayConfigurable.

3) Answers below - net I do not currently perceive any need to change code - please feel free to correct me.

  • In summary of #84-86, title_prefix and title_suffix are already not fully connected to the title. If page is true, then the prefix and suffix appear but not the title in between. The same will happen when using a field formatter, so it's fine.
  • I agree, if a user wants to be able to order to fields at will, then they would have to use the "new way" for all of them. That works and you can test it already with the manage_display module. I personally feel half "old way" and half "new way" is poor UX, but this issue leaves the choice to each site builder.
  • I agree that I would expect the "old way" to be removed in D9. It should be easy: just remove the corresponding code from process and templates.

4) In that case, would you prefer to leave the stable theme as is?? It would still work, but would not support setDisplayConfigurable.

adamps’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new20.07 KB
new580 bytes

Patch addresses #83.1. Please let me know anything else that needs doing.

jonathanshaw’s picture

There are other related occurrences of #83.1; can we not change the pattern every time getFieldDefinition is called?

they would have a confusing UI as the site builder can move the field up and down in the order but nothing happens.

True. But is there are drawback to covering BC in this edge case in the way I suggested?

adamps’s picture

@jonathanshaw re code in #84:
(I think you would need to remove the ! before $variables)

1) Well it could reduce BC in a case where we promised not to, for example: the site has a custom template that uses author_name but doesn't set display_submitted.

I am trying to set out a clear picture on BC.

  • Sites that don't call isDisplayConfigurable will get exactly the same behavior as now.
  • The (small minority) of sites that already call isDisplayConfigurable in a hook may need to change their code, but the fixes here should allow a lot of simplification and removing of hacks.

2) I like that the code we have now has the same pattern for every field on every entity type.

adamps’s picture

There are other related occurrences of #83.1; can we not change the pattern every time getFieldDefinition is called?

Good idea, I hadn't spotted that - feel free to upload a new patch (or I will probably get to it tomorrow afternoon).

jonathanshaw’s picture

Status: Needs review » Needs work

could reduce BC in a case where we promised not to, for example: the site has a custom template that uses author_name but doesn't set display_submitted.

Good point, I'm convinced.

I think your BC approach is sound: try to preserve BC as much as possible, but if it has to break somewhere let that be where the site is already using isDisplayConfigurable.

Is it time for tests?

adamps’s picture

adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new20.07 KB
new1.73 KB

New patch that covers #89. It would be great if we can get back to RTBC.

Is it time for tests?

If you are offering, then please go ahead:-)

Personally speaking I won't have time for a couple of weeks. I am hoping for a clear indication from a core committer / expert that this patch is ready for commit (aside from tests).

@Berdir I would welcome your view.

jonathanshaw’s picture

Status: Needs review » Reviewed & tested by the community

I think the matters raised by @Berdir have been addressed.

Not sure how we get a review from a frontend maintainer as @berdir suggested.

RTBC again to seek the guidance you're requesting.

berdir’s picture

Assigned: Unassigned » lauriii
Issue tags: +Needs subsystem maintainer review

Lets try like this.

lauriii’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -Needs subsystem maintainer review

Overall, the changes look great for me. I also think that we can make the changes for the Stable and Classy templates.

  1. +++ b/core/modules/node/node.module
    @@ -605,16 +605,37 @@ function template_preprocess_node(&$variables) {
    +  if (!$node->getFieldDefinition('created')->isDisplayConfigurable('view')) {
    ...
    +  if (!$node->getFieldDefinition('uid')->isDisplayConfigurable('view')) {
    ...
    +  if (!$node->getFieldDefinition('title')->isDisplayConfigurable('view')) {
    

    I assume we can remove these in D9. Given that this is an opt-in feature, we probably shouldn't place this in Stable since otherwise, this wouldn't be available for people not using Stable. We should probably add a @todo to revisit this before D9.

  2. +++ b/core/themes/stable/templates/content/node.html.twig
    @@ -15,7 +15,7 @@
    + * - label: (optional) The title of the node.
    
    @@ -23,8 +23,8 @@
    + * - date: (optional) Themed creation date field.
    + * - author_name: (optional) Themed author name field.
    
    @@ -73,14 +73,14 @@
    +  {% if display_submitted and author_name and date %}
    
    +++ b/core/themes/stable/templates/content/taxonomy-term.html.twig
    @@ -5,7 +5,7 @@
    + * - name: (optional) Name of the current term.
    
    +++ b/core/themes/stable/templates/dataset/aggregator-feed.html.twig
    @@ -7,7 +7,7 @@
    + * - title: (optional) Title of the feed item.
    

    Changing variables to optional is technically a BC break. We should create a change record for that.

  3. Make sure that the changes applied for Bartik get done for Umami theme as well :)
lauriii’s picture

Assigned: lauriii » Unassigned

Unassigning as well

adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new28.31 KB
new15.89 KB

@lauriii many thanks

At top

I also think that we can make the changes for the Stable and Classy templates

OK, I am a bit confused, but given your comment in 1) I think that perhaps you meant to say "Bartik" here.

1) Done: removed changes to stable and done @todo.

2) There is already a CR draft.

3) Done Umami. That's completely new to me so please check I figured it out.

adamps’s picture

@lauriii Re Umami I don't understand how the existing code can work to display h1, for example in node--article--full.html.twig.

I would have thought that it would hit the exact problems in this issue and #2941208: Title formatting broken due to flawed EntityViewController->buildTitle:

  • EntityViewController->buildTitle calls render of the title field
  • this sets #printed
  • Drupal won't output the title again even if the template includes it

I would be very interested to understand this better as it potentially affects these issues.

adamps’s picture

After thinking about #2941208: Title formatting broken due to flawed EntityViewController->buildTitle I propose that we remove the inline_title part from this issue and instead handle it in a better way in the other issue. Please can I have your feedback on that idea?

Background is that there are two related problems

  1. Title field must be output inline whenever used as a page title. This applies for all entities and no matter what the value of setDisplayConfigurable.
  2. Title field must be output inline to put inside h2 in node template. This applies only for nodes and only if not isDisplayConfigurable. We plan to drop support for this case in D9.

Timing/relationships

  • Currently Drupal has code to handle both 1) and 2) for nodes. However it's a bit hacky as it takes over field--node--title.html.twig in a way that creates problems if isDisplayConfigurable.
  • 1) is currently an open bug for other entity types such as Media.
  • As part of solving #2941208: Title formatting broken due to flawed EntityViewController->buildTitle I would expect to solve 1) for all entity types. It would likely mean creating a template for entity-page-title that allows entity-type-specific variants.
  • Once that's done, the node-specific code only applies to 2) which is code that we plan to throw away in D9. So it seems wrong to ask theme designers and site owners to add a hacky inline_title test to their templates only to remove it again in D9.
  • Instead I propose that 2941208 should rework the node-specific code to build on the entity-page-title template created in that issue.
jonathanshaw’s picture

Re Umami I don't understand how the existing code can work to display h1, for example in node--article--full.html.twig.

I figured it out eventually: #printed suppresses rendering as part of the {{ content }} sub-render-array, but not when the variable is invoked directly in the template as {{ label }}.

adamps’s picture

@jonathanshaw #102 aha thanks for figuring that out

New patch as per #101 removing #inline_title, which I now plan to cover in #2941208.

Perhaps @lauriii is not planning to review again. Can @jonathanshaw or someone else please re-review to check the changes since last review:

  • response to @lauriii comments
  • removing #inline_title

Please comment to say that you have reviewed the code, and it is RTBC apart from the lack of tests. Then please set 'Needs work'.

jonathanshaw’s picture

Without #inline_title doesn't this need to be postponed on #2941208: Title formatting broken due to flawed EntityViewController->buildTitle, i.e. we'd have BC breakage without it?

adamps’s picture

Issue summary: View changes

Without #inline_title doesn't this need to be postponed on #2941208: Title formatting broken due to flawed EntityViewController->buildTitle, i.e. we'd have BC breakage without it?

I don't think so. I believe that we have simply solved slightly less of the total problem in this issue and left more of it to the other issue. Specifically we are no longer solving what was listed as item 2. I have updated the IS.

If you are still not convinced then please can you describe a specific scenario that concerns you?

berdir’s picture

+++ b/core/modules/node/templates/node.html.twig
@@ -75,14 +75,14 @@
   {{ title_prefix }}
-  {% if not page %}
+  {% if label and not page %}
     <h2{{ title_attributes }}>

I'm wondering what to do about the page flag.

The thing is that we not just "deprecate" the label variable but also page flag. To be clear, I think that's great, that was actually one of the reasons why making the label configurable is so tricky, as it is actually not tied to a view mode but a completely separate concept.

It means that showing a node with full view mode will still display the node title while node/N will not.

What this issue needs anyway is a change record, that explains what we are doing here, what it means for contrib/custom modules and themes.

Also, what is your plan with the manage_display module exactly? I think it makes sense to eventually add that to core as a BC layer. Meaning, we'd add a setting to make the field configurable, keep it of by default on existing sites (and on for new sites, maybe also in a second step) and then in 9.x remove the setting again and always have it configurable, removing the old label/page variables?

The second thing is about title_prefix/suffix. I'd love to see a separate issue to discuss what to do about those. My suggestion would actually be to deprecate both of them in favor of some kind of generic variable/placeholder that we just show at the top of the entity. We had similar discussions in media issues and ended up doing something rather strange there (only specifically display contextual links)

adamps’s picture

@Berdir Thanks

  • I agree page is also deprecated.
  • There is already a CR, please feel free to improve it or give feedback.
  • Stage 1), I feel manage_display is there to give a way for people to test these patches (but sadly I haven't always kept it up to date). Stage 2) I would be very happy for the module to be replaced by corresponding function in core. manage_display is not really intended to be a prototype for the interface that core would have, just a way to prove the function. I will defer to wisdom the relevant experts to decide on an interface.
  • Feel free to raise a separate issue for title_prefix/suffix - but I think I have enough issues already so I'm afraid I won't be able to work on it:-)
jonathanshaw’s picture

Re #105 #inline_title @AdamPS:

OK, that makes sense. We're saying that the title markup problem is not exacerbated by anything done in this issue, it's just a further obstacle that anyone wanting to make their titles configurable will have to work around for now depending on the details of their use case.

I agree that the code here is RTBC bar tests and improvement in change record. Regardless of the road map for the bigger context @berdir asks about, the changes here are minimal, unproblematic, and solve a real pain point that cannot be easily addressed otherwise.

Re #106 @Berdir:

It means that showing a node with full view mode will still display the node title while node/N will not.

Yes, it's the need for the default view mode to support both full page and other contexts that is the source of a lot of pain here.

Re {{title_prefix}} and {{title_suffix}} I think you want #2004966: Markup and variable cleanup for titles and attributes in all templates (possibly needs rescoping or title change).

jonathanshaw’s picture

Issue summary: View changes
berdir’s picture

Ah, missed the CR sorry. The change record should include before/after code/template snippets on how to update a node template to respect it being configurable. I would also include an example snippet on how to place the title somewhere else if using configurable titles (basically {{ content.title }} I guess, with a condition and maybe excluding it in content.

And sure, lets continue to discuss how to bring this into core so no module is needed in #2353867: [META] Expose Title and other base fields in Manage Display. Maybe also reference that issue and mention that the plan is to eventually deprecate the label and page variables completely?

About the title_suffix/prefix issue, yeah, sorry for being too lazy to create it myself :) I did of course not imply that you should work on that, quite the opposite. By creating separate issues, you can easily point out reviews that bring that topic up that it will not be addressed here but in that issue. Created #2943911: Figure out what to do with title prefix/title_suffix in entity templates.

Conflicted with #109, if that other issue also covers title prefix/suffix then maybe they can be merged.

adamps’s picture

Thanks for comments, please review updated CR. After that I will set back to needs work for the tests.

@Berdir

I would also include an example snippet on how to place the title somewhere else if using configurable titles (basically {{ content.title }} I guess, with a condition and maybe excluding it in content.

I have put this into a "future plans" section. I don't think it applies now as:

  • If the field is setDisplayConfigurable, it's a bad idea to hard-code it into the template because the GUI user will change the display order yet it will be ignored.
  • If the field is not setDisplayConfigurable, the field isn't present in content
berdir’s picture

I have put this into a "future plans" section. I don't think it applies now as:

If the field is setDisplayConfigurable, it's a bad idea to hard-code it into the template because the GUI user will change the display order yet it will be ignored.

But it's not future. If you set it to configurable, that's how it behaves *now*. So it's something that we should document, with an example.

There's basically two approaches to frontend, those who use standard templates and work with field configuration/weights and just display content.

But a lot of frontend developers either use some thing like patternlab/UI patterns or just want full control over their markup, so they likely end up displaying all fields separately.

Granted, it's unlikely that someone who fully customizes everything does go through the trouble of making it configurable in the first place, but that will get more likely as we add the UI to core. Maybe they rely on it in one case and have one special template or so.

Instead of an arbitrary "In the future", I'd just mention that for the case when the field is made configurable, it needs to be done like that.

adamps’s picture

@Berdir I'm afraid that I still don't follow you. It seems that you a proposing a site that has

  • taken the trouble to write a hook to call setDisplayConfigurable hence a base field appears in Manage Display
  • yet ignores whatever was chosen in Manage Display and hard-codes the markup in the template

This makes no sense to me because the GUI admin user gets a broken UX. A call to setDisplayConfigurable means "the developer grants the GUI admin control over the display". If the frontend developer wants full control of markup via templates, then they should not call setDisplayConfigurable.

that will get more likely as we add the UI to core.

Exactly. The point that we add the UI to core is exactly what I mean by "in the future". At that point there will be another CR which can give new instructions. This CR should not give instructions that are inadvisable now, but might become correct at some future date.

jonathanshaw’s picture

This makes no sense to me because the GUI admin user gets a broken UX.

This is the core pattern already. Themers can be selective in how they implement the choices made by sitebuilders in entity displays.

And it's not inconceivable that even a developer who was also the themer would choose to set displayConfigurable and pull the title out from content for separate rendering, if for example they wanted the sitebuilder to control the title's formatter and its settings but not its position.

What Berdir is suggesting is to illustrate how we have made the title available in the content array (if displayConfigurable), in the same way that other fields are. It's not a recommendation, just an illustration of what's possible. Some people understand a code illustration more than a verbal explanation.

berdir’s picture

Exactly. Yes, it is a bit weird, but as @jonathanshaw said, that's already how it works with other fields and this happens far more often than you think. And something that varies by the view mode/template. They might make it configurable for the full view mode where just a different order is enough, but maybe they use a custom layout with two columns, where they need to/want to display each field explicitly.

All I'm saying is that we should document how it works *if* it's enabled.

adamps’s picture

OK, I understand, thanks for taking the time to explain. It seems weird to me but I'll trust your greater knowledge of what people do. Please could one of you two update the CR as I'm still not sure I've grasped it well enough to explain it clearly.

jonathanshaw’s picture

I did a thorough reworking on the change record, see what you think.

berdir’s picture

Nice work on the CR!

> It is still not configurable by default, a developer must still set it to be configurable.

Suggestion:

"It is still not configurable by default, this must be done by a developer or a modue like manage_display. A setting for this will likely be added to Drupal core in a later phase and will eventually be always configurable." (maybe link that text to https://www.drupal.org/project/drupal/issues/2353867)?

We might be able to leave out the Future plans section then completely with that part?

> A developer now wishing to force the title to always appear on top, while allowing the sitebuilder to configure it in "Manage display" should now use the normal approach

Suggestion:
If those fields are set to "display configurable" so that they can be controlled by a sitebuilder, then they can be displayed in a specific position in the template like any other rendered field:

adamps’s picture

Status: Needs review » Needs work

Thanks @jonathanshaw. I'll set this back to "needs work" for the tests.

Request for help

To the 23 other followers of this issue. I have worked to complete the code (through 23 patches!) and we are now RTBC except for tests. I need to take some time off this issue now for other priorities (sadly no one is paying me on this one!).

Can anyone else help to write the tests - or can you reach out and find someone who is looking for a way to contribute? The task should be fairly straight forward and well-defined now, ideal for a student learning to code with a little help from a mentor. Probably it works something like this:

  1. Fetch the page for a node (probably don't need to test other entity types too?), and assert a few basic things
  2. Enable a test module that calls setDisplayConfigurable, and configure the base fields
  3. Fetch the page for a node again, and assert that the new layout is working plus there is no junk left over in the template

There is one complication that EntityViewController->buildTitle will capture display of the title (something we are solving in the related issue #2941208: Title formatting broken due to flawed EntityViewController->buildTitle). I can see two ways to workaround that

  • Run the test on a view of node teaser
  • OR Hook out the problematic code with hook_entity_view_alter()
adamps’s picture

I have been thinking some more on the recent comments and deprecation.

As I understand it we have proposed that in the long term:

  • We plan to get rid of the magic extra variables such as author_name.
  • Calling setDisplayConfigurable is allowed either TRUE/FALSE for node and other core entities.
  • Hard-coded templates are allowed, but they should be written using {{ content.title }}.

In that case it seems that instead of

  if (!$node->getFieldDefinition('created')->isDisplayConfigurable('view')) {

We should say something like

  if ($back_compatible_mode) {

Where $back_compatible_mode is a setting that currently defaults to true and can be overridden by the site builder.

We could also do the same for $variables['page'] and $variables['display_submitted'].

Thoughts??

  1. Is this a good idea?
  2. What should the actual code be for $back_compatible_mode?
jonathanshaw’s picture

I think that's unnecessary and problematic here.

It's unnecessary in that because isDisplayConfigurable is off by default for these fields, it functions as a reasonable test in itself of whether we are in a BC mode.

It's problematic in that the setting you suggest would have no effect unless isDisplayConfigurable was also turned on for the field. So it would have no effect for most sites, which would be confusing and add unhelpful complication.

A setting like that is an excellent way of preserving BC (particularly for distinguishing new vs existing installations) and possibly we should use it if we want to turn isDisplayConfigurable on by default. But that's for a future issue.

adamps’s picture

@jonathanshaw Thanks for the reply. I think we are talking at cross-purposes. Let's see if I can explain better.

It's unnecessary in that because isDisplayConfigurable is off by default for these fields, it functions as a reasonable test in itself of whether we are in a BC mode.

I agree that we have solved BC already. My reason for proposing a new idea is something else.

It's problematic in that the setting you suggest would have no effect unless isDisplayConfigurable was also turned on for the field.

No - in the new idea there is no call to isDisplayConfigurable. I plan to replace that if test with the new one.

Recap of the problem

We have some "legacy variables" such as "author_name" and "date". These are created by some "hard-coded" formatting in template_preprocess_node. That formatting only applies for a specific theming choice and it's wrong if isDisplayConfigurable. But I think it's also wrong (or at least unnecessary) if NOT isDisplayConfigurable AND custom formatting of submitted info.

Solution

In vanilla core, the field formatter should handle all formatting for base fields. I now believe this should apply always - whether or not isDisplayConfigurable. Site builders are recommended to follow this pattern and use the field formatter but could instead write a preprocess hook.

Old idea

Wrap legacy variables inside isDisplayConfigurable. However this is actually the wrong track as sites with isDisplayConfigurable=FALSE are still forced to use the legacy variables. I now believe that we actually want to get rid of the legacy variables for all sites.

New idea

Wrap legacy variables inside a global BC setting which could be something like theme_get_setting('old_entity_template_variables').

This way sites/themes can migrate away from the legacy variables at any time that suits them. We can remove the variables in D9.

A second benefit of the new idea is that it makes it very clear which code is deprecated. This can include 'page', 'author_picture', and 'display_submitted'. I propose we can also deprecate the corresponding UI for 'display_submitted' and 'features.node_user_picture' - these would much more logically be settings on the display formatter of the uid field.

Actual usability

The manage_display module is a good benchmark for how easy it is to setDisplayConfigurable. The new idea is definitely cleaner for the module in terms of submitted info, as I can just write a field formatter for uid. It's advantageous that the UI settings for 'display_submitted' and 'features.node_user_picture' have been removed as they don't work with the module.

jonathanshaw’s picture

the field formatter should handle all formatting for base fields. I now believe this should apply always - whether or not isDisplayConfigurable

Are you suggesting that the rendering of a field should invoke the default formatter for that field type if isDisplayConfigurable=false? Is that not the current behaviour?

theme_get_setting('old_entity_template_variables')

That's interesting. I thought you were proposing a per field or per bundle or per view mode setting, which I was concerned gave too much prominence to a setting that was irrelevant to most people.

I now believe that we actually want to get rid of the legacy variables for all sites...
I propose we can also deprecate the corresponding UI for 'display_submitted' and 'features.node_user_picture' - these would much more logically be settings on the display formatter of the uid field.

There's no doubt that this is the right direction of travel. And there's bound to be existing issues for this. It all ties in with setting isDisplayConfigurable=true by default. The question is whether to o it here or in a follow-up.

adamps’s picture

I guess I had in mind something like this:

/**
 * Prepares variables for node templates.
 *
 * Default template: node.html.twig.
 *
 * Most themes use their own copy of node.html.twig. The default is located
 * inside "/core/modules/node/templates/node.html.twig". Look in there for the
 * full list of variables.
 *
 * @param array $variables
 *   An associative array containing:
 *   - elements: An array of elements to display in view mode.
 *   - node: The node object.
 *   - view_mode: View mode; e.g., 'full', 'teaser', etc.
 */
function template_preprocess_node(&$variables) {
  $variables['view_mode'] = $variables['elements']['#view_mode'];
  // Provide a distinct $teaser boolean.
  $variables['teaser'] = $variables['view_mode'] == 'teaser';
  $variables['node'] = $variables['elements']['#node'];
  /** @var \Drupal\node\NodeInterface $node */
  $node = $variables['node'];

  // Helpful $content variable for templates.
  $variables += ['content' => []];
  foreach (Element::children($variables['elements']) as $key) {
    $variables['content'][$key] = $variables['elements'][$key];
  }

  $variables['url'] = $node->url('canonical', [
    'language' => $node->language(),
  ]);

  // Add article ARIA role.
  $variables['attributes']['role'] = 'article';

  // Some base fields on the node entity have historically been treated
  // specially.  This approach is now deprecated and the preferred method
  // is to handle all fields via $content and field formatters.
  // If configured, generate the old-style deprecated entity variables.
  // @todo In D9 delete this code and matching template lines.
  if (theme_get_setting('old_entity_template_variables')) {
    $variables['date'] = \Drupal::service('renderer')->render($variables['elements']['created']);
    unset($variables['elements']['created']);
    $variables['author_name'] = \Drupal::service('renderer')->render($variables['elements']['uid']);
    unset($variables['elements']['uid']);
    $variables['label'] = $variables['elements']['title'];
    unset($variables['elements']['title']);

    // The 'page' variable is set to TRUE in two occasions:
    //   - The view mode is 'full' and we are on the 'node.view' route.
    //   - The node is in preview and view mode is either 'full' or 'default'.
    $variables['page'] = ($variables['view_mode'] == 'full' && (node_is_page($node)) || (isset($node->in_preview) && in_array($node->preview_view_mode, ['full', 'default'])));

    // Display post information only on certain node types.
    $node_type = $node->type->entity;
    // Used by RDF to add attributes around the author and date submitted.
    $variables['author_attributes'] = new Attribute();
    $variables['display_submitted'] = $node_type->displaySubmitted();
    if ($variables['display_submitted']) {
      if (theme_get_setting('features.node_user_picture')) {
        // To change user picture settings (e.g. image style), edit the 'compact'
        // view mode on the User entity. Note that the 'compact' view mode might
        // not be configured, so remember to always check the theme setting first.
        $variables['author_picture'] = user_view($node->getOwner(), 'compact');
      }
    }
  }
}
berdir’s picture

The downside of a single variable is that we can never add something else to the list of deprecated variables.

Example:

You also put author_picture in there, but with author_name and author_picture, we have two different variants of the same field, that's something that we currently can't really do, not without layout_builder at least, as each field can only have a single formatter/rendering with the default field formatter API.

So likely, we'd actually not be able to deprecate author_picture just yet. So lets say we deprecate the others in 8.6 and keep author_picture. Now, I'm a good developer and I update my templates to rely on the new content.X variables and set the variable accordingly. But I still use author_picture because there is no replacement for it. But then core finds a solution for author_picture in 8.7 and also moves that inside the existing check. Now my template is broken when I update from 8.6 to 8.7.

Similar to custom/contrib entity types that might want to follow the example set by core, if they'd use the same variable any time later, they might also break for sites that already had the variable set.

We're also not really deprecating those variables just yet. We can't deprecate something without having a valid replacement, and requiring a contrib module is not an option. We can only really deprecate them in follow-up/related issues, when adding a method to make them configurable directly in core.

IMHO, the configurable check is a useful first step towards fully deprecating them.

That said, the author_name/author_picture is in fact also a bit of a problem for per-field "deprecation" as it is the same field. But we can figure that out later I think.

adamps’s picture

Thanks @Berdir, yes that all makes sense.

I think deprecation is at a field level and author_name/author_picture will be fine. If !isDisplayConfigurable you get the 2+ variables and of course may choose to use just one of them. If not, you get the field formatter output. I can't really imagine a valid use case in between - what would it be one variable and half the field formatter output?

So I propose that the patch should have an if test around the display_submitted code:

if (!$node->getFieldDefinition('uid')->isDisplayConfigurable('view')) {
  // Display post information only on certain node types.
  ...

I have noticed that 'metadata' is another awkward variable: like 'title_prefix' it picks up attributes from modules such as rdf. It has to be present on the node, but then moved to the uid field for display. It's a bit awkward, but I think I have it working in the manage_display module.

jonathanshaw’s picture

I propose that the patch should have an if test around the display_submitted code

I don't see the necessity?

The reason for our isDisplayConfigurable checks introduced here was not because these old variables were unnecessary if these fields were configurable, but because the associated unsets were removing them from the content variable and messing with ability to position them.

display_submitted may be unlikely to be used if uid is displayConfigurable, but it's also harmless and there's already a UI setting to disable it.

adamps’s picture

I don't see the necessity [of an if test around the display_submitted]

@jonathanshaw You are right, it is a fair point. I agree there is no necessity in terms of the task allowing modules to setDisplayConfigurable.

However this issue is also part of a wider task of tidying up base field display #2353867: [META] Expose Title and other base fields in Manage Display. I thought that the extra change would create a clearer and more consistent position for others to understand - disabling all of the special processing for uid rather than just part of it. I feel that the extra change makes it clearer for writing modules like manage_display and for planing the wider changes.

I don't have an especially strong feeling about it.

adamps’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new28.47 KB

OK I've written some basic tests. No changes to the patch compared with last time (can come back to #126 later).

I discovered (but did not yet solve) some more problems:

  1. Exactly like field--node--title.html.twig there are field--node--created.html.twig and field--node--uid.html.twig which force inline output and discard the label even if it was configured to be shown.
  2. rdf_preprocess_node has a hard-coded reference to $variables['display_submitted'] so doesn't work if setDisplayConfigurable.
jonathanshaw’s picture

Exactly like field--node--title.html.twig there are field--node--created.html.twig and field--node--uid.html.twig which force inline output and discard the label even if it was configured to be shown.

I'm wondering if we need a global solution to this along the lines of a variable passed to all field templates like "raw" or "minimal" or "entity_display" that allows the templates to discriminate whether they are being called as normal field templates or in some more barebones context where labels and other wrappers aren't needed.

adamps’s picture

StatusFileSize
new41.45 KB
new14.29 KB

New patch that solves #129.1, similar to the idea in #130.

Possibly we could move these extra bits into #2941208: Title formatting broken due to flawed EntityViewController->buildTitle to allow the earlier patch to be committed more easily. However without the extra bits, what we have isn't really fully usable so I feel it's worth expanding to the more useful solution.

Details

  1. New template variable '#inline_field', if set switches templates from 'field__' to 'inline_field__'.
  2. Enable it for node base fields if not isDisplayConfigurable.
  3. Enable it for page title. Applies to all entity types and hence fixes an existing bug e.g. for media.
  4. Remove existing templates for 'field--node--***' where the only purpose was to force inline output (possibly unwanted if setDisplayConfigurable).
  5. Applies to 3 fields in 3 themes. NB Includes stable else classy/bartik pick up unwanted templates from stable.
  6. Create inline-field.html.twig based on deleted templates.

TODO: Probably need some BC for themes that have their own customised field--node--***. In the long term they should rename it to inline-field.html.twig but in the short term if not isDisplayConfigurable we should probably hook it in as an extra suggestion.

Please let me know what you think of these extra changes.

adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new45.6 KB
new6.87 KB
new2.79 KB

The problem with #131 shown up by StandardProfileTest test fail is that it because I switch to using a new suggestion inline_field__* instead of field__*, Drupal calls correspondingly different preprocess functions, so rdf_preprocess_field__node__uid does not get called. I could rename that to rdf_preprocess_inline_field__node__uid but it's not really an answer as the same problem would apply to any custom hooks.

New patch #133 sticks with the field template and sets a new variable inline_field. This should fix the test. Unfortunately it is more of a BC problem: every theme that has overridden field.html.twig must update their template with a test for inline_field. If they don't, then the submitted info gets split onto multiple lines - see attached image file.

I can't yet see any perfect option unfortunately. Comments/ideas please.

adamps’s picture

Oops I missed out stable field.html.twig and forgot to update the comment in the other two field.html.twig.

adamps’s picture

Issue summary: View changes
jonathanshaw’s picture

Issue summary: View changes

I like this approach, but the patch seems weird. There's a lot more changing than I expected. Can you check the patch and makes sure it's what you're really suggesting now?

  1. +++ b/core/modules/system/templates/field.html.twig
    rename from core/modules/node/templates/field--node--uid.html.twig
    rename to core/modules/system/templates/inline-field.html.twig
    

    I think this is leftover from the previous approach?

  2. +++ /dev/null
    index 33b105f..0000000
    --- a/core/themes/classy/templates/field/field--node--title.html.twig
    

    Deleted by mistake I think?

every theme that has overridden field.html.twig must update their template with a test for inline_field. If they don't, then the submitted info gets split onto multiple lines

I don't understand why yet, but I won't try harder yet in case the patch is malformed.

adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new46.05 KB
new9.2 KB

Here is a new patch that hopefully fixes the tests and resolves muddles of last time.

  • I do still have inline-field.html.twig. It is not strictly a template in its own right but is used for %include from other templates.
  • Delete of field--node--title.html.twig in classy and system is deliberate. There is simply no need for it now. Previously there was a template per field but they were all identical. It's now covered by inline-field.html.twig.
  • I have hopefully solved the BC worry by leaving the field--node--title.html.twig in stable.
adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new46.05 KB
new971 bytes
adamps’s picture

Minor extra change to fix RDF

jonathanshaw’s picture

  1. Minor extra change to fix RDF

    It's not obvious to me what the problem is, or why this is the best fix. We'll need to update IS to explain, can you start by explaining it to me?

  2. +++ b/core/includes/theme.inc
    @@ -1860,6 +1861,9 @@ function drupal_common_theme() {
    	+    'inline_field' => [
    +      'base hook' => 'field',
    +    ],
    

    I don't understand why we need this or what it does. But I'm weak on theming ...

  3. +++ b/core/lib/Drupal/Core/Field/FormatterBase.php
    @@ -100,6 +100,7 @@ public function view(FieldItemListInterface $items, $langcode = NULL) {
    +        '#inline_field' => FALSE,
    

    Do we need this? I'm not sure what our best practices are for optional variables, whether to default them false or leave them unset.

  4. +++ b/core/modules/node/node.module
    @@ -171,15 +171,6 @@ function node_theme() {
    	-    'field__node__title' => [
    -      'base hook' => 'field',
    -    ],
    -    'field__node__uid' => [
    -      'base hook' => 'field',
    -    ],
    -    'field__node__created' => [
    -      'base hook' => 'field',
    -    ],
    

    Removing these seems inconsistent with leaving the templates in. Enlighten me?

  5. +++ b/core/modules/system/templates/field.html.twig
    @@ -32,6 +32,8 @@
    + *   If true, display an inline format, suitable for inside span/h1/h2 etc
    

    I doubt this is the right CS for multi-line variable comments.

  6. +++ b/core/modules/system/templates/field.html.twig
    @@ -39,6 +41,9 @@
    +{% include "inline-field.html.twig" %}
    

    Indentation?

  7. +++ b/core/modules/system/tests/src/Functional/Entity/EntityViewControllerTest.php
    @@ -43,9 +43,8 @@ protected function setUp() {
    	-      return '<h1 class="page-title">
    -            <div class="field field--name-name field--type-string field--label-hidden field__item">' . $label . '</div>
    -      </h1>';
    +      return '<h1 class="page-title"><span class="field field--name-name field--type-string field--label-hidden">' . $label . '</span>
    +</h1>';
    

    I worry about the disruption of dropping .field__item. Is it avoidable? At very least needs IS & CR mention.

  8. +++ b/core/themes/stable/templates/field/field--node--created.html.twig
    @@ -1,26 +1,14 @@
    + * Helper file for back-compatibility in case a theme has overridden
    + * field.html.twig but not added a test for inline_field.
    + * @todo Delete in D9.
    

    I think you could say something like "@deprecated, remove before D9.0 as it now duplicates field.html.twig."

adamps’s picture

@jonathanshaw thanks good comment, you picked up a lot of complex aspects that I need to explain better - here is a new patch.

1. Modules that use setDisplayConfigurable do not need or want $node_type->displaySubmitted() and will likely hide it in the UI. Instead the site builder can show/hide the field in manage display and choose a field formatter, which will manage its own markup. The manage_display module contains such a field formatter.

Hence node.module should only create derived submitted variables if !isDisplayConfigurable. I have now added a comment to mark that code @deprecated. If the code to set $variables['display_submitted'] is left in, code in rdf.module checks the setting and potentially leaves out the metadata. I fixed rdf.module to handle $variables['display_submitted'] being unset - I have now clarified this code and commented.

In terms of IS, this is a sub-case of item 1: it is just a bit more usurping of the processing of base fields.

2. This is necessary to allow {% include "inline-field.html.twig" %}. I have now added a comment.

3. I opted for consistency with the existing code. Without this line, template_preprocess_field has to check isset, which does not happen for any other variable.

4. In the early days of D8 there needed to be a hook_theme entry to pick up field--node--title.html.twig but that is no longer true - it gets picked up based on the theme suggestions. So that code has been unnecessary for a while. If there is a hook_theme entry, Drupal mandates that the template exist, which is not what we want (it's present only in stable and only for back-compatibility), hence I had to remove the hook_theme entry.

5. The alignment I used matches node.html.twig. Feel free to point to a CS doc that says otherwise.

6. I deliberately didn't indent to minimise disruption and preserve BC. Firstly, if many themes have to add the if test, it's faster and less VCS churn not to indent the entire template. Secondly indenting the lines does actually change the spaces in the HTML in a way that would have required changes to core tests, and could also break contrib theme tests so it seemed easiest to leave it. I guess I could try to add a comment to explain??

7. The inline-field template applies to all entity types and I propose we should keep that consistency or it's going to be really confusing and complicated. The templates I used match the historical node templates, hence avoiding any change for nodes. I think it's by far the most important case to keep nodes the same as before. Other entities are less often displayed on their own page - and to support that I claim I point out that no one seems to have noticed that Drupal currently generates illegal HTML in that case.

I guess if we want to be safer for now, I can change the patch so as not to affect the page title for non-node entities and we could handle that in the other issue.

8. Done.

adamps’s picture

For the CR, we should mention two more template fixes. These are in the same category: recommended to fix, but optional except in case of setDisplayConfigurable as it's fully BC

  • Need to change field.html.twig to add {% if inline_field %}
  • If field--node--*.html.twig, retire them in favour of inline-field.html.twig

Related bug fix, which possibly should move out of this issue:

  • .field__item removed from page titles for non-node entities (it was present on illegal markup)
jonathanshaw’s picture

Thanks for explaining those things, that mostly made sense to me now you explained it.

Related bug fix, which possibly should move out of this issue:

.field__item removed from page titles for non-node entities (it was present on illegal markup)

I'm always up for splitting out issues, but not sure how we could here, without special-casing node in some awkward way.

+    // Hook for inline field template, inline-field.html.twig. Code should not
+    // directly use '#theme' = 'inline_field', because that bypasses any
+    // preprocess hooks such as rdf_preprocess_field__node__uid. Instead code
+    // should set '#theme' = 'field' and '#inline_field' = TRUE. The
+    // field.html.twig template checks the variable and conditionally includes
+    // the template:
+    //   {% if inline_field %}
+    //   {% include "inline-field.html.twig" %}
+    //   {% else %}
+    'inline_field' => [
+      'base hook' => 'field',
+    ],
2. This is necessary to allow {% include "inline-field.html.twig" %}. I have now added a comment.

I still don't understand the necessity.

{% include 'some-arbitrarily-named-unregistered-partial-template.html.twig' %}

works fine for me, even if the partial is only present in a parent theme.

(I also wonder if core theme maintainers will think it worth creating this template partial as the only repetition in core that it's saving is in the the deprecated field templates.)

If the code to set $variables['display_submitted'] is left in, code in rdf.module checks the setting and potentially leaves out the metadata.

Sorry to ramble ...

I worry about leaving the display_submitted setting in the UI if it no longer produces the expected results in some circumstances, it could cause some head scratching. For example, a developer might not anticipate that setting uid to be configurable would make their author_picture variable disappear. I understand that configurable uid and display_submitted are two different paradigms, but as long as we have them both it seems better to keep them working simultaneously without interfering with each other.

This makes me interested in leaving (for now) the display_submitted and author_picture variables stuff intact regardless of uid display configurability, and instead putting more checks into rdf.module to make sure the metadata behaves right.

I've tried to understand how rdf.module works, but I can't find anything that ever sets the mapping's fieldMapping property, so hit a dead end. I'm not sure what happens to $created_mapping if the uid is configurable and disabled, whether it's affected by that.

It seems like in principle we should be enabling the created data metadata at the node level only if the created date is visible to the visitor; otherwise we might be leaking information that the site wishes to keep private. Therefore we have 6 situations:

Conf = uid display configurable
Enabled = uid configurable display enabled
d_s = UI "display submitted" setting
Metadata = metadata is desired given the values of Conf, Enabled and d_s

Conf Enabled d_s Metadata
N - Y Y
N - N N
Y Y Y Y
Y Y N Y
Y N Y Y
Y N N N

So maybe we need something like this

$uid_enabled = // code to check uid is configurable & enabled in this view mode
if (!empty($created_mapping) && ($display_submitted || uid_enabled ))
In terms of IS, this is a sub-case of item 1: it is just a bit more usurping of the processing of base fields.

I'm not sure that's the right way of conceiving this. It seems more about deciding what metadata is a part of the display of node itself, not just of its individual fields.

I do wonder if the simplest thing is to leave the metadata and $display_submitted as they are. If someone wants the metadata to appear on the node, they check simply check the display_submitted setting; this is true whether or not they have made uid configurable.

What's the harm in leaving things as they stand? Could we leave this to be resolved in the future when uid is made always configurable?

It may be that we decide then that the best thing to do is always default to adding the data metadata to the node, regardless of whether the date is displayed to the visitor; it keeps it clean and simple for the 80% use case, and developers can always strip it out.

adamps’s picture

Thanks for the reply.

I'm always up for splitting out issues, but not sure how we could here, without special-casing node in some awkward way.

It's not too bad: in EntityViewController->buildTitle we would need to add an if:

+if ($entity_type == 'node)
        $page[$label_field]['#inline_field'] = TRUE;
+}
2. This is necessary to allow {% include "inline-field.html.twig" %}. I have now added a comment.
I still don't understand the necessity.

If I comment out that line and rebuild cache then I get an error The website encountered an unexpected error. Please try again later.</br></br><em class="placeholder">Twig_Error_Loader</em>: Template &quot;inline-field.html.twig&quot; is not defined (Drupal\Core\Template\Loader\ThemeRegistryLoader: Unable to find template &quot;inline-field.html.twig&quot; in the Drupal theme registry.) in &quot;core/themes/stable/templates/field/field--node--title.html.twig&quot; at line 11. in <em class="placeholder">Twig_Loader_Chain-&gt;getCacheKey()</em> (line <em class="placeholder">129</em> of <em class="placeholder">vendor/twig/twig/lib/Twig/Loader/Chain.php</em>).

I also wonder if core theme maintainers will think it worth creating this template partial as the only repetition in core that it's saving is in the the deprecated field templates.

The benefit is mostly for themers:

  • Theme can override field.html.twig but leave inline-field.html.twig unaltered (or vice versa)
  • Each theme fixing their field.html.twig only has to have a single line {% include } rather copy in the whole inline-field.html.twig

I worry about leaving the display_submitted setting in the UI if it no longer produces the expected results in some circumstances .... [many following paragraphs]

Unfortunately I don't really understand your reason/purpose for objecting to the current code and wanting something else.

The title of this issue is "Field rendering should respect configurable field display". So if isDisplayConfigurable then the settings in "Manage Display" should work 100% and anything else have no effect. It is not my intention to ever have both display_submitted and setDisplayConfigurable in the UI; however this issue is not changing the UI. Personally I would recommend any module calling setDisplayConfigurable to hide display_submitted. As you say, they are two completely different paradigms and you want one or the other but not both.

It seems that you are considering control of "created metadata" separately from "created field display". That's not possible with Core now for this field or other fields and I don't see a mainstream use case for making it possible in Core. It seems like a bit of a tangent, but would of course be possible with custom module hooks or custom formatters.

What's the harm in leaving things as they stand?

  1. Main reason is that the metadata is likely to be omitted.
  2. Secondary reason is that it seems unhelpful to have a variable $variables['display_submitted'] that is often wrong.

Yes I could refactor the code to solve 1) and yet keep $variables['display_submitted']. I don't understand why that's a good idea though.

It seems like in principle we should be enabling the created data metadata at the node level only if the created date is visible to the visitor; otherwise we might be leaking information that the site wishes to keep private

Yes I agree. I had assumed that $created_mapping would be empty if the display was disabled, but now I scan the code I worry that's not necessarily true - I'll check.

It may be that we decide then that the best thing to do is always default to adding the data metadata to the node, regardless of whether the date is displayed to the visitor

This seems to contradict the previous paragraph and I don't agree for the reasons you gave above:-)

adamps’s picture

New patch. Aim is to be as safe as possible because it's already a fairly big and complicated change.

jonathanshaw’s picture

Sorry not had time to review the latest yet, but I did have a thought:

+++ b/core/includes/theme.inc
@@ -1860,6 +1861,18 @@ function drupal_common_theme() {
+    'inline_field' => [
+      'base hook' => 'field',
+    ],

I think you need this only because inline-field.html.twig is in the system module not a theme.

Given it is fundamentally a helper for themers (as you explained in #146) rather than something that core needs, I suggest it would be better to add it to classy & stable rather than the system module, in which case you don't need this hook.

This is a little less DRY in core itself, but the fact that this hook needs a long comment explaining why not to use it as normal smells to me.

jonathanshaw’s picture

I like #147. I think we're close to RTBC for real, just need the RDF etc tests. IS and CR will need a check over too.

+++ b/core/modules/node/node.module
@@ -627,6 +633,8 @@ function template_preprocess_node(&$variables) {
+  // @deprecated In D9 delete this code and matching template lines. Using
+  // a field formatter is more flexible and consistent.

I don't think the comment is right. @deprecated is quite technical in it's usage I think. If anything it's the variables in the template that would need to be @deprecated. What we should probably do is make sure there is an issue about removing the whole display_submitted mechanism, and a meta to keep track of those whole family. Possibly we could add an @todo here linking to that issue, but again I have the impression we only use those in quite specific circumstances


+++ b/core/modules/rdf/rdf.module
@@ -323,7 +323,10 @@ function rdf_preprocess_node(&$variables) {
+  $display_created = $variables['node']->getFieldDefinition('created')->isDisplayConfigurable('view') ? isset($variables['elements']['created']) : $variables['display_submitted'];
+  if (!empty($created_mapping) && $display_created) {

OK, this is consistent with with what we do in template_preprocess_node and node.html.twig:
we disrupt the old-style display of submitted info if the relevant fields are made configurable.

And we have to do this because otherwise the old-style disrupts the configurable display. The only way to avoid it would involve cloning fields.

+++ b/core/modules/rdf/rdf.module
@@ -323,7 +323,10 @@ function rdf_preprocess_node(&$variables) {
+  // Check if the created information is displayed.  There are two different
+  // possibilities, @see template_preprocess_node.

How about:
If 'created' display is not configurable then it is controlled by the display_submitted setting. @see template_preprocess_node.

jonathanshaw’s picture

Issue summary: View changes
adamps’s picture

Thanks @jonathanshaw. I haven't done a new patch yet as I have a question for you first (see bold italic).

#148

  • inline-field.html.twig is already in classy and stable
  • If I remove core/modules/system/templates/inline-field.html.twig and back out the changes to theme.inc I still get the same error.

For the last several of your comments a major point seems to be inline-field.html.twig. I have tried a few variations but it seems to keep coming up. The only thing I can think of is to remove the mechanism entirely. It will mean more duplication, but that's not a big deal in comparison to making it clearer. Note that every theme developer will have to add this to field.html.twig rather than just an include.

{% if inline_field %}
<span{{ attributes }}>
  {%- for item in items -%}
    {{ item.content }}
  {%- endfor -%}
</span>
{% else %}

Are you in agreement that I should remove inline-field.html.twig?

#149

  • I have replaced @deprecated with @todo which seems to match the general usage.
  • I have adopted your improved comment text.
jonathanshaw’s picture

Are you in agreement that I should remove inline-field.html.twig?

I'm neutral on that.

From my testing I'm certain that undeclared arbitrarily named template partials can be included in other templates, so the declaration is not absolutely necessary. I'm weak on theming so tentative, but the way the template is being declared here doesn't feel right to me, I'd expect a maintainer to reject it.

adamps’s picture

From my testing I'm certain that undeclared arbitrarily named template partials can be included in other templates, so the declaration is not absolutely necessary.

Sorry but I can't get it to work without the declaration. If you can, please upload a patch with passing tests. NB I thought you were right for a while, but I think it was just caching.

If you can't get it to work either then I am willing to remove inline-field.html.twig.

jonathanshaw’s picture

Sorry I'm travelling for 2 weeks. What I tried was creating a template called monkey.html.twog in my theme or parent theme and including it in field.html.twig in my theme.

adamps’s picture

@jonathanshaw I'm sure you will be amused to learn how many hours of my life I have spent figuring this one out.

I deduce that you ran your test using a Bootstrap derived theme, and it worked because Bootstrap has a mechanism to automatically register hooks for any *.html.twig files that don't already have hooks.

Setting aside the exception of Bootstrap, then the normal procedure is to register new templates via hook_theme. Possibly we could avoid the need for these 3 lines if we called the template field__inline instead of inline_field, but I don't favour that as it basically disguises what we are doing and potentially creates confusion as it looks like a field name or type 'inline'.

Therefore it seems that the lines in theme.inc are necessary and correct unless we drop inline-field.html.twig entirely. As far as I can see you have not put forward any reason against the lines except that you thought they weren't necessary.

I have updated the comment in theme.inc to try and make it clearer.

I'm weak on theming so tentative

In that case, please can we avoid spending any further time until we have an opinion from an expert?

adamps’s picture

Enhance tests to check quickedit and rdf attributes

jonathanshaw’s picture

#155 you're right, it was bootstrap, sorry! Not amused!

jonathanshaw’s picture

Status: Needs review » Reviewed & tested by the community

This seems ready. Possibly inline-field.html.twig needs mentioning in CR.

adamps’s picture

Issue summary: View changes

Yay, thanks @jonathanshaw.

I hesitate to raise a doubt just as we reach RTBC but if we don't raise things I expect others will.

1. If isDisplayConfigurable $variables['metadata'] (meta-created tag) basically gets lost and is never printed. I have some code in the contrib module manage_display that rescues it. However this seems wrong - core should print the metadata without need for a contrib module.

In rdf.module, the other meta items get put into $variables['title_suffix']. I propose that if isDisplayConfigurable we put meta-created into title_suffix too.

2. I noticed that we could avoid the need for the second node.html.twig change

-  {% if display_submitted %}
+  {% if display_submitted and author_name and date %}

Instead node.module should only set display_submitted if both variables are available. This is something I wanted to do earlier but backed off to minimise changes. My new insight means that the balance has changed as the top priority is to minimise changes in templates. With this new approach, it significantly reduces the problems for a site that calls setDisplayConfigurable but doesn't change the node template - it avoids random printing of "Submitted by on".

Any objections if I create a new patch that includes these two extra changes?

jonathanshaw’s picture

Yes, I think you're right on both.

adamps’s picture

New patch for #159

jonathanshaw’s picture

Status: Needs review » Reviewed & tested by the community
adamps’s picture

Excellent, thanks @jonathanshaw.

adrian83’s picture

A big thank you to all of you for your tireless work on this!

alexpott’s picture

Status: Needs work » Reviewed & tested by the community

Testbot had a hiccup re-rtbcing

andypost’s picture

+++ b/core/modules/node/node.module
@@ -632,19 +632,22 @@
+        // view mode on the User entity. Note that the 'compact' view mode might
+        // not be configured, so remember to always check the theme setting first.
+        $variables['author_picture'] = user_view($node->getOwner(), 'compact');

Instead of user_view() better use $node->getOwner->view('compact) also makes sense to assert() that view mode configured

berdir’s picture

Entities do not have a view() method. If anything, it needs to use the view builder.

adamps’s picture

Status: Needs work » Reviewed & tested by the community

@andypost although at first glance the lines you refer to appear to be new in this patch in fact they are existing lines that were merely indented. We definitely don't want to make any changes in this patch that are not directly required to achieve the goals.

Re-setting status to RTBC as testbot seems to be confused.

alexpott’s picture

I'm a bit concerned about backwards compatibility and this change.

  1. I think there might be considerable risks to sites that have made the base fields configurable
  2. +++ b/core/modules/node/node.module
    @@ -171,15 +171,6 @@ function node_theme() {
    -    'field__node__title' => [
    -      'base hook' => 'field',
    -    ],
    -    'field__node__uid' => [
    -      'base hook' => 'field',
    -    ],
    -    'field__node__created' => [
    -      'base hook' => 'field',
    -    ],
    

    Won't removing these affect existing sites?

  3. +++ b/core/modules/node/node.module
    index 91a97b3..0000000
    --- a/core/modules/node/templates/field--node--uid.html.twig
    

    If a site has overridden this will this patch break it?

adamps’s picture

@Alex Pott thanks very much for your time. The major part of the work here as been to do the best we possibly can for back-compatibility, but even so the result is not perfect. I don't know if you noticed, but we already have a CR that attempts to explain.

1. I think there might be considerable risks to sites that have made the base fields configurable

Yes I agree there is some risk in the sense that these sites may well need to make some changes to preserve existing appearance. Nevertheless I am proposing that we allow this change in a minor release for the following reasons:

  • The back-compatibility risk is only for sites that have made a fairly major customisation to implement this feature before it is officially available in Drupal core.
  • Such sites will discover many "bugs" or obstacles that make it very difficult to get a sensible result. For example there was a D8 alpha of the "title" module that was abandoned by the developer because he decided it wasn't possible to get useful behaviour without altering Core.
  • Hence I suspect there will be very few sites that are at risk - as far I can tell almost everybody is using the Display Suite module instead which works in a different way essentially reimplementing "Manage Display" in custom code.
  • A further balancing factor is that I suspect the sites at risk will also gain benefits. They likely haven't spotted some of the bugs that will be fixed by this patch - e.g. they are likely missing RDF metadata. Also they can likely stop maintaining various hacks or complex workarounds.
  • I don't believe it will be possible to bring this feature into core without the current level of risk, which we have worked hard to minimise.

2) Won't removing these [theme definitions in node_theme] affect existing sites?

I believe not.

  • In the early days of D8 there needed to be a hook_theme entry to pick up field--node--title.html.twig but that is no longer true - it gets picked up based on the theme suggestions. So that code has been unnecessary for a while.
  • If there is a hook_theme entry, Drupal mandates that the template exist, which is not what we want (it's present only in stable and only for back-compatibility), hence I had to remove the hook_theme entry.

3. If a site has overridden [field--node--uid.html.twig] will this patch break it?

No I believe it's fine. This patch should be fully BC for every site except for sites that have made base fields configurable.

However if a site has overridden certain templates, and also wants to take advantage of the function added by this feature, then the site will have to alter their templates to match the changes made in this patch. We have tried to explain this in detail in the CR.

adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new49.97 KB
new496 bytes

New patch fixes the coding standards error. The test failure looks like a glitch.

jonathanshaw’s picture

Status: Needs work » Reviewed & tested by the community

Agreed with #172. The CR discusses BC. There's no perfect solution, but this is likely the best we can do before D9.

adamps’s picture

As I understand it, the only BC concern is the calls to isDisplayConfigurable because it might affect sites that are already calling setDisplayConfigurable.

@alexpott If our responses have not relieved your concern then we do possibly have another option. Instead of the calls to isDisplayConfigurable there could be a separate new switch. I raised this in #124 and Berdir pointed out some flaws in #125 - here is an attempt to solve them.

The idea is there would be a setting "Entity preprocess migration" with values:

  1. ORIGINAL = same as current HEAD = pull certain base fields out of $content and perform extra processing.
  2. MANAGE_DISPLAY = same as patch when isDisplayConfigurable is TRUE = leave all base fields in $content to allow manage display.
  3. New levels might be introduced by later patches to D8.

Migration path

After this patch

  • D8 defaults to [1] which is fully BC, but does not support manage display of base fields.
  • Core does not support manage display of base fields, but modules/sites can enable it (use code to change the setting to [2]). There are no suitable Formatters in Core at this stage, so the module must provide them. Requires updates to templates if using custom theme.
  • D8 core templates are fully compatible with both [1] & [2].

After a later D8 patch that brings manage display into core

  • D8 defaults to [1], but provides a GUI option to switch to [2] - with a note to warn that the theme must support it (we could even add a mechanism for the theme to indicate support).
  • Core includes required Formatters.
  • D9 removes the setting and only supports [2] (or the final newest option if more were added).

    Comments anyone?

    jonathanshaw’s picture

    Yes, a setting is the "heavy artillery" of BC: it sure works, but it makes an ugly mess.

    I think we might be able to go a little further than you suggested:
    create an update hook, that tests if isDisplayConfigurable is enabled for any of the problem base fields; if it is, then and only then store the setting in the entity config; in the preprocess, test for the presence of the setting.

    This way existing sites that have messed with isDisplayConfigurable don't break, but everyone else gets the new goodness.

    kingdutch’s picture

    Issue tags: +Needs reroll

    The commit bc1b1fa8ce214478ecbf41004b545956d0101647 changes core/modules/system/templates/field.html.twig which prevents this patch from applying.

    jofitz’s picture

    Status: Reviewed & tested by the community » Needs review
    Issue tags: -Needs reroll
    StatusFileSize
    new49.99 KB

    Re-rolled.

    adamps’s picture

    Thanks @Jo Fitzgerald

    Clarification re Back-Compatibility: I believe the community consensus is in favor of the proposed patch #181 for the reasons explained in #172.

    The recent comments #178/#179 put forward two slightly different alternatives only in the case that the core committers are not convinced by #172. I don't propose to discuss the relative merits of each unless the core committers indicate that #172/#181 is not acceptable.

    jonathanshaw’s picture

    Status: Needs review » Reviewed & tested by the community

    In which case rtbc

    berdir’s picture

    1. +++ b/core/modules/aggregator/aggregator.theme.inc
      @@ -46,5 +46,8 @@ function template_preprocess_aggregator_feed(&$variables) {
           $variables['content'][$key] = $variables['elements'][$key];
         }
         $variables['full'] = $variables['elements']['#view_mode'] == 'full';
      -  $variables['title'] = $feed->label();
      +  // If the title field is not configurable, make it available separately.
      +  if (!$feed->getFieldDefinition('title')->isDisplayConfigurable('view')) {
      +    $variables['title'] = $feed->label();
      +  }
      

      This is still a very large patch. And in other places, we already focus on node to limit the scope.

      What about doing the same here and e.g. moving the aggregator parts (which are not tested for example) to a separate issue, maybe other things too?

    2. +++ b/core/modules/node/node.module
      @@ -608,16 +599,31 @@ function template_preprocess_node(&$variables) {
      +  if (!$node->getFieldDefinition('created')->isDisplayConfigurable('view')) {
      +    $variables['elements']['created']['#inline_field'] = TRUE;
      +    $variables['date'] = \Drupal::service('renderer')->render($variables['elements']['created']);
      +    unset($variables['elements']['created']);
      

      Similar here about the whole node field template changes and the #inline_field stuff.

      Is that really needed in *this* issue? Does it really block when those other templates still exist?

      BC goes in many directions, you also have to consider that people might be using themes with field templates that will not be considering that setting.

    3. +++ b/core/modules/node/node.module
      @@ -629,17 +635,22 @@ function template_preprocess_node(&$variables) {
      +  if (isset($variables['date']) && isset($variables['author_name'])) {
      +    $node_type = $node->type->entity;
      +    // Used by RDF to add attributes around the author and date submitted.
      +    $variables['author_attributes'] = new Attribute();
      

      As the comment says, this is used by rdf_preprocess_node() for example to add additional information to the template. This isn't really something that can be controlled by field UI and shows the general problem with BC on this.

      It's one thing for one site to make the fields configurable and configure it accordingly/update their templates. But it also needs to work in both cases with all core & contrib modules.

      Not sure what the best solution is, but I'm not convinced that this is sufficiently BC.

    4. +++ b/core/modules/rdf/rdf.module
      @@ -323,13 +323,22 @@ function rdf_preprocess_node(&$variables) {
         $created_mapping = $mapping->getPreparedFieldMapping('created');
      -  if (!empty($created_mapping) && $variables['display_submitted']) {
      +  // If 'created' display is not configurable then it is controlled by the
      +  // display_submitted setting. @see template_preprocess_node.
      +  $display_configurable = $variables['node']->getFieldDefinition('created')->isDisplayConfigurable('view');
      +  $display_created = $display_configurable ? isset($variables['elements']['created']) : $variables['display_submitted'];
      +  if (!empty($created_mapping) && $display_created) {
           $date_attributes = rdf_rdfa_attributes($created_mapping, $variables['node']->get('created')->first()->toArray());
           $rdf_metadata = [
      

      so you are changing rdf module accordingly. But that you need to change it also shows that this is technically a non-BC change and we can not know how this will affect contrib/custom modules.

    Thanks for all your work on this and I'd love to make progress on this issue, figuring out BC is really hard. You mentioned that this only affects sites that are calling setDisplayConfigurable() but I don't think that is true. Specifically the #inline_field stuff and all that refactoring does not seem necessary *and* will affect anyone.

    adamps’s picture

    @Berdir many thanks for your time and expertise for a detailed review. I've replied below, but it might be easier to cover some details via online chat/Skype then report back a summary to this issue - I'm very happy to do that if you wish.

    Yes it's a large patch, but I have been careful as I can to only change what needs to be changed to achieve the objective. I have read your arguments in detail, but nevertheless I stand by the current patch - i.e. I believe I have already considered the points you mention and it's fine, but the other possibility is that you are right and I am being dense failing to understand your point in which case please help me out. On the plus side the tests all pass and I have done extensive manual testing.

    Recap on BC promise

    A) Sites that don't call setDisplayConfigurable are unaffected. I will justify this claim below in specific cases you raise.
    B) Sites that already call setDisplayConfigurable may well be affected, but I propose that is deemed highly experimental as it basically doesn't work for a variety of reasons as per #172 etc, and the evidence of Google searching is that everyone who wants to manage title display is currently using Display Suite. However we could add a BC flag if core committers prefer with the obvious cost of making the code more complex/less clear.
    C) "Forward compatibility": sites that want to make use of this patch and start calling setDisplayConfigurable then this patch removes various obstacles in core. This patch is an important step but still just a step and other obstacles remain in core deferred to other issues, and of course in contrib. Sites must ensure the theme chosen has the template updates. As you say, there may be other contrib modules similar to RDF where hooks would need to be updated. This patch does not expose any way to enable setDisplayConfigurable, so these obstacles only affect sites that have very clearly opted in, and the sites will work much better with the patch than without. Once this patch is committed, the community can start to fix contrib modules and themes.

    Response to specific points

    1) I included aggregator for completeness but very happy to defer to a separate issue (but I'll wait for resolution on the other points before creating the new patch).

    2 & final paragraph)
    I absolutely understand where you are coming from - I implemented the #inline_field idea reluctantly after a considerable effort to find a better way and failing so I would be happy to hear of a better way. Without this part, we get invalid HTML and missing RDF metadata.

    The complications start from EntityViewController::buildTitle, see comment If the entity's label is rendered using a field formatter, set the rendered title field formatter as the page title instead of the default plain text title. This allows attributes set on the field to propagate correctly (e.g. RDFa, in-place editing). This leads to the field formatter output being emitted into the page wrapped in h1. Tags such as div and even worse h2 would not be valid in that context hence core contains templates such as field--node--title.html.twig that create non-standard inline output.

    I assumed that for BC I had to retain this concept, but it breaks with setDisplayConfigurable, because the title field must now be inline if used as page title but must not be if used as a normal field. The existing field-by-field approach is not so elegant because it leads to an identical inline template for each of 3 node fields, plus there ought to be at least one for other fieldable labelled entities (e.g. media is currently broken with div inside h1 but as you noticed I have deferred tackling that to a separate issue). Hence I created the generic 'inline field' concept.

    Specifically the #inline_field stuff and all that refactoring does not seem necessary *and* will affect anyone.

    Please can you describe a specific scenario that illustrates your claim it will affect anyone? I am aware that existing templates won't check inline_field but it doesn't matter so long as there is no call to setDisplayConfigurable (case A) - exactly as now the 'special fields' will all be used inline and the existing templates will emit inline markup.

    Even for setDisplayConfigurable (case C) I've done my best to help: search in the patch for This file exists to help back-compatibility in case a theme has overridden field.html.twig but not added a test for inline_field. and see code that provides the check on inline_field. That means that themes only need fixing if they override the specialist templates such as field--node--title.html.twig.

    3&4) I think this is covered by point C) above. This patch removes so obstacles in Core for sites that want to call setDisplayConfigurable. Yes most likely some contrib modules also need work to match what was done in RDF. However I can't see anything we can do in core to avoid that.

    adrian83’s picture

    Quick Question: Is this issue affected by the new Layout Builder exposing fields as blocks on the manage display page? If title is a block already on default and full view modes but uncontrollable on other view modes, and both blocks and fields will be placeable on Manage Display, does that change anything with this issue?

    adamps’s picture

    @Adrian83 I am not very knowledgeable on Layout Builder and I'm sure others following here know much more about it. My feeling is that Layout Builder is a separate, compatible strand which does not change the way we go about solving this issue.

    1) Presumably until this issue is solved, the title field won't even be present in manage display for Layout Builder to act on.

    2) A key element here is back-compatibility (BC) so we have to ensure that existing sites that don't use Layout Builder continue to work well without it.

    3) You have made an assumption that I have seen many people make: "full view mode" = "node is displayed on own page, hence put title field into title block". However I can see cases where that's not true

    • A teaser can be displayed on own page using node preview.
    • A view can be configured to display many nodes using full view mode hence not on own page.

    This suggests that the title block pulling in the title field is not directly related to view modes.

    adrian83’s picture

    @AdamPS Thank you for the explanation. Your assumption is what I also expect, though I haven't tested. For the record, I would love to see this issue fixed, because on almost every site I need to install Display Suite primarily to control the title on any view modes that are not the full view mode. The promise of view modes is only half realized in D8 because title appears first thing on all non-full display modes, which is almost never what I want.

    berdir’s picture

    Please can you describe a specific scenario that illustrates your claim it will affect anyone? I am aware that existing templates won't check inline_field but it doesn't matter so long as there is no call to setDisplayConfigurable (case A) - exactly as now the 'special fields' will all be used inline and the existing templates will emit inline markup.

    You are changing field.html.twig. You are adding a feature to it to tell it to render inline layout through a flag.

    If an existing theme does not implement that new option, then it will *not* render inline layout but a regular one. That means the logic in template_preprocess_node() will now no longer render an inline field template but a regular one.

    I had another look the patch and I see that there are fewer changes to the node specific templates than I thought before (it's hard to see what exactly is going on when just looking at the diff, easier when applied), so while you remove the templates from classy, you keep them in stable. So it still works for existing themes that extend from stable, even if they have a custom field template, but it does break themes that don't (you can do that by setting "base theme = false" in .info.yml) and have a field.html.twig. I tested it in our project and confirmed that this then ends up using the full field markup for the uid and created markup in the Submitted by.. text.

    So the #inline_change => TRUE case can break in two cases when themes have a field.html.twig:

    1. New usages of #inline_field => TRUE for other fields, which I think this issue does not yet add, but later issues will and other modules might start to use it as well
    2. For those themes that opt out of stable

    1. is probably OK if it's fixing bugs that can not otherwise be fixed like the entity title thing, but this doesn't actually fix those things yet, notde works because it does have its custom template now. 2. is technically also allowed I think (https://www.drupal.org/core/d8-bc-policy#themes), because we did define that themes that do not extend from stable are on their own, but the part I don't understand yet is why it is *necessary* to do it in this issue like this.

    he existing field-by-field approach is not so elegant because it leads to an identical inline template for each of 3 node fields

    Yes, it's not elegant. But BC and elegant usually don't go hand in hand, we often can't have both.

    So while this might be acceptable when strictly following our BC policy, we should try to limit even allowed BC changes to cases when it is really necessary. And yes, #2941208: Title formatting broken due to flawed EntityViewController->buildTitle I assume needs something like #inline_field, but unless I'm missing something, we can just add it there, without having to change all those node templates here. Adding it there to EntityViewController means as far as I see that the worst thing that can happen is that the bug will not be fixed in themes not respecting the new setting. So it's not getting better, but it is also not getting worse for them (At least not until modules start to rely more on that).

    Am I missing something in thinking that at least as far as node is concerned, the result would be the same if we don't do the #inline_field change and don't do any of those field template changes? And for now, only node field templates use #inline_field TRUE.

    Also, inline_field is currently not mentioned as something that themes should now consider in their field templates, if we decide to keep that change in here, then it should be put in either the existing CR or a separate one, or if we only introduce it in the follow-up, then one for it then.

    adamps’s picture

    @Berdir thanks again for your time and detailed explanations. In summary you have spotted a bug that hopefully I can fix, but I still support the overall approach used in the patch.

    I tested it in our project and confirmed that this then ends up using the full field markup for the uid and created markup in the Submitted by.. text.

    OK, I now see your scenario. This occurs if the theme opted out of stable and it doesn't implement field--node--created.html.twig. It looks like the code worked before my patch because it picked up core\modules\node\templates\field--node--created.html.twig which my latest patch removed. I'll take a look at that and see if I can put it back. However as you say there is a possible fallback "themes that do not extend from stable are on their own".

    Why we need inline_field

    Core already has the concept of an inline field. The node fields title, uid and created are rendered inline, using span and other simplifications to markup. All other fields are full (i.e. not inline). We definitely must correctly handle inline/full:

    • If a field should be inline, but is displayed full, that breaks alignment and generates illegal markup such as div inside h1.
    • If a field should be full, but is displayed inline, that misses some things off, in particular the label.
    • If a field is displayed the wrong way, the markup is different and CSS rules may fail to match.

    Once we enable manage display then the requirements change. The node fields uid and created should be rendered full. The title should be rendered full except on the node's own page where it is rendered inline. So the existing approach of hard-coding specific field templates to be inline no longer works - we need a system that adapts dynamically based on a variable: #inline_field.

    True, #inline_field will only ever be set to true for those specific 3 fields. Would it be sensible/feasible to add it to just those three templates? Not really because field--node--title.html.twig is a special case of field.twig so they share template_preprocess_field hence share the set of variables that will be available. I guess it would be possible to only comment the variable on the 3 specific templates, but that is potentially confusing. Looking forward to the future, we are likely to need #inline_field on other fields too. If we don't add it properly now, we are likely to force every theme to make some changes now and some more later.

    Why it works for BC

    (Aside from the bug you pointed out which hopefully I can fix.)

    I do agree that existing templates will ignore #inline_field. I don't see why it creates a problem. Suppose that my patch added the #inline_field variable but made no other changes. In that case, the existing field.twig would always get passed #inline_field=FALSE, ignore it, but nevertheless correctly output full markup. Similarly field--node--title.html.twig would always get passed #inline_field=TRUE, ignore it, but nevertheless correctly output inline markup.

    For any site that does not call setDisplayConfigurable, this is effectively what will happen, so it's perfectly safe for the existing templates to ignore #inline_field.

    adamps’s picture

    Status: Reviewed & tested by the community » Needs review
    StatusFileSize
    new51.32 KB
    new2.1 KB

    Here is a modified patch that I believe fixes the specific case that @Berdir hit in #189 by keeping a few more templates for BC.

    Version: 8.6.x-dev » 8.7.x-dev

    Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

    adamps’s picture

    Priority: Normal » Major

    Please can a community member (@jonathanshaw?) review the latest patch and set RTBC?

    OK so we have missed 8.6, so let's try really hard to get this in for 8.7. Setting priority to major as this issue has 40 followers, the parent issue has 111 and the D7 title module has 56,329 sites using it (of course many of these just want the translation but even so). The longer we wait, the more sites might have done workarounds and the greater the BC risk.

    I believe I have answered the comments from @Berdir (it would be great to have confirmation). I didn't yet remove the aggregator to put them in a separate issue because I admit I don't quite understand what that would achieve. If we are going to commit both anyway surely it's easier/clearer to do it all together and the IS, CR and patch are all ready for that. If we are not going to do aggregator ever then fine I can remove it, although it does seem a shame to leave it as the only inconsistency.

    berdir’s picture

    Adding the templates back helps, there's still at least one way where the behavior is changed. The templates now respect the #inline_field variable. That means until now, those 3 fields are *always* displayed inline if you render them, now you must provide that setting, otherwise they are no longer inline. If you wouldn't change EntityViewController in this patch then the title display would be broken. The same would happen to any call to rendering those fields themself.

    If you would ignore that variable in those templates and instead always call the inline template, then that's another thing less that could possibly break. That said, I still really don't understand why that variable/concept must be introduced in this issue, it still just seems like a refactoring that isn't strictly required to achieve the goal of this issue. But I'm going to leave the decision to the maintainers whether we should include that or not.

    > I believe I have answered the comments from @Berdir (it would be great to have confirmation). I didn't yet remove the aggregator to put them in a separate issue because I admit I don't quite understand what that would achieve. If we are going to commit both anyway surely it's easier/clearer to do it all together and the IS, CR and patch are all ready for that. If we are not going to do aggregator ever then fine I can remove it, although it does seem a shame to leave it as the only inconsistency.

    http://www.webchick.net/please-stop-eating-baby-kittens explains that well. Every small change that doesn't absolutely belong distracts and makes it harder to review and understand a patch.

    I know very well it's hard to do on your own patch. I had the same recently in #2960253: [meta] Allow Paragraphs widget/field and similar use cases to to be considered translatable where I tried to get 3 different changes (that were all necessary to achieve what I needed) and I initially argued against splitting it up, but we eventually agreed on it and we did manage to get all 3 changes committed in 8.6 because each issue on its own was easier to review and agree upon.

    adamps’s picture

    Thanks again Berdir. OK here is a patch without aggregator.

    adamps’s picture

    Status: Needs work » Needs review
    StatusFileSize
    new30.66 KB
    new16.7 KB

    Darn, the umami files have changed. I'll come back to that. Here is a patch that takes out inline-field. Notice that I had to compromise in NodeDisplayConfigurableTest:

    • missing field label
    • missing rel="schema:author"
    • wrapper is a span unlike other fields which are div, so CSS rules might not match as expected

    I set it to test against 8.6.x else the patch would fail to apply again - that's to get a record of how the patch looks and save an interdiff before adding in the complication of refactoring for umami.

    adamps’s picture

    Status: Needs work » Needs review
    StatusFileSize
    new28.54 KB

    Reroll, same as #197: without inline-field, without aggregator
    (Sorry no interdiff - my tool fails to apply the patches)

    adamps’s picture

    Reroll of #195: with inline-field, without aggregator

    This is a more complex patch but fixes the problems listed in #197:

    • missing field label
    • missing rel="schema:author"
    • wrapper is a span unlike other fields which are div, so CSS rules might not match as expected
    oriol_e9g’s picture

    If #199 it's not including inline-field, why we need to set this vars?

    $variables['elements']['created']['#inline_field'] = TRUE;
    ...
    $variables['elements']['uid']['#inline_field'] = TRUE;
    ...
    $variables['elements']['title']['#inline_field'] = TRUE;
    

    I think this could be removed.

    adamps’s picture

    If #199 it's not including inline-field, why we need to set this vars?

    @oriol_e9g Well spotted - those three lines shouldn't be there, I'll fix that.

    jonathanshaw’s picture

    Thanks for your patience with this @AdamPS.

    I think we need to move the taxonomy changes out of the patch, in the same way you have aggregator. I'm fairly sure @Berdir intended aggregator as an example of something distracting, not something that caused a particular problem.

    +++ b/core/modules/rdf/rdf.module
    @@ -323,13 +323,22 @@ function rdf_preprocess_node(&$variables) {
    -    $variables['metadata'] = \Drupal::service('renderer')->render($rdf_metadata);
    +    if ($display_configurable) {
    +      $variables['title_suffix']['rdf_meta_created'] = $rdf_metadata;
    +    }
    +    else {
    +      $variables['metadata'] = \Drupal::service('renderer')->render($rdf_metadata);
    +    }
    +    }
    

    This would benefit from a comment explaining why 'title_suffix' vs 'metadata? It's a bit of a WTF.

    This is a more complex patch but fixes the problems listed in #197:
    missing field label
    missing rel="schema:author"
    wrapper is a span unlike other fields which are div, so CSS rules might not match as expected

    Do we cause these problems by our other work in this issue? Is there anyone who currently doesn't experience these problems who will immediately experience them if this patch is committed? If not we should push them into a follow-up in order to simplify this as much as possible. I see the real challenge for this issue is building consensus on how to address the BC concerns caused by what we're doing in template_preprocess_node; maybe everything work perfectly when isDisplayConfigurable is set can be follow-up stuff.

    AlexPott's had a BC concern "I think there might be considerable risks to sites that have made the base fields configurable". In light of this it would be good if we could document more exactly in the IS & CR in what circumstances someone could be affected.

    I believe it is if they have made a base field configurable and:
    1) they made it configurable in order to use a different formatter on the title, author name or date, but still wanted them to appear only at a template-hardcoded location.
    2) they made it configurable and wanted the field to appear twice, once in the configured location amidst content fields, and once in a template-hardcoded location.
    3) they use twig coding in the template to add the field back into the twig content array in a specific position
    4) is there a hook to alter the output of template_preprocess_node before it gets to the template? Someone using that to work round the could be affected.
    5) they did any kind of conditional processing in a custom template based on values of the label, author_name and date variables
    Anything else?

    adamps’s picture

    Status: Needs work » Needs review
    StatusFileSize
    new25.9 KB
    new3.91 KB

    Do we cause these problems by our other work in this issue? Is there anyone who currently doesn't experience these problems who will immediately experience them if this patch is committed? If not we should push them into a follow-up in order to simplify this as much as possible.

    No and no - so let's push it to a follow-up.

    OK here is a new patch

    • Remove taxonomy
    • Add comment requested in #204
    • Remove unwanted lines spotted in #201
    adamps’s picture

    In light of this it would be good if we could document more exactly in the IS & CR in what circumstances someone could be affected.

    I don't think with the list you are being more exact. I think you are being more detailed yes, but it will become less exact, because I doubt it will be possible to think of every strange piece of code that someone could have written that might be affected.

    I feel that all we can safely say is that any site that already calls isDisplayConfigurable may be affected. However this is not an option that's available via the GUI or documented/recommended. See #172 and as explained in the IS, currently calling isDisplayConfigurable does not actually make the display configurable, but rather leads to a strange partly-broken result. So my question is, do we really have an obligation to keep the broken behavior working?

    I see two options:

    1. As current code: use isDisplayConfigurable to trigger the new behavior. Sites that already call isDisplayConfigurable are potentially affected.
    2. Use an entirely new flag/function to trigger the new behavior such as #178. It's clean for BC, but messier going forwards.

    How about if we stick with option 1) for now and get a response from committers to the new much simplified patch?

    jonathanshaw’s picture

    Status: Needs review » Reviewed & tested by the community

    All good with me. I'm RTBCing because we need to get approval in principle from a committer.

    Before actual commit we need to change IS & CR and create follow-ups.

    adamps’s picture

    OK, I have mostly convinced myself that we should change the patch to eliminate the BC problems here and in the follow on inline field issue.

    Recap of intent of this issue

    Drupal core contains some template preprocessing of base fields based on certain assumptions about the template files. In fact this processing is not always wanted and can present problems, so we need a way to disable it.

    Current approach

    The current patch disables processing if the field is display configurable. This makes an assumption that might be right 90% of the time, but it's possible to imagine counter examples.

    1. A site might enable manage display of authored on to let the admin configure field display options - for example to change the date format. However the template is the same as core, and preprocessing is required. The site accepts the limitation that changing the display order of authored on has no effect. This would be a BC break.
    2. A site might want to alter the formatters (using code) and templates to give a completely different display of the base fields, hence would like to disable the preprocessing. However the site has manage display disabled. This is not BC - but it is an example where it could be useful to disable processing without altering manage display.

    Proposed approach

    Instead we can make it really simple - we add a new option to enable/disable the base field preprocessing. This isn't a "BC-hack" - the option would be available for the rest of D8 (with the intention that the preprocessing option be removed in D9). This patch would not expose a GUI for the option.

    In #125 @Berdir said

    The downside of a single variable is that we can never add something else to the list of deprecated variables.

    True - but I think we now know every case of base field preprocessing and can fix them all, so it should be fine. Yes we would need to bring taxonomy and aggregator back into the same patch.

    Code snippet

      if (theme_get_setting('base_field_preprocess')) {
        // Make created, uid and title fields available separately.
        // @todo In D9 delete this code and matching template lines. Using
        // $variables['content'] is more flexible and consistent.
        $variables['date'] = \Drupal::service('renderer')->render($variables['elements']['created']);
        unset($variables['elements']['created']);
    
        $variables['author_name'] = \Drupal::service('renderer')->render($variables['elements']['uid']);
        unset($variables['elements']['uid']);
    
        $variables['label'] = $variables['elements']['title'];
        unset($variables['elements']['title']);
      }
    

    We need base_field_preprocess to default to TRUE which might need an upgrade hook for existing sites.

    To me it seems simpler code that is guaranteed safe for BC. It also makes very clear which parts are deprecated (everything relating to base_field_preprocess). What does anyone else think?

    jonathanshaw’s picture

    Status: Reviewed & tested by the community » Needs review

    if (theme_get_setting('base_field_preprocess')) {

    We need base_field_preprocess to default to TRUE which might need an upgrade hook for existing sites.

    We'd also need an upgrade hook test, which is not a picnic. It'd be much easier to just avoid all this:
    if (theme_get_setting('base_field_preprocess') !== FALSE) {

    The downside of a single variable is that we can never add something else to the list of deprecated variables.

    True - but I think we now know every case of base field preprocessing and can fix them all, so it should be fine. Yes we would need to bring taxonomy and aggregator back into the same patch.

    You can avoid both issues if we have separate variables for each field:

        // Make created, uid and title fields available separately.
        // @todo In D9 delete this code and matching template lines. Using
        // $variables['content'] is more flexible and consistent.
    
      if (theme_get_setting('preprocess_node_created') !== FALSE) {
        $variables['date'] = \Drupal::service('renderer')->render($variables['elements']['created']);
        unset($variables['elements']['created']);
      }
    
      if (theme_get_setting('preprocess_node_uid') !== FALSE) {
        $variables['author_name'] = \Drupal::service('renderer')->render($variables['elements']['uid']);
        unset($variables['elements']['uid']);
      }

    What I like about your proposal @AdamPS (and even more with these modifications) is that it seems simple and unobjectionable, a much easier thing to get reviewed and agreed.

    adamps’s picture

    Good suggestions @jonathanshaw

    We'd also need an upgrade hook test, which is not a picnic. It'd be much easier to just avoid all this:

    I agree. However I'm not sure how much I like node_base_field_preprocess having the semantics
    NULL => Yes
    false => No
    true => Yes

    It looks like a boolean, but it isn't. We could instead have skip_node_base_field_preprocess, and then it works like a proper bool.

    @Berdir - can you spot any problems or shall I make a new patch along these lines?

    jonathanshaw’s picture

    @AdamPs, agreed your semantics are probably better.
    I'd suggest bypass_preprocess_node_fieldname or preprocess_bypass_node_fieldname or node_fieldname_bypass_preprocess (I think 'bypass' is a little more frequently used in core, skip is slightly more informal English?)

    adamps’s picture

    Here is a patch that implements #208-#211.

    Detailed notes:

    1. Rather than one option per field I have one option per entity type. That seems simpler and avoids the problem of what to do if the per-field setting is different for 'created' and 'uid'.
    2. Now that we have a new setting and BC is therefore not the same problem, I have taken the opportunity to hide $form['display']['display_submitted'] in cases when it has no effect.

    We can still go back to #205 if the experts prefer it. I've not yet updated the IS or CR, but I think they become simpler with the new patch.

    adamps’s picture

    OK, I think I have a new better approach, and finally I can see a possible whole "road map" for manage display in core.

    The overall goal is to have a setting in the Drupal GUI to turn on manage display of base fields. Of course there would be an underlying config setting to record the chosen setting. So we don't really want another similar (but less easy to understand) config setting for "bypass preprocess". Why don't we instead create the proper manage display config setting now? Here is a patch that does that.

    Roadmap

    In this issue:

    • Create config setting for "manage display of node base fields"
    • Fix proprocess functions and templates to work with it

    In other issues:

    • Do the same for other entity types
    • Handle "inline field" problems and other bugs split to separate issues
    • Add the field formatters to core
    • Create a GUI for the new manage display settings
    adamps’s picture

    Issue summary: View changes
    Status: Needs work » Needs review
    StatusFileSize
    new30.38 KB
    new328 bytes

    Sorry bad patch - try again.

    Also I have updated the IS.

    jonathanshaw’s picture

    I'm not qualified to offer an opinion

    adamps’s picture

    Title: Field rendering should respect configurable field display » Framework for manage display of node base fields

    Fix title

    adamps’s picture

    I'm feeling quite optimistic that this new approach gives a sequence of simple BC steps to the goal of manage display in Core GUI. I've created issues for all the parts that we have split out and updated the parent META issue #2353867: [META] Expose Title and other base fields in Manage Display.

    @jonathanshaw Even if you feel uncertain of the wider implications, I would very much value your opinion seeing as you have been following this issue closely.

    • Do you feel this approach will work, with the benefits I have in mind?
    • Do you see any major problems?
    • If it's broadly OK, if possible please could you provide a detailed code review with aim of getting back to RTBC?
    adamps’s picture

    Status: Needs review » Reviewed & tested by the community
    Issue tags: +review

    This issue needs guidance please from a core committer/maintainer/expert to direct us to one of three open approaches. Setting to RTBC to request this. In fact 2 of the approaches are RTBC, the third is only "needs review" - if anyone can provide a community review of option 3 that would be very useful please.

    Three options:

    1. title.display-2923701-205.patch is RTBC. However it has some possible BC concerns that might affect a small percentage of sites (where there is already call to setDisplayConfigurable).
    2. title.display-2923701-212.patch is RTBC. It is fully BC based on a new theme_get_setting('bypass_base_preprocess.node');. The downside is that we would presumably eventually want to have an option in Drupal Core GUI to enable manage display and that would mean a second new setting.
    3. title.display-2923701-215.patch is "Needs review". It is fully BC based on a new setting \Drupal::config('system.theme')->get('manage_base_field_display.node');. When we eventually have an option in Drupal Core GUI, it should be possible to use the new setting.

    Currently I favor option 3 as it is fully BC and seems directly aligned towards the longer term goal to have a manage display option in Drupal Core GUI.

    adamps’s picture

    Issue tags: -review
    jonathanshaw’s picture

    Sorry for not replying Adam, I ran out of steam with it.

    adamps’s picture

    Title: Framework for manage display of node base fields » Mechanism to disable preprocessing of node base fields so they can be used in "Manage Display"
    Issue summary: View changes
    Status: Reviewed & tested by the community » Needs review
    Issue tags: +Contributed project blocker
    StatusFileSize
    new25.8 KB
    new3.68 KB

    OK I think we are so close, I will keep working to find the patch that has no disadvantages. The only uncertain part of the patch is how we enable/disable the special preprocessing of base fields.

    #215 created a new setting in the expectation it could eventually be used in the core GUI. As @Berdir says, I should keep each issue to the minimum. We should leave the eventual GUI and it's associated settings to the next issue.

    #212 created a per-theme setting. That's not really right as manage display settings as shared for every theme. Plus we don't want to make a setting and force the eventual GUI to make another setting.

    This new patch uses an additional property on the node entity type. There is no new setting. When we eventually make a setting/GUI in core, we can add code to automatically set the property. Any module that wants to disable the processing needs this code.

    function XXX_entity_type_build(array &$entity_types) {
      $entity_types['node']->set('bypass_base_preprocess', TRUE);
    }
    

    It's very similar to writing code that calls setDisplayConfigurable().

    The interdiff from #212 is now very small and simple. I would be very grateful if someone can set to RTBC.

    jonathanshaw’s picture

    the eventual GUI

    I'm not sure there is one. Dries' recent blog post points to D9 in 2020. And for D9 we will want to default setDisplayConfigurable to TRUE and remove this legacy preprocess code altogether.

    #212 created a per-theme setting. That's not really right as manage display settings as shared for every theme.

    I'm not sure that's necessarily a valid objection. It's only a problem if we knew we wanted to create a site wide GUI. But I'm not sure we need a GUI, and the per-theme settings GUI is a good enough place for it form my point of view. Whether you want to bypass this preprocess or not depends on what you're doing in your theme templates.

    Here's my current thinking:

    we should make it so that a site that (a) is a fresh 8.7+ install and (b) uses custom code to setDisplayConfigurable(TRUE) works perfectly, as if it were D9 already.

    This requires that (a) whatever it is we check in the preprocess, it's something that defaults to passing on a clean install, and (b) we don't omit to also test isDisplayConfigurable().

    Does this make sense as the goal?

    adamps’s picture

    OK I've read your arguments, but I still have the same opinion as before. Let's see if I can explain why.

    Dries' recent blog post points to D9 in 2020

    OK but:

    1. Actual releases tend to be later than their far-advanced prediction.
    2. Mainstream adoption of a major new version lags well behind the core release waiting for the main contrib modules are all ported - after all, here we are 3 years after D8 initial release still waiting to get a replacement for the D7 title module.
    3. D8 sites are still supported until D10 is released.

    Therefore I feel that whatever work we do on D8 has substantial value. We should not just give up, but the opposite: do as much as we can as soon as we can, subject to high standards of quality. The work we do in D8 likely helps D9 anyway. It would be nice to make substantial progress in 8.7.

    I'm not sure we need a GUI

    I think many people want a GUI and it's exactly what the parent issue calls for. Potentially people will be happy for the GUI to be in a contrib module, but core would be the ideal.

    Whether you want to bypass this preprocess or not depends on what you're doing in your theme templates

    As per the previous point, the principal motivation is to allow manage display in GUI, ideally core, or at least contrib. Calling setDisplayConfigurable is not-per theme and "Manage display" settings are not per theme. Hence the underlying code to disable preprocessing of base fields needs to work whatever the theme.

    If I understand correctly, you suggest a possible secondary motivation to allow one site to use multiple themes and for those themes to make different choices about preprocessing base fields. However, as you said yourself, the preprocessing will be removed in D9. All we need here is a simple mechanism to handle back-compatibility. I don't think we want to introduce new complex mixed use cases on top of something that is already deprecated.

    We should make it so that a site that (a) is a fresh 8.7+ install and (b) uses custom code to setDisplayConfigurable(TRUE) works perfectly, as if it were D9 already.

    Well it sounds nice, but that's tricky in several ways.

    1. We can't be sure how D9 will behave.
    2. setDisplayConfigurable is a per-field setting, so what about if a site calls it for just some fields (in particular 'created' but not 'uid')?
    3. Assuming we want 100% BC for 8.6- installs, I believe your goal would require a) a config setting "legacy mode" that has no GUI and defaults to FALSE and b) an D8.7 upgrade_hook that sets it to TRUE. As you pointed out in #209, this is not a picnic.
    4. I don't entirely like the idea that the Drupal core behavior varies so radically based merely on when the site was installed. Is there a precedent for that? Suppose I have a custom module that calls setDisplayConfigurable and a site using it on D8.6. It works well and, later on after D8.7 has been released, I create a second similar site and use the same module. Mysteriously it doesn't work in a way that can't be detected or fixed in the GUI.

    In summary, I think that the current patch is simple and clear. True it's one extra call, a site that calls setDisplayConfigurable also must call set('bypass_base_preprocess', TRUE); but it's not so hard, and that would normally be done by the contrib module or even core anyway. In comparison, the goal turns out to be trickier.

    ========

    Next step: either I haven't convinced you, in which case we debate further, maybe even chat offline. Or if I have, it would be great if you could review the patch.

    jonathanshaw’s picture

    Assuming we want 100% BC for 8.6- installs, I believe your goal would require a) a config setting "legacy mode" that has no GUI and defaults to FALSE and b) an D8.7 upgrade_hook that sets it to TRUE. As you pointed out in #209, this is not a picnic.

    I was worried that might be the case. I was wondering if the theme setting approach from #212 delivers this without the update hassle; I don't understand theme settings enough to know.

    jonathanshaw’s picture

    Status: Needs review » Reviewed & tested by the community

    I'm coming round to the idea that #222 is a good approach. It creates a crude switch for developers wanting to bypass the problematic code in the preprocess function.

    And that's all we need; in D9 we remove the problem code from the preprocess altogether, but for now with this patch anyone who wants to bypass it can.

    RTBCing to seek approval of the solution in principle; the tests need revision if this is the approach we settle on.

    adamps’s picture

    @jonathanshaw Excellent, thank you.

    I have updated the CR to match the latest patch - please review and improve as required.

    the tests need revision if this is the approach we settle on.

    Please can you explain what revision to tests is required? I already added hook_entity_type_build() to node_display_configurable_test.module and the tests all pass.

    jonathanshaw’s picture

    You're right, I only glanced before but the test itself is OK. But ....

    +++ b/core/modules/node/tests/modules/node_display_configurable_test/node_display_configurable_test.info.yml
    @@ -0,0 +1,6 @@
    +description: 'Support module for node setDisplayConfigurable testing.'
    
    +++ b/core/modules/node/tests/modules/node_display_configurable_test/node_display_configurable_test.module
    @@ -0,0 +1,26 @@
    + * A dummy module for testing node setDisplayConfigurable.
    
    +++ b/core/modules/node/tests/src/Functional/NodeDisplayConfigurableTest.php
    @@ -0,0 +1,74 @@
    + * Tests setDisplayConfigurable.
    ...
    +    // Enable module to setDisplayConfigurable.
    

    All these comments refer to the previous approach and are misleading now.

    adamps’s picture

    Status: Reviewed & tested by the community » Needs review
    StatusFileSize
    new26.01 KB
    new1.77 KB

    All these comments refer to the previous approach and are misleading now.

    Is it really so bad? Basically this a test to set base fields to configurable display using setDisplayConfigurable and then check that the chosen output is respected.

    I agree that as an implementation detail, node_display_configurable_test also has to set bypass_base_preprocess. However I feel that the comments regarding the primary purpose of the test are still accurate. The same module and test file will continue to be used and enhanced for the other issues that we split off.

    However I can flesh out some of the detailed comments, so here is a new patch that does that. Also I have fixed the comment "Tests the html head links" which presumably was a block-copy error!

    jonathanshaw’s picture

    Status: Needs review » Reviewed & tested by the community

    Fair enough.

    adamps’s picture

    Thanks @jonathanshaw.

    To the core committer - hopefully this is the patch that you can commit without reservation, thanks!

    • The BC concerns have been resolved: changes only occur if a new setting is enabled.
    • This issue has been reduced to achieve a single clear target, with further steps split to follow on issues.
    • This issue is the first step in a clear strategy moving forwards towards "manage display GUI in Drupal code", see the parent issue #2353867: [META] Expose Title and other base fields in Manage Display.
    • We have well-defined 'deprecated' areas of code scheduled for removal in D9.
    larowlan’s picture

    Status: Reviewed & tested by the community » Needs review

    This is looking good, is there a reason why we only did node though? Should we be doing comment, taxonomy term etc in the same patch?

    1. +++ b/core/modules/node/node.module
      @@ -608,16 +608,24 @@ function template_preprocess_node(&$variables) {
      +    unset($variables['elements']['created']);
      ...
      +    unset($variables['elements']['uid']);
      ...
      +    unset($variables['elements']['title']);
      

      As I see it (correct me if I'm wrong) but the main issue is with these unsets. Is there any harm in leaving the new variables (date, label etc) around even if we have the display configured fields?

      That way we don't need to mark the fields as optional and themers can depend on them being present if they need them.

      We would have to do something about the new label conditional in the template though.

    2. +++ b/core/modules/node/tests/modules/node_display_configurable_test/node_display_configurable_test.module
      @@ -0,0 +1,27 @@
      + * A dummy module for testing setDisplayConfigurable on node base fields.
      

      nit: its a test module, not a dummy module

    3. +++ b/core/modules/node/tests/modules/node_display_configurable_test/node_display_configurable_test.module
      @@ -0,0 +1,27 @@
      +  $entity_types['node']->set('bypass_base_preprocess', TRUE);
      

      This is a good approach, but I think we need somewhere to document it, at present it lacks discoverability.

    4. +++ b/core/modules/node/tests/src/Functional/NodeDisplayConfigurableTest.php
      @@ -0,0 +1,76 @@
      +   * Set base fields to configurable display using
      +   * <code>setDisplayConfigurable

      and then check that the chosen output
      + * is respected.

      this violates our coding standards, should be a short summary (<80 chars) and then an additional comment if required.

    adamps’s picture

    Status: Needs review » Needs work

    Thanks @larowlan.

    Should we be doing comment, taxonomy term etc in the same patch?

    The patch had got big and people were finding it hard to review/understand, so based on @Berdir suggestion we split it out into multiple issues. See #2993642: Mechanism to disable preprocessing of base fields in taxonomy and aggregator entity types so they can be configured via the field UI. As soon as this issue is committed, I will put a matching patch for the other issue.

    1)

    the main issue is with these unsets. Is there any harm in leaving the new variables (date, label etc) around even if we have the display configured fields?

    Yes unfortunately there is. The call to render marks the field as rendered, which means if you try to render it a second time it outputs nothing.

    2) +1 I will fix

    3)

    we need somewhere to document it, at present it lacks discoverability.

    Do you have any idea where/how we could document this? In the long term, the goal is to have a GUI in core; in the short term there is a GUI in contrib module manage_display.

    4) +1 I will fix

    adamps’s picture

    Status: Needs work » Needs review
    StatusFileSize
    new25.94 KB
    new1.37 KB

    New patch fixing comments in #232.

    In terms of documentation, we have the change notice. I guess we could also make a page on https://www.drupal.org/docs/8.

    adamps’s picture

    Status: Needs work » Needs review
    StatusFileSize
    new25.94 KB
    new1.66 KB

    Fix deprecated functions

    berdir’s picture

    > Yes unfortunately there is. The call to render marks the field as rendered, which means if you try to render it a second time it outputs nothing.

    Not 100% sure right now we even can/want to keep them, but what if we still assign it, but as a render array and stop trying to render it early? Alternatively, copy the array into a new variable before rendering it, so it is not passed in by-reference.

    adamps’s picture

    I propose that each field be passed in at most one place. This allows a core template to be written with both code for preprocessing and code without and only one of them will actually display.

    • Copying the array would indeed bypass the code the prevents a field from being displayed twice, but I the field would then be displayed twice:-)
    • Passing a render array would be non-BC and I think it breaks because in the template the author info is wrapped in {% trans %}

    It would be great if someone could set this back to RTBC

    jonathanshaw’s picture

    Status: Needs review » Reviewed & tested by the community

    #232

    As I see it (correct me if I'm wrong) but the main issue is with these unsets. Is there any harm in leaving the new variables (date, label etc) around even if we have the display configured fields?

    @larowlan's right that the main issue is with the unsets, they're what must be bypassed.
    @AdamPS is right to point out that you can't print the same variable twice
    @berdir's right that we could copy the array to prevent calls to {{label}} from suppressing subsequent {{content.title}}

    I think the most important point here is that
    1) we ultimately want to remove {{label}} and friends one day. They're legacy variables that will always have an awkward relationship with the layout UI.
    2) Making these variables optionals is a problem for no one. People making contrib themes need to be aware of the emerging possibility of managing the title as a normal variable and allow for that in their theme. People doing a theme for a single site will either keep using label happily, or deliberately opt in and change their templates to not use it. It's possible we should add to the comment on label with a link to a CR explaining the circumstances is which label is present/absent.

    But the bigger problem is already forseen by @larowlan:

    #232

    We would have to do something about the new label conditional in the template though.

    {% if label and not page %}
    Obviously if label is no longer optional this conditional will always pass.

    One option is to add a new 'bypassed_preprocess' variable into the template.
    {% if bypassed_preprocess and not page %}
    The increase in complexity doesn't seem worth it to me, it feels horrid.

    Another option is something like
    {% if not content.title is defined and not page %}
    I think this might break BC for people who were using a custom preprocess to add a title variable back into the main content array, without touching their template, and wanted the title to print twice. But there's so many things these people could hypothetically be doing that there's almost no way to make any change that doesn't risk a break for someone somewhere....

    jonathanshaw’s picture

    Status: Reviewed & tested by the community » Needs review
    adamps’s picture

    But there's so many things these people could hypothetically be doing that there's almost no way to make any change that doesn't risk a break for someone somewhere....

    Sorry I don't agree. After many iterations we have carefully restructured this patch in a way that is 100% BC. Nothing is going to break.

    We are creating a new mechanism, and yes I agree, sites that opt in to the mechanism will have to follow the way that it works. Sites that set bypass_base_preprocess may have to adjust their templates, but this is impossible to avoid. With most of the core templates, the consequences of failing to adjust the template are small - an empty h2.

    We are following a completely natural path here: label becomes optional with this change, and then perhaps in D9 we can retire label entirely. The template adjustments are minimal and intuitive.

    The alternative is to set label and then the template uses some other mechanism controls when to ignore the label. Then a site that fails to adjust the template would have a duplicate title, which seems worse. Furthermore there is additional complexity and increased difficulty to eventually simplify.

    I agree we need to document what we are doing clearly and carefully. However we have now split everything into many many issues so this issue is far from the complete solution. I think we need to see the whole picture before we can document it. I have raised #3011017: Document manage display of base fields and marked it as postponed.

    adamps’s picture

    Advance warning: I will be taking a break from Drupal.org for December and January.

    Please, please can we try and get this issue in before that?

    There has been a huge amount of work by the community with over 50 patches and 100s of hours of unpaid work. Likely thousands of users would like to have this function, available in D7 in the hugely popular title module. Seeing as we have split everything out, there are multiple follow-on issues before we have a fully working solution that are currently blocked.

    The patch is 100% BC and there is a contrib module Manage Display that proves it does achieve the desired end goal.

    The latest patch changed two comments in response to #232, and I believe we have answered the other points raised there.

    Next step: please can someone confirm the comments are OK then set RTBC?

    jonathanshaw’s picture

    100% BC. Nothing is going to break.

    I'm not sure that can be guaranteed. Core's node template relies on the variables having the meanings given to them in core's node preprocess. If someone uses their own preprocess function to mess with the meanings of the variables, without changing the template, then any change we make to the preprocess or the template cannot be guaranteed to not break. My point was that this is a hypothetical risk that has no absolute mitigation and should be ignored, we don't need to discuss it more. Core offers no BC guarantee for render arrays.

    You haven't actually addressed #239: is there a reason to prefer

    {{ if label and not page }}

    instead of something along the lines of

    {% if not content.title is defined and not page %}
    ?

    The latter would allow us to not have to change #label to optional, which @larowlan was interested in.

    adamps’s picture

    Any change we make to the preprocess or the template cannot be guaranteed to not break. My point was that this is a hypothetical risk that has no absolute mitigation and should be ignored, we don't need to discuss it more

    OK fine - but just in case anyone is worrying, I will re-emphasize that we don't change the preprocess result unless a site has opted in by setting a new option bypass_base_preprocess, so the render array is actually BC. The templates have changed, but only to suppress printing of an empty label and it's hard to see how that could be bad.

    The latter would allow us to not have to change #label to optional, which @larowlan was interested in.

    I don't think it would really. The label is optional either way in the sense that it might be blank. What you are doing is to alter the way of testing whether label is blank.

    {{ if label and not page }}
    

    This seems clearly superior because it directly tests whether the label is present in a clear and obvious way.

    {% if not content.title is defined and not page %}
    

    Now we are testing a secondary variable content.title that we believe has a relationship to label. However if people write a custom preprocess function that belief might turn out to be false. This way is a potential BC break because if a site has set the content.title variable for some unrelated reason then their title will disappear.

    jonathanshaw’s picture

    Status: Needs review » Reviewed & tested by the community

    So we've considered what @larowlan asked us to

    adamps’s picture

    We seem to have consensus for the approach here, so I have created a matching patch for #2993642: Mechanism to disable preprocessing of base fields in taxonomy and aggregator entity types so they can be configured via the field UI. Please can someone review it?

    alexpott’s picture

    +++ b/core/modules/node/node.module
    @@ -609,16 +609,24 @@ function template_preprocess_node(&$variables) {
    +  $preprocess = !$node->getEntityType()->get('bypass_base_preprocess');
    

    This needs documenting somewhere. Not sure where though. Also I think documenting it will reveal a flaw in the naming. I.e. if it did what it implies it did I would expect the code to look something like:

    function template_preprocess_node(&$variables) {
      if ($variables['elements']['#node']->getEntityType()->get('bypass_base_preprocess')) {
        return;
      }
    

    But the thing is it is a partial bypass. I think the name needs to reflect what it is really doing. It is extremely specific to nodes and only certain things it adds. I'm also not sure why we don't check whether the fields have a configurable display in the preprocess function. Ie. why is the bypass_base_preprocess thing necessary?

    alexpott’s picture

    Status: Reviewed & tested by the community » Needs review

    Back to needs review to get an answer to #247

    jonathanshaw’s picture

    I'm also not sure why we don't check whether the fields have a configurable display in the preprocess function. Ie. why is the bypass_base_preprocess thing necessary?

    That was our first approach and it is more elegant. However, it is potentially disruptive for anyone who has previously made these fields configurable but still expected the current preprocess behaviour.

    We changed to the bypass approach in response to your feedback [#171.1].

    alexpott’s picture

    @jonathanshaw - ok that makes sense. So I still think we need a better name that reflects what this is doing and there needs to be documentation beyond a change record.

    adamps’s picture

    Naming

    But the thing is it is a partial bypass. I think the name needs to reflect what it is really doing. It is extremely specific to nodes and only certain things it adds.

    Yes it is a partial bypass - it bypasses preprocessing of base fields, but not of other fields. This distinction is made clear by the name bypass_base_preprocess. Please let me know if you have an idea for a better name.

    Yes it is specific to nodes, because the option is set on the node entity. The same option is available on some other entity types as part of #2993642: Mechanism to disable preprocessing of base fields in taxonomy and aggregator entity types so they can be configured via the field UI. This allows developers to choose separately for each entity type:

    /**
     * Implements hook_entity_type_build().
     */
    function manage_display_entity_type_build(array &$entity_types) {
      $entity_types['node']->set('bypass_base_preprocess', TRUE);
      //$entity_types['taxonomy_term']->set('bypass_base_preprocess', TRUE);
    }
    

    Documentation

    We have split the overall problem into multiple sub-issues (see #2353867: [META] Expose Title and other base fields in Manage Display) to make it easier to commit. That means there is a series of other issues blocked waiting for this one. Therefore it would be a huge help if you could commit this fix now, and we can follow up with documentation later. I give you my firm promise that I will write some documentation in time for the release of 8.7.x.

    For the documentation part I have raised #3011017: Document manage display of base fields and marked it as postponed because:

    • This issue alone leaves a buggy and partial solution and hopefully we can commit some more issues during 8.7.x then describe a more coherent working system.
    • We need some guidance on where the documentation should go.
    adamps’s picture

    Heads up on availability and timing

    • I will be away from Drupal.org for December and January
    • 8.7.0 Feature Freeze (alpha1 release) is week of March 18, 2019
    • We have several follow on issues blocked behind this one with patches ready

    It would be extremely helpful if possible please to get a commit in the next few days so I can upload patches for the next issues. 1000s of users of D7 title module are anticipating the equivalent function for D8, and I get regular issues raised on manage_display module by people who didn't realise they needed a core patch for this basic function.

    alexpott’s picture

    Status: Needs review » Needs work

    @AdamPS base to me meant only the preprocess from the module and not the theme. Base has way too many meanings. I would suggest that the it be called something like node_basefield_skip_preprocess. Documentation is a core gate and should not be skipped for a speedy commit. Adding some random state to the node entity type needs to be documented somewhere.

    As a place to document things I suggest starting with the docblock of template_preprocess_node() as its when you override this you need to be aware that some contrib module might be setting this flag.

    jonathanshaw’s picture

    node_basefield_skip_preprocess

    That seems fine to me and is an easy fix.

    You may worry that it sounds like skipping preprocess on - all- base fields. The obvious solution to that worry would be to have 3 settings for the 3 skipped fields, named for each. But as Adam has pointed out before, that leads to more awkward edge cases because the preprocess logic about authoring information works with both uid and created together.

    alexpott’s picture

    @jonathanshaw I'm open to suggestions on the name - I just think that bypass_base_preprocess is really obscure and doesn't help a developer work out what it might do.

    adamps’s picture

    Status: Needs work » Needs review
    StatusFileSize
    new26.8 KB
    new2.78 KB

    @alexpott Thanks for your time and suggestions. I very much appreciate your hard work to keep Drupal stable for all of us and understand that you have to uphold the quality level.

    I have applied your suggestions except that I used basefield_skip_preprocess. The 'node' part seems unnecessary because the flag is set directly on the node entity:

    $entity_types['node']->set('basefield_skip_preprocess', TRUE);
    $entity_types['taxonomy_term']->set('basefield_skip_preprocess', TRUE);
    

    Rather than:

    $entity_types['node']->set('node_basefield_skip_preprocess', TRUE);
    $entity_types['taxonomy_term']->set('taxonomy_term_basefield_skip_preprocess', TRUE);
    
    alexpott’s picture

    Status: Needs review » Needs work
    1. +++ b/core/modules/node/node.module
      @@ -596,6 +596,14 @@
      + * entity flag 'basefield_skip_preprocess', which indicates that base fields
      

      entity flag is new terminology. It's an additional entity type property see \Drupal\Core\Entity\EntityType::$additional. Also this is why I think prefixing with node is a good idea. Because the object this is retrieved from is a ContentEntityType object.

    2. +++ b/core/modules/node/node.module
      @@ -596,6 +596,14 @@
      + * flag using hook_entity_type_build. This flag should be set if a module
      

      hook_entity_type_build(). Let's also add @see hook_entity_type_build()

    3. +++ b/core/modules/node/node.module
      @@ -596,6 +596,14 @@
      + * enables manage display of base fields by means of setDisplayConfigurable().
      

      makes the display node's base fields configurable via the field UI. Let's add an @see \Drupal\Core\Field\BaseFieldDefinition::setDisplayConfigurable to the doc block.

      @see's go at the end.

    adamps’s picture

    Status: Needs work » Needs review
    StatusFileSize
    new27.21 KB
    new3.39 KB

    Many thanks for a quick turnaround - here's a new patch.

    alexpott’s picture

    Status: Needs review » Needs work
    1. +++ b/core/modules/node/node.module
      @@ -599,16 +599,21 @@
      + * A module can enable the flag using hook_entity_type_build. This flag should
      

      hook_entity_type_build()

    2. +++ b/core/modules/node/node.module
      @@ -599,16 +599,21 @@
      + * be set if a module enables manage display of base fields by means of
      

      module enables manage display does read quite right to me. That's why I re-wrote it in my last comment. At the very least I think manage needs to be managing the or managing base fields' display but I prefer what I wrote the first time around as the important thing is that you're now using the Field UI to manage their display.

    3. +++ b/core/modules/node/node.module
      @@ -599,16 +599,21 @@
      + * @see \Drupal\Core\Entity\EntityType::$additional
      

      I don't think we should add this. It's an implementation detail.

    4. +++ b/core/modules/node/node.module
      @@ -599,16 +599,21 @@
      + * @see \Drupal\Core\Field\BaseFieldDefinition::setDisplayConfigurable
      

      Needs a () at the end

    jofitz’s picture

    Status: Needs work » Needs review
    StatusFileSize
    new27.19 KB
    new1.45 KB

    Made changes suggested by @alexpott in #259.

    EDIT: Apologies for the mis-titled patch file

    adamps’s picture

    @alexpott thank you for your patience and many apologies I didn't get it right. Please bear with us, hopefully it's now correct.

    Thanks @Jo Fitzgerald. Unfortunately one comment line is too long in #260 after adding brackets - here's a fix.

    adamps’s picture

    Please follow #2993647: Correctly determine when to display fields as inline which is the next step and has a patch that needs review. This issue has 50 followers, but the other one has just one and that's me! I can't get it done all by myself.

    I will be away for Dec/Jan so it would be useful to get a review from someone now if possible please.

    Reminder: we split the original problem into multiple issues and this fix alone is not enough to get manage display of node title working perfectly.

    PS Please can a member of the community set this to RTBC so that the core commit team know it's ready to go.

    thejimbirch’s picture

    Status: Needs review » Reviewed & tested by the community
    alexpott’s picture

    Issue summary: View changes
    Status: Reviewed & tested by the community » Needs work
    Issue tags: +Needs issue summary update

    We need to update the issue summary. It needs:

    • A description of the solution
    • API changes - there are none but I think it is important that the setting is described and the possible impact on themes should be described
    • The release notes section is new and important here. We need a one-liner that describes the new feature and also includes the information that this is not disruptive to existing sites.

    My big fear about this change is that whilst it is not disruptive to existing sites it makes any contrib modules that leverage it potentially very disruptive to existing sites that use contrib themes.

    Also the change record needs updating for the latest changes.

    adamps’s picture

    Title: Mechanism to disable preprocessing of node base fields so they can be used in "Manage Display" » Mechanism to disable preprocessing of node base fields so they can be configured via the field UI
    Issue summary: View changes
    Issue tags: -Needs issue summary update

    Thanks @alexpott, here is the IS. CR coming up next, but first I should save my edits here so I don't lose them by mistake.

    My big fear about this change is that whilst it is not disruptive to existing sites it makes any contrib modules that leverage it potentially very disruptive to existing sites that use contrib themes.

    I agree that is an important factor, and it has been very carefully considered when coding this patch. It should not be 'very disruptive', but it could be 'somewhat disruptive'.

    For an existing site (that enables this feature and fails to update templates) if the template closely matches the default, then the consequence is only an unwanted empty h2 tag.

    adamps’s picture

    Status: Needs work » Reviewed & tested by the community

    CR done.

    • Fixed the name of the entity type property.
    • Updated terminology to match @alexpott preference of "configurable via the field UI" rather than "Manage display".
    dqd’s picture

    Awesome progress here! +1 for all the hard work on this. Would love to see this in before freeze!

    adamps’s picture

    I am now on a break from Drupal.org

    Hopefully this will now get committed. However if any more work is needed (with luck a simple fix), it would be great if someone else could step in.

    Finally, reminder please follow and help review #2993647: Correctly determine when to display fields as inline - without that fix there are other bugs and there won't be a working beta of Manage Display module for D8.7.

    plach’s picture

    Issue summary: View changes

    +1 on the idea!

    Just a few nitpicks after a quick code review:

    1. +++ b/core/modules/node/node.module
      @@ -596,11 +596,23 @@ function node_theme_suggestions_node(array $variables) {
      + * additional entity type property 'node_basefield_skip_preprocess', which
      

      What about node_base_field_skip_preprocess? :)

    2. +++ b/core/modules/node/node.module
      @@ -596,11 +596,23 @@ function node_theme_suggestions_node(array $variables) {
      + * via the field UI by means of setDisplayConfigurable().
      
      +++ b/core/modules/node/tests/modules/node_display_configurable_test/node_display_configurable_test.info.yml
      @@ -0,0 +1,6 @@
      +description: 'Support module for node setDisplayConfigurable testing.'
      +package: Testing
      
      +++ b/core/modules/node/tests/modules/node_display_configurable_test/node_display_configurable_test.module
      @@ -0,0 +1,27 @@
      + * A module for testing setDisplayConfigurable on node base fields.
      
      +++ b/core/modules/node/tests/src/Functional/NodeDisplayConfigurableTest.php
      @@ -0,0 +1,74 @@
      + * Test setDisplayConfigurable on node base fields.
      ...
      +    // Enable module to setDisplayConfigurable.
      

      These would be more readable if we were using the full method notation: ::setDisplayConfigurable().

    3. +++ b/core/modules/node/tests/src/Functional/NodeDisplayConfigurableTest.php
      @@ -0,0 +1,74 @@
      +/**
      + * Test setDisplayConfigurable on node base fields.
      + *
      + * @group node
      + * @see \Drupal\node\Controller\NodeController
      + */
      

      "Tests"

      Also, the @see item looks extraneous.

    4. +++ b/core/modules/node/tests/src/Functional/NodeDisplayConfigurableTest.php
      @@ -0,0 +1,74 @@
      +   * Set base fields to configurable display and check settings are respected.
      

      "Sets"

    5. +++ b/core/modules/node/tests/src/Functional/NodeDisplayConfigurableTest.php
      @@ -0,0 +1,74 @@
      +    $this->drupalGet($node->urlInfo());
      ...
      +    $this->drupalGet($node->urlInfo());
      

      ::urlInfo() is deprecated, we should use ::toUrl() instead.

    6. +++ b/core/themes/bartik/templates/node.html.twig
      @@ -81,13 +81,13 @@
      +    {% if display_submitted and author_name and date %}
      

      Why isn't display_submitted enough here?

    jonathanshaw’s picture

    +++ b/core/themes/bartik/templates/node.html.twig
    @@ -81,13 +81,13 @@
    +    {% if display_submitted and author_name and date %}
    

    Why isn't display_submitted enough here?

    For basically the same reason that we need {% if label and not page %} not just {% if not page %}: we can no longer rely on the field variables label, author_name and date always being present.

    We could in theory make sure author_name is always present (by copying the array variable to bypass passing by reference so that its rendering here does not prevent it from rendering as a normally managed field later).

    While this approach of non-optional variables might seem to make sense for author_name & date (where there is a setting provided on the content type for the very purpose of controlling the display of author and date) it is more awkward for title because there the sitebuilder or even the developer are not provided with a way to turn off the printing of the label. This means that when the title is also treated as a configurable field in the way this issue enables, it would still end up being printed in front of the other fields as the label. Therefore we have to have the label variable optional, not present when managing the title as a normal field.

    TLDR; it's debatable but it's for simplicity:
    {% if display_submitted and author_name and date %}
    is used to keep the logic closely parallel to that required for the title:
    {% if label and not page %}

    larowlan’s picture

    Status: Reviewed & tested by the community » Needs work

    For last couple of comments

    alexpott’s picture

    Status: Needs work » Needs review
    StatusFileSize
    new8.46 KB
    new27.46 KB
    1. I agree
    2. Tried to improve the comments
    3. Fixed
    4. Fixed
    5. Fixed
    6. See #270

    The interdiff is a bit odd because there was a rebase too.

    jonathanshaw’s picture

    Status: Needs review » Reviewed & tested by the community
    adamps’s picture

    Many thanks @larowlan and @alexpott. The new patch looks good to me. The patch has now been reviewed in detail by many experts and also tested in the real world (contrib module manage_display has 7000 downloads).

    It would be great if we can get a commit soon as 8.7.x alpha is not so far away and there are multiple follow on issues waiting.

    pancho’s picture

    Status: Reviewed & tested by the community » Needs review
    -    {% if display_submitted %}
    +    {% if display_submitted and author_name and date %}

    I agree with @jonathanshaw that we should handle this in a way consistent with {{ label }}. This way we're documenting that the presence of these variables can't be relied on.

    However, why do we do this in core/themes/bartik/templates/node.html.twig but leave it out in all the other node.html.twig files?

    Setting back to needs review to doublecheck if there's a deeper reason or if it was just left out.
    Otherwise an excellently documented and tested patch implementing a very simple (though important) flag, so apart from this it should remain RTBC.

    adamps’s picture

    @Pancho Thank you for a detailed review, well spotted. That change not be present on core/themes/bartik/templates/node.html.twig.

    The reason why we don't need the code is because of the logic in template_preprocess_node. author_name, date etc. are blank only if $preprocess is FALSE, in which case display_submitted will also be blank.

    FYI the code was previously present in all copies of node.html.twig and later got removed, but this once case was missed out. The current approach is much preferred because the template change is less impact.

    adamps’s picture

    Let's get this back to RTBC - please can someone review? Just a one line change, the tests are passing. It's simple enough that you don't need to be an expert - just look at the code in node.module and check agree with my claim that {% if display_submitted %} is a sufficient test.

    jonathanshaw’s picture

    Status: Needs review » Reviewed & tested by the community

    As usual @AdamPS is right.
    @Pancho correctly understood the thrust of @plach's #269.6 which I misunderstood in #270, and my line of reasoning in #270 was wrong anyway for the reasons @AdamPS explain in #276.

    larowlan’s picture

    1. +++ b/core/modules/node/node.module
      @@ -596,11 +596,23 @@ function node_theme_suggestions_node(array $variables) {
      + * By default this function performs special preprocessing of some base fields
      + * so they are available as variables in the template. For example 'title'
      + * appears as 'label'. This preprocessing can be disabled by means of the
      + * additional entity type property 'node_base_field_skip_preprocess', which
      

      around patch 200 or so we swapped from using ->isDisplayConfigurable to using this flag - can you elaborate on why that was done in the issue summary (tagging as such).

      there is talk of BC but its not clear to me why

    2. +++ b/core/modules/node/node.module
      @@ -609,14 +621,22 @@ function template_preprocess_node(&$variables) {
      +  $preprocess = !$node->getEntityType()->get('node_base_field_skip_preprocess');
      

      Why do we prefix this with 'node' - we know its a node because of the entity type, why not make it base_field_skip_preprocess?

    imclean’s picture

    #279.2, see #253.

    larowlan’s picture

    Thanks

    adamps’s picture

    Issue summary: View changes

    Thanks @larowlan for continuing to give your time to this issue.

    #291.1 The key comments relating to your question are #171
    #172
    #178
    #208
    #213

    I have created a new section in the IS to summarise. I hope this answers your questions.

    plach’s picture

    Status: Reviewed & tested by the community » Needs review
    Issue tags: -Needs issue summary update

    Thanks a lot for the updated summary, that's very useful!

    @larowlan and I have been discussing this a bit more, given that we both weren't feeling completely ok with the current approach. We both agree with the end goal of not special-casing base field display, we just had some doubts about the best way to get there.

    We'd like to suggest the following way forward:

    1. Rename the flag to something like enable_base_field_custom_preprocess_skipping (or something similarly ugly we will be happy to deprecate later on ;)
    2. Reintroduce a check on FieldDefinitionInterface::isDisplayConfigurable() for each entity field. When preprocessing is combining two or more rendered fields, check that none of their displays is configurable.
    3. Once all core entity types got this treatment, deprecate the enable_base_field_custom_preprocess_skipping flag.
    4. Verify whether the current core behavior can be implemented via layout builder (+ maybe custom formatters?) and:
      • if at all possible, use that instead of the custom preprocess logic when the flag is enabled; this would make core default's behavior match the current one, but would allow people to configure base field display via the UI;
      • if it's not possible to conditionally enable the LB configuration, just deprecate the preprocess logic and suggest to use Layout Builder instead.
    5. In D9 remove the flag and the custom preprocess logic, leave only the Layout Builder configuration as default.
    plach’s picture

    Of course, only bullet 1 and 2 would need to happen in this issue :)

    adamps’s picture

    Here is a new patch that addresses 1. and 2.

    The title field can now be controlled independently whether it has special preprocessing.

    When preprocessing is combining two or more rendered fields, check that none of their displays is configurable.

    Yes, the uid and created fields go together as a pair. If enable_base_field_custom_preprocess_skipping is set and either of the two fields is display configurable, then the special preprocessing is skipped. There's no way around that as far as I can see: the method of special preprocessing and display_submitted only works if both fields are preprocessed. If we preprocess just one field then that field is not displayed at all.

    adamps’s picture

    StatusFileSize
    new27.47 KB
    new885 bytes

    Oops previous patch has a bug with an extra !

    adamps’s picture

    Regarding 4. The contrib module manage_display contains formatters that exactly replicate the current core behavior without the need for layout builder. There are new custom formatters for "title" and "submitted". I hope that these can eventually become part of core.

    I am not very familiar with layout builder. I could see how to use it to replicate the existing core behavior of the submitted field where the author and date fields are combined into a single sentence "Submitted by XXX on YYY" with an optional user picture first.

    plach’s picture

    Thanks for the updated patches!

    I am not very familiar with layout builder. I could see how to use it to replicate the existing core behavior of the submitted field where the author and date fields are combined into a single sentence "Submitted by XXX on YYY" with an optional user picture first.

    Through LB it should be possible to assign the node title as a standalone field block to the page title region, thus matching the current behavior. The markup might be different though, so we might still need some additional tweaks.

    Not sure about the "Submitted by XXX on YYY" output TBH. The fact that it involves two fields makes me think that a custom formatter might not be the right choice, as formatters are designed to handle a single field. Since it's a whole (translatable) sentence, we cannot simply add two separate inline blocks, one for each field, so the only idea that atm comes to my mind to replicate the current behavior and keep everything configurable through the UI, could be a custom block, ideally supporting any entity implementing both EntityOwnerInterface and EntityCreatedInterface (the latter does not exist).

    pancho’s picture

    Rename the flag to something like enable_base_field_custom_preprocess_skipping (or something similarly ugly we will be happy to deprecate later on ;)

    -  $entity_types['node']->set('node_base_field_skip_preprocess', TRUE);
    +  $entity_types['node']->set('enable_base_field_custom_preprocess_skipping', TRUE);
    

    LOL. This is funny, and I get the logic: you're avoiding a switch that is acceptable enough to stick and not get deprecated.

    However, in the meantime outsiders who happen to take it serious or who don't wish us well, might use this as an example how "weird and clumsy" Drupal supposedly is. So while I don't think it is necessary at all to be extra clumsy, at least we need to add a comment that we did this on purpose.

    plach’s picture

    You're welcome to suggest something less weird and clumsy conveying the same meaning, I don't mind to be honest :)

    pancho’s picture

    [minor edit: numbering was incorrect]

    A.), was 1.)
    Oh sorry, I didn't mean to be that honest... did I read your wrong and this wasn't on purpose? 😳
    In that case sorry again! However, how about just 'skip_custom_preprocessing'? It has to be correct, sure, but does it need to have everything in it?

    B.)

    The contrib module manage_display contains formatters that exactly replicate the current core behavior without the need for layout builder. There are new custom formatters for "title" and "submitted".

    True, but as plach said, formatters on their own can't handle multiple fields. manage_display uses a custom preprocessor, too:

    function template_preprocess_submitted(&$variables) {
      $account = $variables['account'];
      if (theme_get_setting('features.node_user_picture')) {
        $variables['author_picture'] = user_view($account, 'compact');
      }
      if (is_array($variables['date'])) {
        $variables['date']['#inline_field'] = TRUE;
        $variables['date'] = \Drupal::service('renderer')->render($variables['date']);
      }
    }
    

    C.), was 2.)
    Regarding the two proposed options 1) use Layout Builder on default, or 2) refer to Layout Builder, I'm not overly confident this is a good idea. Last time I tested it, Layout Builder was far away from being stable enough to be enabled on default or worse: (more or less) forced on site-builders. I'm quite sure we would receive tons of complaints, bug reports and support requests. This plus: I always thought Layout builder should remain an alternative rather than more or less replace our existing UI. Otherwise I would be shocked, too.

    So, while it would be nice to have a custom Layout Builder block as well, I generally tend towards thinking: "If something's missing in order to convert existing Core functionality to a new Core paradigm, then seize the opportunity to make it generically possible." This might be much more work than a quickfix, but IMO worth it, because it can (and will) be reused for all kinds of totally different sitebuilding scenarios.

    In this case, this would mean adding a super-super-basic "Display Suite" (also a bit like "Field Group") kind-of API and UI to Core that allows creating configurable extra fields to combine two or more real fields into one, possibly using field tokens. This would be sooo awesome, and would by the way allow for properly replacing (not just deprecating) current custom 'submitted' preprocessing without forcing Layout builder on anyone.

    And as you said in #284, of course this doesn't have to happen in this issue here. We can try and implement this feature to have it in place until D8 LTS, and only if we really shouldn't get it right in time (which I'm not expecting), we'd refer to the one-off Layout Builder block.

    adamps’s picture

    1) Regarding the name of the additional entity type property: I assure you that I take the matter of core patches seriously and do not intend to be purposely clumsy. There has been a lot of debate on this in past comments so please do read through that as it will help you avoid suggesting something that has already been rejected with good reason.

    I think the consensus of earlier comments is that it is essential for 'base_field' to be in there, so it would have to be at least 'skip_base_field_custom_preprocessing'. However that's not right either, because that implies this property will always cause the preprocessing to be skipped which is not true. Instead this property allows the preprocessing to be skipped if the fields are isDisplayConfigurable. Therefore the name 'enable_base_field_custom_preprocess_skipping' although long does seem to be what we need.

    To a degree it is subjective and therefore each person will have a different idea of the perfect name. I prefer to give precedence to the people who are most involved/expert and I note that plach has been credited on 51 commits to Drupal core in the past year. Every change to the name needs a change to the patch, the IS, the CR, the contrib modules that use this, so please let's not change it without a good reason. Finally, this property is intended for removal again in D9 and that's not so far away now so it's perhaps not so important to keep debating the name and instead please please can we focus on ensuring this patch gets into D8.7 before the feature freeze date next month.

    2) The discussion of plach's item 4. regarding replicating core etc is out of scope of this issue. There have been some good points raised in recent comments, but I suggest that we don't discuss it further here as this issue already has 292 comments. In the end there is likely not going to be a single right answer. LB can implement something beautifully styled with a custom block however nothing here is forcing anyone to use LB; contrib modules can implement something a bit hacky (yes I will admit to that) but that works well in the short term; there might be other ideas using calculated fields or hook_entity_extra_field_info() or yes even inventing entirely new mechanisms.

    adamps’s picture

    NB in case of any confusion, the patch that failed testing was not the most recent one. The tests are all good.

    Next step please can someone mark this as RTBC?

    plach’s picture

    First of all, thanks @AdamPS for the continued effort here, we are very close to commit and I see no risk of this missing the alpha deadline!

    I agree with some points raised in #292 (thanks for that!) and I agree this is not the issue to debate point 4, which is the trickiest of the proposed roadmap, given that step 1 and 2 are being implemented as suggested.

    (or something similarly ugly we will be happy to deprecate later on ;)

    Sorry for not being clear here: as @AdamPS explained perfectly in #294, the name was not long and clumsy on purpose, it's just that to be sufficiently self-explanatory I couldn't suggest anything better. The sentence above was kind of a joke, although it's normally a good practice to give ugly names to stuff that is meant to be deprecated/removed.

    It's perfectly clear that @Pancho meant no offense in #290, so let's keep working together towards a final RTBC. No hard feelings I hope :)

    A code review will follow shortly, didn't have time to look at the updated patches yet.

    pancho’s picture

    Category: Feature request » Task
    Status: Needs review » Reviewed & tested by the community

    The discussion of plach's item 4. regarding replicating core etc is out of scope of this issue. There have been some good points raised in recent comments, but I suggest that we don't discuss it further here

    ACK.

    Also recategorized as a task. This patch smoothes out an inconsistency rather than really introducing a new feature.

    Now this has aleady been RTBC several times, and all outstanding issues have been sufficiently resolved. We even figured out multiple options how to proceed, which I think was important not to defer to a followup. Further discussion and the actual implementation however have to be deferred to followups, so I really think this should finally go in.

    Hope I didn't miss anything on this loong issue, but am rather confident that it is ready now.

    pancho’s picture

    P.S. Think @Berdir and @plach should absolutely be credited as well.

    jonathanshaw’s picture

    @AdamPS, perhaps it would be good to update #2353867: [META] Expose Title and other base fields in Manage Display with the follow-ups 3 and 4 requested by @plach and a link to the discussion here?

    plach’s picture

    Status: Reviewed & tested by the community » Needs work
    Issue tags: +Needs followup

    This looks really solid, I only found minor coding standards or readability issues. We are very close!

    1. +++ b/core/modules/node/node.module
      @@ -621,16 +621,21 @@
      +  $can_skip = $node->getEntityType()->get('enable_base_field_custom_preprocess_skipping');
      

      I'd find the code more readable, especially below, if the variable name were mentioning preprocessing explicitly, e.g. $skip_preprocessing or $skip_custom_preprocessing.

    2. +++ b/core/modules/rdf/rdf.module
      @@ -323,24 +323,24 @@
      +    // Depending on whether special preprocessing is enabled, the 'created' field
      +    // may appear in either of two different places.
      

      This comments exceeds 80 chars.

    3. +++ b/core/modules/node/node.module
      @@ -609,14 +621,27 @@ function template_preprocess_node(&$variables) {
      +  // @todo In D9 delete this code and matching template lines. Using
      +  // $variables['content'] is more flexible and consistent.
      
      @@ -628,17 +653,22 @@ function template_preprocess_node(&$variables) {
      +    // @todo In D9 delete this code and matching template lines. Using
      +    // a field formatter is more flexible and consistent.
      

      We need to create a follow-up issue to be referenced here. That would be a good place to resume the discussion around Layout Builder and friends.

      We should also add the suggested roadmap to the parent meta and create an issue to deprecate the existing cruft.

      Also, nit: Missing @todo indentation.

    4. +++ b/core/modules/node/node.module
      @@ -609,14 +621,27 @@ function template_preprocess_node(&$variables) {
      +  if (!($can_skip && ($node->getFieldDefinition('created')->isDisplayConfigurable('view') || $node->getFieldDefinition('uid')->isDisplayConfigurable('view')))) {
      

      Maybe it's just me, but I'd find this condition group more readable if it were !$a && !$b && !$c.

    5. +++ b/core/modules/node/node.module
      @@ -609,14 +621,27 @@ function template_preprocess_node(&$variables) {
      +  if (!($can_skip && $node->getFieldDefinition('title')->isDisplayConfigurable('view'))) {
      

      If we change the conditions above, we should change also these for consistency.

    6. +++ b/core/modules/node/node.module
      @@ -628,17 +653,22 @@ function template_preprocess_node(&$variables) {
      +    // Display post information on certain node types.  This only occurs if
      

      Nit: double space before "This".

    7. +++ b/core/modules/node/node.module
      @@ -628,17 +653,22 @@ function template_preprocess_node(&$variables) {
      +    $variables['display_submitted'] = $node_type->displaySubmitted();
      

      As previously pointed out, still having this setting is tricky. I agree with:

      Personally I would recommend any module calling setDisplayConfigurable to hide display_submitted. As you say, they are two completely different paradigms and you want one or the other but not both.

      What we should probably do is make sure there is an issue about removing the whole display_submitted mechanism, and a meta to keep track of those whole family.

      We should have an issue in the parent meta to remove this setting from the UI entirely once fields are fully configurable through the UI. Meanwhile, modules enabling the flag should likely gray out the setting and add an explanation in the setting description.

    8. +++ b/core/modules/node/node.module
      @@ -628,17 +653,22 @@ function template_preprocess_node(&$variables) {
      +        // To change user picture settings (e.g. image style), edit the 'compact'
      +        // view mode on the User entity. Note that the 'compact' view mode might
      +        // not be configured, so remember to always check the theme setting first.
      +        $variables['author_picture'] = user_view($node->getOwner(), 'compact');
      

      80 chars exceeded.

    9. +++ b/core/modules/rdf/rdf.module
      @@ -323,13 +323,26 @@ function rdf_preprocess_node(&$variables) {
      +    // Depending on whether special preprocessing is enabled, the 'created' field
      +    // may appear in either of two different places.
      

      Is the comment referring to the node custom preprocessing? If so "custom" instead of "special" would be more consistent. However, if this is the case, maybe the comment needs to be reworked, because the if test is about the "display_submitted" setting, not the custom preprocessing logic.

      Also, 80 chars exceeded.

    10. +++ b/core/modules/rdf/rdf.module
      @@ -323,13 +323,26 @@ function rdf_preprocess_node(&$variables) {
      +    if (isset($variables['display_submitted']) && $variables['display_submitted']) {
      

      This can be simplified to !empty($variables['display_submitted']).

    11. +++ b/core/modules/rdf/rdf.module
      @@ -323,13 +323,26 @@ function rdf_preprocess_node(&$variables) {
      +      // If the special preprocessing is enabled, put the metadata into the
      

      As above, should we use "custom" instead of "special" here?

    pancho’s picture

    Status: Needs work » Needs review
    StatusFileSize
    new27.58 KB
    new4.42 KB

    Here we go.

    Fixed 1-2, 4-6, 8-11.

    Still to do:
    3. We need the followup issue first to add it into the comment
    7. Is there something to do at this point?
    11. I'm still not happy with:

          // If custom preprocessing is enabled, put the metadata into the special
          // variable specifically for metadata related to "Submitted by".
    
    pancho’s picture

    StatusFileSize
    new27.7 KB
    new1.66 KB

    ad 3.) Ah, there it is: #3015623: [PP-many] Remove outdated code relating to "Expose Title in Manage Display". Added to the @todo comments.

    Still to do:
    7. Is there something to do at this point?
    11. I'm still not happy with:

          // If custom preprocessing is enabled, put the metadata into the special
          // variable specifically for metadata related to "Submitted by".
    
    plach’s picture

    Thanks!

    7: This:

    We should have an issue in the parent meta to remove this setting from the UI entirely once fields are fully configurable through the UI.

    :)
    11: Neither do I, but it doesn't seem a blocker honestly


    +++ b/core/modules/node/node.module
    @@ -627,21 +627,21 @@
    +  if ($skip_custom_preprocessing || $node->getFieldDefinition('title')->isDisplayConfigurable('view')) {
    

    Shouldn't this be !$a || !$b?

    adamps’s picture

    Assigned: Unassigned » adamps
    Status: Needs review » Needs work

    OK I am working on a patch but I see there is already a patch from Pancho. So here are the comments I have written, but my patch hasn't finished testing yet. Please can any reviewers just give me a chance to compare/merge my work in before reviewing.

    Thanks @plach, good nit-picking! All done, except if indicated otherwise below.

    3, 7. The follow-up issue to remove outdated code already exists: #3015623: [PP-many] Remove outdated code relating to "Expose Title in Manage Display". I have added a link to it in the code. I have updated the issue summary in the META issue to make an explicit link from there.

    I created a new issue to cover adding formatters, LB blocks and so on #3033301: Add formatters and other mechanisms as alternative to base fields directly in entity templates - anyone who is interested feel free to comment and improve this issue. I linked it from the META issue. It's didn't seem to make sense to link this one from the code because that's not what the @todo in the code is about.

    4, 5. Well the existing code is actually !(a && (b || c))) so the alternative is !a || (!b && !c). However I'll take the hint that's it's hard to follow, and split it out into two lines by saying d = b || c. So now we have a choice between !(a && d) or !a || !d and I don't have a strong opinion. I had originally picked the first one because it more closely matches the sentence in the comment. However the second one has less brackets and you prefer it, so let's swap to that.

    plach’s picture

    4, 5. Well the existing code is actually !(a && (b || c))) so the alternative is !a || (!b && !c).

    Correct!

    (this was indeed hard to parse :)

    adamps’s picture

    Assigned: adamps » Unassigned
    Status: Needs work » Needs review
    StatusFileSize
    new27.91 KB
    new2.8 KB

    New patch similar to #301, except fix/simplify the logic of the complex if statements and improve the comments for RDF.

    Tested in my local box with manage_display module - matching new release available publicly soon.

    pancho’s picture

    Thanks, I was just about fixing #303, but there it is. :)

    adamps’s picture

    Issue tags: -Needs followup

    I believe all the follow ups are in place now, so removing that tag.

    plach’s picture

    Status: Needs review » Reviewed & tested by the community

    Thanks both, this looks ready to go now!

    pancho’s picture

    Awesome!
    Again, somebody please add Berdir and plach to the credits.

    larowlan’s picture

    Updating issue credits for those who reviewing and helped shape the patch.
    I've flagged with other committers that I intend to commit this tomorrow, but have given them an opportunity for another review in the meantime.
    To all involved here, especially @AdamPS @Pancho and @JonathanShaw, thanks for your patience and consideration of feedback.

    • larowlan committed 2541973 on 8.7.x
      Issue #2923701 by AdamPS, jonathanshaw, Pancho, Jo Fitzgerald, alexpott...
    larowlan’s picture

    Status: Reviewed & tested by the community » Fixed
    Issue tags: +8.7.0 release notes, +8.7.0 highlights

    Committed 2541973 and pushed to 8.7.x. Thanks!

    Published the change notice

    adamps’s picture

    StatusFileSize
    new28.16 KB

    Excellent many thanks @larowlan and all the other committers/experts for your time. Thanks also to everyone who helped, most especially @JonathanShaw for so many reviews.

    This issue is not suitable for cherry pick into D8.6, but in case any wants to apply it locally I have uploaded a re-roll against D8.6.

    adrian83’s picture

    🎉 Wow, watching this favorite issue of mine play out was a huge learning experience to me! Congratulations and thank you, AdamPS, JonathanShaw, and core committers for pushing this through. The ability to manage base fields in the Manage Display UI for all view modes is a huge win for the usability of Drupal display modes.

    adamps’s picture

    StatusFileSize
    new27.46 KB

    Next steps

    This issue was split into 3 parts to allow easier commit. It's now time to move our efforts to the other 2 parts, so please come and follow.

    It would be easier and less confusing for the community if we could get either one or both into D8.7. I realise time is tight now, but also I hope that we have done all the hard work now, and the rest is just tidying up.

    1. #2993647: Correctly determine when to display fields as inline This is a follow problem for nodes. The issue is ready for review with working tests. It reuses the additional entity type property enable_base_field_custom_preprocess_skipping to ensure full BC. There are no further template changes so perhaps even if we miss the alpha deadline it could be cherry picked as a bug fix .
    2. #2993642: Mechanism to disable preprocessing of base fields in taxonomy and aggregator entity types so they can be configured via the field UI Exact copy of this issue for other entity types. Main remaining task is to write tests - can anyone help with that?
    skaught’s picture

    cheers!

    xjm’s picture

    Issue tags: -8.7.0 release notes

    @plach and I both looked at this issue's release note and change record, and we didn't see any disruptive changes that would need a release notes mention, since it's explicitly stated the change is backwards-compatible.

    If that's incorrect and there is a disruption, let's update the CR and especially the release note to explain the specific disruption (and then re-tag the issue). Thanks!

    adamps’s picture

    @xjm Although the fix is fully BC, the reason we might want to bring it to people's attention is so that theme developers can update their themes - ready for site owners to enable the feature using contrib and in future perhaps directly in core. Anyway fine by me whatever what you think best.

    Status: Fixed » Closed (fixed)

    Automatically closed - issue fixed for 2 weeks with no activity.