When Drupal displays a field, the template is field.html.twig, which generates block-level markup including optional labels, attributes, and supports multiple values.

For the node title, uid and created fields Drupal supplies an overridden template (e.g. field--node--title.html.twig) that generates simplified inline markup without label or title_attributes.

If the site owner has hooked the node title to setDisplayConfigurable(), then the inline display is incorrect. The label is missing, markup is inline, and the markup might not match normal CSS selectors for fields (for example if the CSS selector specifically matches on div). For the node created field, also the metadata rel="schema:author" is missing.

Solution

Add a '#inline_field' variable to the field templates so that they can distinguish whether they are called in a context where they should return block markup or inline markup.

The detailed rules for inline markup are as follows:

  1. The page title is always inline.
  2. The node title, uid and created fields are inline except if setDisplayConfigurable() has been called.
  3. To preserve back-compatibility, rule 2) only applies if an additional entity type property has been set - reusing the mechanism from #2923701: Mechanism to disable preprocessing of node base fields so they can be configured via the field UI.

Workaround

/**
 * Implements hook_theme_registry_alter().
 */
function XXX_theme_registry_alter(&$theme_registry) {
  // Disable the 'inline' versions of node base field templates to workaround
  // https://www.drupal.org/node/2993647.
  unset($theme_registry['field__node__title']);
  unset($theme_registry['field__node__uid']);
  unset($theme_registry['field__node__created']);
}

Release notes snippet

field--node--title.html.twig, field--node--created.html.twig, and field--node--uid.html.twig have been modified to render these fields as they are configured by the site builder for sites that allow configuring the display of these fields. Themes that include these templates should add this change to them as well. See the change record for details.

CommentFileSizeAuthor
#122 inline-field.2993647-interdiff-119-122.txt5.36 KBadamps
#122 inline-field.2993647-122.patch37.58 KBadamps
#119 inline-field.2993647-interdiff-116-119.txt677 bytesadamps
#119 inline-field.2993647-119.patch37.29 KBadamps
#116 inline-field.2993647-interdiff-114-116.txt682 bytesadamps
#116 inline-field.2993647-116.patch37.29 KBadamps
#114 inline-field.2993647-interdiff-104-114.txt3.76 KBadamps
#114 inline-field.2993647-114.patch37.17 KBadamps
#103 2993647-104.patch34.19 KBalexpott
#103 102-104-interdiff.txt615 bytesalexpott
#101 2993647-102.patch34.18 KBalexpott
#101 86-102-interdiff.txt6.99 KBalexpott
#87 inline-field.2993647-interdiff-85-86.txt11.06 KBadamps
#87 inline-field.2993647-86.patch29.06 KBadamps
#85 inline-field.2993647-interdiff-80-85.txt853 bytesadamps
#85 inline-field.2993647-85.patch16.72 KBadamps
#84 interdiff_82-84.txt1015 bytesravi.shankar
#84 2993647-84.patch9.67 KBravi.shankar
#82 inline-field.2993647-interdiff-80-81.txt22.58 KBadamps
#82 inline-field.2993647-81.patch10.66 KBadamps
#80 inline-field.2993647-interdiff-63-80.txt7.77 KBadamps
#80 inline-field.2993647-80.patch15.73 KBadamps
#63 inline-field.2993647-interdiff-58-63.txt5.26 KBadamps
#63 inline-field.2993647-63.patch12.87 KBadamps
#62 entity.title-2941208-interdiff-57-63.txt1.74 KBadamps
#62 entity.title-2941208-63.patch8.41 KBadamps
#58 inline-field.2993647-interdiff-55-58.txt8.65 KBadamps
#58 inline-field.2993647-58.patch12.25 KBadamps
#55 inline-field.2993647-interdiff-49-55.txt8.34 KBadamps
#55 inline-field.2993647-55.patch12.08 KBadamps
#49 inline-field.2993647-interdiff-47-49.txt1.09 KBadamps
#49 inline-field.2993647-49.patch12.14 KBadamps
#47 inline-field.2993647-interdiff-45-47.txt592 bytesadamps
#47 inline-field.2993647-47.patch11.96 KBadamps
#45 inline-field.2993647-45.patch11.95 KBadamps
#34 inline-field.2993647-interdiff-28-34.txt610 bytesadamps
#34 inline-field.2993647-34.patch3.36 KBadamps
#28 inline-field.2993647-28.patch3.45 KBadamps
#22 inline-field.DELTA_.2993647-interdiff-20-22.txt892 bytesadamps
#22 inline-field.2993647-22.patch37.68 KBadamps
#22 inline-field.DELTA_.2993647-22.patch13.11 KBadamps
#20 inline-field.DELTA_.2993647-interdiff-12-20.txt947 bytesadamps
#20 inline-field.DELTA_.2993647-20.patch13.11 KBadamps
#20 inline-field.2993647-20.patch37.68 KBadamps
#12 inline-field.2993647-interdiff-11-12.txt2.06 KBadamps
#12 inline-field.DELTA_.2993647-12.patch12.83 KBadamps
#12 inline-field.2993647-12.patch37.51 KBadamps
#11 inline-field.2993647-interdiff-8-11.txt10.58 KBadamps
#11 inline-field.DELTA_.2993647-11.patch13.05 KBadamps
#11 inline-field.2993647-11.patch37.73 KBadamps
#9 inline-field.2993647-interdiff-6-8.txt1.66 KBadamps
#9 inline-field.DELTA_.2993647-8.patch12.19 KBadamps
#9 inline-field.2993647-8.patch36.61 KBadamps
#6 inline-field.DELTA_.2993647-6.patch12.05 KBadamps
#6 inline-field.2993647-6.patch36.46 KBadamps
#5 inline-field.2993647-5.patch25.27 KBadamps
#4 inline-field.2993647-4.patch20.03 KBadamps

Comments

AdamPS created an issue. See original summary.

adamps’s picture

adamps’s picture

Issue summary: View changes
adamps’s picture

StatusFileSize
new20.03 KB

Here is a patch, but it must be applied after the patch from #2923701: Mechanism to disable preprocessing of node base fields so they can be configured via the field UI. It will show as "failed to apply" on Drupal.org.

adamps’s picture

StatusFileSize
new25.27 KB

Previous patch was bad. Here is a new patch, which applies on top of title.display-2923701-205.patch.

adamps’s picture

Issue summary: View changes
Status: Postponed » Needs review
StatusFileSize
new36.46 KB
new12.05 KB

I have modified the issue summary so that this issue now relates specifically to nodes. The other part of the original problem has been moved into #2941208: Title formatting broken due to flawed EntityViewController->buildTitle. This makes the fix here much simpler and hopefully easy to commit to 8.7.x.

This issue is based on #2923701: Mechanism to disable preprocessing of node base fields so they can be configured via the field UI so I have uploaded two patches.

  • Please review inline-field.DELTA.2993647-6.patch which includes only this fix - but it won't apply
  • Please test inline-field.2993647-6.patch which includes both fixes
adamps’s picture

Issue summary: View changes

The last submitted patch, 6: inline-field.2993647-6.patch, failed testing. View results

adamps’s picture

Fix deprecation notice and add comment.

adamps’s picture

Reminder

adamps’s picture

StatusFileSize
new37.73 KB
new13.05 KB
new10.58 KB

I found a problem with quickedit. When a base field is re-rendered after edit, a single field is rendered without first calling template_preprocess_node. The new patch moves all the inline_field logic into node_preprocess_field__node. However if you edit the title field from the title block, it's still not fixed, and I can't see any way to fix it without big changes to quickedit. I've added a note for that problem to #2941208: Title formatting broken due to flawed EntityViewController->buildTitle

Secondly I have changed the variable name from #skip_inline_field back to #inline_field. In case we do want ever apply the more general patch like #5 then we need to get the name right now.

adamps’s picture

StatusFileSize
new37.51 KB
new12.83 KB
new2.06 KB

Slight change to make it more general - this makes it easier for contib modules to control the formatting within the page title.

adamps’s picture

Priority: Normal » Major

I have created a new release of the Contrib module Manage Display

Thanks to the 3 others who are now following. Please help get this patch committed - you don't have to be an expert to help. If anyone can test that the patch works and makes sense, please set the status to RTBC. This brings the patch to the attention of the core committers - don't worry they will give it a thorough review.

adamps’s picture

I am now on a break from Drupal.org

Hopefully #2923701: Mechanism to disable preprocessing of node base fields so they can be configured via the field UI will get committed soon, in which case I have already prepared the reroll. Please can someone load up inline-field.DELTA_.2993647-12.patch again as inline-field.2993647-XX.patch (XX = next comment number of course).

Setting this to major, as the important feature introduced in #2923701: Mechanism to disable preprocessing of node base fields so they can be configured via the field UI doesn't work properly without this patch.

mrpauldriver’s picture

Status: Needs review » Reviewed & tested by the community

Confirm that this patch together with manage_display 8.x-1.0-alpha6 is working for me

The last submitted patch, 5: inline-field.2993647-5.patch, failed testing. View results

larowlan’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/lib/Drupal/Core/Entity/Controller/EntityViewController.php
    @@ -66,10 +66,11 @@ public function buildTitle(array $page) {
    -    // correctly (e.g. RDFa, in-place editing).
    +    // correctly (e.g. in-place editing).
    

    Unintended change?

  2. +++ b/core/lib/Drupal/Core/Entity/Controller/EntityViewController.php
    @@ -66,10 +66,11 @@ public function buildTitle(array $page) {
    +        $page[$label_field]['#is_page_title'] = TRUE;
    

    I'm not a huge fan of new undocumented magic array keys

  3. +++ b/core/modules/node/node.module
    @@ -571,6 +573,23 @@ function node_preprocess_block(&$variables) {
    +    $variables['inline_field'] = !$variables['element']['#object']->getEntityType()->get('node_basefield_skip_preprocess');
    

    this relies on elements from the other issue? I don't think we can add this without that

  4. +++ b/core/modules/node/node.module
    @@ -609,16 +640,25 @@ function template_preprocess_node(&$variables) {
    +  $preprocess = !$node->getEntityType()->get('node_basefield_skip_preprocess');
    +  if ($preprocess) {
    +    // Make created, uid and title fields available separately.
    

    this looks like the code from #2923701: Mechanism to disable preprocessing of node base fields so they can be configured via the field UI?

  5. +++ b/core/themes/stable/templates/field/field--node--created.html.twig
    @@ -15,12 +15,20 @@
    +{% if not inline_field %}
    
    +++ b/core/themes/stable/templates/field/field--node--title.html.twig
    @@ -15,12 +15,20 @@
    +{% if not inline_field %}
    
    +++ b/core/themes/stable/templates/field/field--node--uid.html.twig
    @@ -15,12 +15,20 @@
    +{% if not inline_field %}
    

    are we allowed to make changes to markup in stable?

jonathanshaw’s picture

Yes, this depends on #2923701: Mechanism to disable preprocessing of node base fields so they can be configured via the field UI.

+++ b/core/lib/Drupal/Core/Entity/Controller/EntityViewController.php
@@ -66,10 +66,11 @@ public function buildTitle(array $page) {
+        $page[$label_field]['#is_page_title'] = TRUE;

I'm not a huge fan of new undocumented magic array keys

Looks like @AdamPS introduced this in #12 to make it "easier for contib modules to control the formatting within the page title". Let's hope he can explain the need.

adamps’s picture

@larowlan Thanks for your time to review.

1. This was intended change because the original comment is wrong. The code for RDFa in rdf_preprocess_node puts title metadata into $variables['title_suffix']. However I can see that fixing that comment is not directly related to this issue, so I could leave it out of the patch if you think that's better.

2. Good point - I should definitely have a comment here with @see referring to the related template. That would address "undocumented magic". It would still be an array key, but I can't see any alternative.

3, 4. Yes this depends on #2923701: Mechanism to disable preprocessing of node base fields so they can be configured via the field UI. However if you look at inline-field.DELTA_.2993647-12.patch then you can see only the differences specific to this issue.

5. Correct me if I'm wrong, but I believe the purpose of stable is to create a stable base-point for theme developers to that they don't have to track every change to a template. If we put these changes into stable, then we achieve that. If we don't, then theme developers would have to add it themselves.

adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new37.68 KB
new13.11 KB
new947 bytes

Here are new patches based on the newer patch in the base patch #2923701: Mechanism to disable preprocessing of node base fields so they can be configured via the field UI and including the code change for point 2. in the previous comment.

As before

  • please review the DELTA one which is the changes since the base issue.
  • please test the other one which includes change for both issues

The last submitted patch, 20: inline-field.2993647-20.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

adamps’s picture

adamps’s picture

Issue summary: View changes
Status: Needs review » Postponed

OK, so I have found a fairly easy workaround

/**
 * Implements hook_theme_registry_alter().
 */
function XXX_theme_registry_alter(&$theme_registry) {
  // Disable the 'inline' versions of node base field templates to workaround
  // https://www.drupal.org/node/2993647.
  unset($theme_registry['field__node__title']);
  unset($theme_registry['field__node__uid']);
  unset($theme_registry['field__node__created']);
}

What's more #3015623: [PP-many] Remove outdated code relating to "Expose Title in Manage Display" will automatically fix this bug in an easy way - by waiting until D9 there is no need to maintain back-compatibility.

Therefore I propose we might as well just postpone this issue and fix it the easy way. However if anyone disagrees and feels keen to put the effort in, then they can reawaken this issues.

jonathanshaw’s picture

Status: Postponed » Closed (won't fix)

I believe postponed has to be postponed on something; this should be closed, and someone can reopen if they disagree.

adamps’s picture

jonathanshaw’s picture

Version: 8.7.x-dev » 9.x-dev
Status: Closed (won't fix) » Active

Actually, my bad, if what you're proposing is to leave this to 9.x, then it should be an active issue on that branch I think. Same done for #2993642: Mechanism to disable preprocessing of base fields in taxonomy and aggregator entity types so they can be configured via the field UI.

adamps’s picture

Status: Active » Postponed

OK I'm not so sure about active, because it encourages someone to work on it or expect some action here.

If it has to be postponed on something, then let's say it is postponed to early 9.0 dev branch on a decision how to handle #3015623: [PP-many] Remove outdated code relating to "Expose Title in Manage Display". If that issue proceeds as expected, we will then close this one as outdated.

adamps’s picture

Version: 9.x-dev » 8.7.x-dev
Issue summary: View changes
Status: Postponed » Needs review
StatusFileSize
new3.45 KB

I have set this back to a D8 task. Sorry for going round in circles, but I had misunderstood the plan for D9. If I understand correctly, we need to get this fix into D8, then deprecate the old way in D9.

Here is a patch that is really simple, fully-BC and requires no template changes. I have just implemented the workaround from the IS.

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

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

rodrigoaguilera’s picture

Status: Needs review » Needs work

I have tried the patch and I can confirm it works as expected. I wanted to show the created date of the node with a label and with the patch applied I only had to set the field as configurable in the view mode.

I'd change it to RTBC but I think it might need a change record for people who are setting those fields as configurable and don't expect the markup to change.

rodrigoaguilera’s picture

Status: Needs work » Needs review

Please review the change record
https://www.drupal.org/node/3043840

The code looks good to me.

adamps’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @rodrigoaguilera. I adjusted the CR slightly to better match the existing CR for #2923701: Mechanism to disable preprocessing of node base fields so they can be configured via the field UI.

We may need to make adjustments depending on the timing. If this fix gets ported back to D8.7 prior to the stable release then we can potentially combine with the existing CR. If not, then perhaps we should change the patch here to use a new property instead of enable_base_field_custom_preprocess_skipping - because otherwise people who have already set the existing property might get an unpleasant surprise when the new behaviour is added in D8.8.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

The patch is failing tests.

adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new3.36 KB
new610 bytes

Updated patch fixes NodeDisplayConfigurableTest. I expect the Media test fail is a random.

jonathanshaw’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 34: inline-field.2993647-34.patch, failed testing. View results

jonathanshaw’s picture

Status: Needs work » Reviewed & tested by the community

Random fail

larowlan’s picture

Tagging for front end framework manager review because of the change from span to div for those fields

adamps’s picture

Thanks @larowlan. NB this fix actually fixes the overall rendered output to be consistent whether setDisplayConfigurable() is ON or OFF:

1) Now setDisplayConfigurable() OFF

  • node.html.twig generates a div around "submitted by"
  • field.html.twig generates a span around name and date sub-elements

2) Now with setDisplayConfigurable() ON

  • field.html.twig generates a span
  • BUG Missing div

3) After this patch with setDisplayConfigurable() ON

  • field.html.twig generates a div
  • If using the SubmittedFormatter from contrib module Manage Display, then output is almost identical to (1)

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 34: inline-field.2993647-34.patch, failed testing. View results

adamps’s picture

Status: Needs work » Reviewed & tested by the community

Another random fail

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 34: inline-field.2993647-34.patch, failed testing. View results

adamps’s picture

Status: Needs work » Reviewed & tested by the community

So many random fails!

lauriii’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -Needs frontend framework manager review

The current approach has some side effects that could be disruptive to themes as well as theming experience. Removing these items from the theme registry seems to completely prevent users from overriding templates using the suggestion matching the theme registry item. So for example, after field__node__created has been removed from theme registry, themes are unable to provide field--node--created.html.twig template. This is also not something we can or should fix because after it gets fixed, this solution also becomes ineffective because Classy and Stable both provide templates using more specific theme suggestions for this template.

I think the approach used earlier on this issues (#22) would be less disruptive. Even though markup changes to Stable and Classy are not allowed, that would be a less disruptive approach than what has been taken currently.

adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new11.95 KB

Thanks @lauriii

Here is a reroll of patch #22.

Status: Needs review » Needs work

The last submitted patch, 45: inline-field.2993647-45.patch, failed testing. View results

adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new11.96 KB
new592 bytes
adamps’s picture

Issue summary: View changes

IS and CR have been updated to match the new patch.

Please can someone from the community review this and set RTBC?

adamps’s picture

StatusFileSize
new12.14 KB
new1.09 KB

Corrected patch after testing with Manage Display module.

jonathanshaw’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

I like the universality of this approach. The calling context knows the surrounding markup, so it's got responsibility for informing the template about it. This pattern could well be useful beyond these few node fields.

wim leers’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +TX (Themer Experience)
+++ b/core/modules/node/templates/field--node--title.html.twig
@@ -15,14 +15,23 @@
+ * - inline_field: If false, display an ordinary field.
+ *   If true, display an inline format, suitable for inside span/h1/h2 etc
...
+

Wouldn't is_inline_field be clearer? Or even is_inline, so that it eventually could be generalized for use in non-Entity Field situations?

jonathanshaw’s picture

+1 for is_inline

wim leers’s picture

Status: Needs review » Needs work

Thanks for responding so quickly, @jonathanshaw :)

Since you previously RTBC'd this patch and now agree with my suggestion, I'm gonna mark this Needs work.

jonathanshaw’s picture

Issue tags: +Novice

An easy fix.

adamps’s picture

Status: Needs work » Needs review
Issue tags: -Novice
StatusFileSize
new12.08 KB
new8.34 KB
wim leers’s picture

Excellent, thanks! I wanted to re-RTBC, but in my final review I found some more problems:

  1. +++ b/core/modules/node/node.module
    @@ -581,6 +583,25 @@ function node_preprocess_block(&$variables) {
    +  elseif (in_array($variables['field_name'], ['created', 'uid', 'title'])) {
    

    Nit: let's use that third in_array() parameter for strict comparison. We do that always.

  2. +++ b/core/modules/node/node.module
    @@ -581,6 +583,25 @@ function node_preprocess_block(&$variables) {
    +    // @todo For back-compatibility, delete in D9. See
    +    // https://www.drupal.org/node/3015623
    +    $node = $variables['element']['#object'];
    +    $skip_custom_preprocessing = $node->getEntityType()->get('enable_base_field_custom_preprocess_skipping');
    +    $variables['is_inline'] = !($node->getFieldDefinition($variables['field_name'])->isDisplayConfigurable('view') && $skip_custom_preprocessing);
    
    +++ b/core/modules/node/templates/field--node--created.html.twig
    @@ -15,14 +15,23 @@
    + * @todo Delete in D9, see https://www.drupal.org/node/3015623
    
    +++ b/core/modules/node/templates/field--node--title.html.twig
    @@ -15,14 +15,23 @@
    + * @todo Delete in D9, see https://www.drupal.org/node/3015623
    
    +++ b/core/modules/node/templates/field--node--uid.html.twig
    @@ -15,14 +15,23 @@
    + * @todo Delete in D9, see https://www.drupal.org/node/3015623
    
    +++ b/core/themes/classy/templates/field/field--node--created.html.twig
    @@ -15,10 +15,17 @@
    + * @todo Delete in D9, see https://www.drupal.org/node/3015623
    
    +++ b/core/themes/classy/templates/field/field--node--title.html.twig
    @@ -15,10 +15,17 @@
    + * @todo Delete in D9, see https://www.drupal.org/node/3015623
    
    +++ b/core/themes/classy/templates/field/field--node--uid.html.twig
    @@ -15,10 +15,17 @@
    + * @todo Delete in D9, see https://www.drupal.org/node/3015623
    
    +++ b/core/themes/stable/templates/field/field--node--created.html.twig
    @@ -15,12 +15,20 @@
    + * @todo Delete in D9, see https://www.drupal.org/node/3015623
    
    +++ b/core/themes/stable/templates/field/field--node--title.html.twig
    @@ -15,12 +15,20 @@
    + * @todo Delete in D9, see https://www.drupal.org/node/3015623
    
    +++ b/core/themes/stable/templates/field/field--node--uid.html.twig
    @@ -15,12 +15,20 @@
    + * @todo Delete in D9, see https://www.drupal.org/node/3015623
    

    There's some shorthand notations ("back-compatibility" and "d9") in this comment that we generally don't use :)

    More importantly: if we're going to remove this, shouldn't we be deprecating it in this issue?

  3. +++ b/core/modules/node/templates/field--node--title.html.twig
    @@ -15,14 +15,23 @@
    + *   If true, display an inline format, suitable for inside span/h1/h2 etc
    

    for inside span/h1/h2 etc is not as precise as we tend to write comments. How about: for inline elements such as <span>, <h2>, and so on.?

jonathanshaw’s picture

More importantly: if we're going to remove this, shouldn't we be deprecating it in this issue?

That makes sense. Unfortunately https://www.drupal.org/core/deprecation does not explain how to deprecate a template. Any ideas?

+    // @todo For back-compatibility, delete in D9. See
+    // https://www.drupal.org/node/3015623
...
+    $skip_custom_preprocessing = $node->getEntityType()->get('enable_base_field_custom_preprocess_skipping');

This flag was introduced in a prior issue; I'd suggest the question of how it should be deprecated is out of scope for this issue?

adamps’s picture

StatusFileSize
new12.25 KB
new8.65 KB

Thanks @Wim Leers - new patch fixes comments from #56. I removed the specific reference to D9 because it is seems more likely that the deletions of #3015623: [PP-many] Remove outdated code relating to "Expose Title in Manage Display" won't make it until D10.

We cannot deprecate anything yet. The full sequence of planned steps is given in the parent META issue #2353867: [META] Expose Title and other base fields in Manage Display. Once we have completed #3036862: Expose Title and other base fields in Manage Display in Drupal Core we can eventually deprecate the old way that does not "Expose Title and other base fields in Manage Display in Drupal Core". Then in the next major version we can finally delete the code for the old way.

jonathanshaw’s picture

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

#58 Thanks for that background information, I was not aware. Thanks for pushing this along! 🙏

lauriii’s picture

Status: Reviewed & tested by the community » Needs work

I do like the current approach more! Thank you!

  1. +++ b/core/modules/node/node.module
    @@ -581,6 +583,24 @@ function node_preprocess_block(&$variables) {
    +/**
    + * Implements hook_preprocess_HOOK() for node field templates.
    + */
    +function node_preprocess_field__node(&$variables) {
    

    Maybe this would be a good place to briefly document what is is_inline including intentions behind introducing it. And for better discoverability, we could maybe add @see documentation to templates.

  2. +++ b/core/modules/node/node.module
    @@ -581,6 +583,24 @@ function node_preprocess_block(&$variables) {
    +    // Page title is always inline.
    

    Could we include an explanation on why the title must be always inline?

  3. I have similar concern as #56.2. Making this change would likely not be enough to allow those templates to be removed since users aren't being notified that there's something expected from them. Could we open an issue to discuss how to deprecate templates? We could then add @todo comments to properly deprecate the templates once that issue has been solved.

adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new8.41 KB
new1.74 KB

Thanks @lauriii

1. and 2. Done

3. We already have @todo comments referring to the issue that will handle deprecation: #3015623: [PP-many] Remove outdated code relating to "Expose Title in Manage Display". That issue covers deprecation for all of the parts of the parent META issue #2353867: [META] Expose Title and other base fields in Manage Display, which makes sense because the deprecation strategy will be shared. So I propose that the existing @todo comments should stay as they are.

Making this change would likely not be enough to allow those templates to be removed

I completely agree. We cannot remove the templates yet because they are still being used. These templates are required so long as we need to support both options: custom preprocessing and isDisplayConfigurable().

So the deprecation strategy that I propose will take some time, but it seems fully valid and the best (only!) idea I have seen so far.

  1. In phase B of the parent meta issue we introduce a "base field manage display" boolean config option into core, but default to off.
  2. In phase C (sometime in D9) we deprecate running with this setting off - which will require some discussion about how to deprecate a config option and give an appropriate warning to site admins.
  3. Finally in the next major release (D10?) we can remove the code and templates.
adamps’s picture

StatusFileSize
new12.87 KB
new5.26 KB

Sorry that was the patch from the wrong issue - here is the correct one.

jonathanshaw’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 63: inline-field.2993647-63.patch, failed testing. View results

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

adamps’s picture

Status: Needs work » Reviewed & tested by the community

Random fail

adamps’s picture

This patch has been RTBC for 5 months. It has been reviewed by the relevant experts and all comments have been addressed. Please, please can someone commit it or explain what more needs to be done before commit?

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 63: inline-field.2993647-63.patch, failed testing. View results

adamps’s picture

Status: Needs work » Reviewed & tested by the community

Random fail

nick_vh’s picture

Maybe good feedback, but at Dropsolid we are waiting anxiously on these commits to happen. Ideally before 9 gets released.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

xjm’s picture

adamps’s picture

The frontend framework manager review already happened in #44. Would be great to get this committed.

jonathanshaw’s picture

Maybe @xjm wanted the frontend framework manager review for #61.3, but that doesn't directly affect this patch.

xjm’s picture

I'm tagging it for frontend framework manager review to validate that the improvements described in #62 and implemented in #63 address his feedback. This request for his signoff is part of trying to get this issue committed. Thanks!

adamps’s picture

Great thanks for your time @xjm

lauriii’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -Needs frontend framework manager review
  1. We need to update these changes to stable9 too
  2. +++ b/core/modules/node/templates/field--node--title.html.twig
    @@ -15,14 +15,25 @@
    + * @todo Delete as part of https://www.drupal.org/node/3015623
    

    Maybe I'm missing something but how are we going to be able to remove the inline template for titles?

  3. +++ b/core/themes/stable/templates/field/field--node--uid.html.twig
    @@ -15,12 +15,22 @@
    + * @todo Delete as part of https://www.drupal.org/node/3015623
    

    I still had the concern that we should deprecate these templates for us to be able to delete them eventually. Maybe we could use the Twig deprecated tag for this https://twig.symfony.com/doc/2.x/tags/deprecated.html. I think it would be fine to do this in a follow-up that would happen between this issue and #3015623: [PP-many] Remove outdated code relating to "Expose Title in Manage Display". Instead of marking these to be deleted as part of that issue, let's reference the new follow-up.

  4. +++ b/core/modules/node/node.module
    @@ -581,6 +583,28 @@ function node_preprocess_block(&$variables) {
    +    $variables['is_inline'] = TRUE;
    ...
    +    $variables['is_inline'] = !($node->getFieldDefinition($variables['field_name'])->isDisplayConfigurable('view') && $skip_custom_preprocessing);
    

    I assume we will have to remove the is_inline variable eventually too. Let's open another follow-up to figure out how to deprecate that.

adamps’s picture

Thanks @lauriii

We need to update these changes to stable9 too

Good point.

Your comments 2-4 are similar to your previous ones in #61 that I tried to answer in #62. Sorry I guess I must not have explained very well last time, so I'll try again. If what I say still makes no sense to you then please can we try to chat?

This issue is just one piece in a fairly complex META issue #2353867: [META] Expose Title and other base fields in Manage Display. The deprecation strategy takes each of the pieces together.

Phase A [Current phase]: Core uses custom preprocessing. Contrib can enable isDisplayConfigurable(). We cannot deprecate anything yet as custom preprocessing is still used in Core.

Phase B: Add a GUI option in Core to choose between custom preprocessing or isDisplayConfigurable(). Wait a while then deprecate the custom preprocessing. At this point we can deprecate many things including the templates. I have raised a new issue #3176673: Deprecate non-standard display of title and other base fields.

Phase C: [D10]: Delete the deprecated code.

Instead of marking these to be deleted as part of that issue, let's reference the new follow-up.

It's a reasonable suggestion however we already have many @todo comments from other issues within this META issue that reference 3015623, so I assume we ought stick with that for consistency.

adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new15.73 KB
new7.77 KB

Status: Needs review » Needs work

The last submitted patch, 80: inline-field.2993647-80.patch, failed testing. View results

adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new10.66 KB
new22.58 KB

Status: Needs review » Needs work

The last submitted patch, 82: inline-field.2993647-81.patch, failed testing. View results

ravi.shankar’s picture

Status: Needs work » Needs review
StatusFileSize
new9.67 KB
new1015 bytes

Fixed failed tests of patch #82.

adamps’s picture

StatusFileSize
new16.72 KB
new853 bytes

Sorry #82 was the patch for a different issue. Try again.

Status: Needs review » Needs work

The last submitted patch, 85: inline-field.2993647-85.patch, failed testing. View results

adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new29.06 KB
new11.06 KB
jonathanshaw’s picture

Back to @laurii

adamps’s picture

Thanks @jonathanshaw. I think it would be useful to get a clearly documented review from the community. If you are happy with the patch please can you set the status to RTBC?

jonathanshaw’s picture

I RTBC'd in #64, and that still stands, but no one's going to commit without frontend framework manager sign off.

adamps’s picture

I RTBC'd in #64, and that still stands, but no one's going to commit without frontend framework manager sign off.

I agree with that. However I worry that the frontend framework manager might wait until issues are RTBC before reviewing them. My interpretation is that you and I are the community; RTBC means we, the community, think it's ready for the maintainers/managers to look at.

jonathanshaw’s picture

Status: Needs review » Reviewed & tested by the community

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 87: inline-field.2993647-86.patch, failed testing. View results

adamps’s picture

Status: Needs work » Reviewed & tested by the community

Just a random fail

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 87: inline-field.2993647-86.patch, failed testing. View results

jonathanshaw’s picture

Status: Needs work » Reviewed & tested by the community

Random

alexpott’s picture

  1. +++ b/core/modules/node/node.module
    @@ -431,6 +433,28 @@ function node_preprocess_block(&$variables) {
    +  if (isset($variables['element']['#is_page_title'])) {
    

    This should test for truthiness too. $variables['element']['#is_page_title'] = FALSE will pass this check too which would be wrong.

    I think:

    if ($variables['element']['#is_page_title'] ?? FALSE) {
    

    would work.

  2. +++ b/core/modules/node/templates/field--node--created.html.twig
    @@ -15,14 +15,25 @@
    +{% if not is_inline %}
    +  {% include "field.html.twig" %}
    +{% else %}
     <span{{ attributes }}>
       {%- for item in items -%}
         {{ item.content }}
       {%- endfor -%}
     </span>
    +{% endif %}
    

    This is making me wonder if field.html.twig should support is_inline too.

  3. +++ b/core/modules/node/tests/src/Functional/NodeDisplayConfigurableTest.php
    @@ -62,9 +62,10 @@ public function testDisplayConfigurable() {
    -    $assert->elementTextContains('css', 'span.field--name-created', \Drupal::service('date.formatter')->format($node->getCreatedTime()));
    -    $assert->elementTextContains('css', 'span.field--name-uid[data-quickedit-field-id="node/1/uid/en/full"]', $user->getAccountName());
    -    $assert->elementNotExists('css', 'span.field--name-uid a');
    +    $assert->elementTextContains('css', 'div.field--name-created', \Drupal::service('date.formatter')->format($node->getCreatedTime()));
    +    $assert->elementTextContains('css', 'div.field--name-uid[data-quickedit-field-id="node/1/uid/en/full"] .field__item[rel="schema:author"]', $user->getAccountName());
    +    $assert->elementNotExists('css', 'div.field--name-uid a');
    +    $assert->elementTextContains('css', 'div.field--name-uid div.field__label', 'Authored by');
    

    This is the sum total of the test coverage introduced here. The good thing is that the test contains the opposite assertions here proving that BC is maintained.

I'm leaving at rtbc because the change required to fix the if is very small.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/node/templates/field--node--title.html.twig
    --- a/core/modules/node/templates/field--node--uid.html.twig
    +++ b/core/modules/node/templates/field--node--uid.html.twig
    
    +++ b/core/profiles/demo_umami/themes/umami/templates/classy/field/field--node--created.html.twig
    @@ -15,10 +15,19 @@
    +  {% include "field.html.twig" %}
    
    +++ b/core/profiles/demo_umami/themes/umami/templates/classy/field/field--node--title.html.twig
    @@ -15,10 +15,19 @@
    +  {% include "field.html.twig" %}
    
    +++ b/core/profiles/demo_umami/themes/umami/templates/classy/field/field--node--uid.html.twig
    @@ -15,10 +15,19 @@
    +  {% include "field.html.twig" %}
    
    +++ b/core/themes/bartik/templates/classy/field/field--node--created.html.twig
    @@ -15,10 +15,19 @@
    +  {% include "field.html.twig" %}
    
    +++ b/core/themes/bartik/templates/classy/field/field--node--title.html.twig
    @@ -15,10 +15,19 @@
    +  {% include "field.html.twig" %}
    
    +++ b/core/themes/bartik/templates/classy/field/field--node--uid.html.twig
    @@ -15,10 +15,19 @@
    +  {% include "field.html.twig" %}
    
    +++ b/core/themes/claro/templates/classy/field/field--node--created.html.twig
    @@ -15,10 +15,19 @@
    +  {% include "field.html.twig" %}
    
    +++ b/core/themes/claro/templates/classy/field/field--node--title.html.twig
    @@ -15,10 +15,19 @@
    +  {% include "field.html.twig" %}
    
    +++ b/core/themes/seven/templates/classy/field/field--node--created.html.twig
    @@ -15,10 +15,19 @@
    +  {% include "field.html.twig" %}
    

    Discussed with @lauriii. In light of #3144443: Phase out Drupal\Core\Template\Loader\ThemeRegistryLoader I think we should use something like

     {% include "@seven/templates/classy/field/field.html.twig" %}</code
    </li>
    
    <li>
    <code>
    +++ b/core/modules/node/tests/src/Functional/NodeDisplayConfigurableTest.php
    @@ -62,9 +62,10 @@ public function testDisplayConfigurable() {
    -    $assert->elementTextContains('css', 'span.field--name-created', \Drupal::service('date.formatter')->format($node->getCreatedTime()));
    -    $assert->elementTextContains('css', 'span.field--name-uid[data-quickedit-field-id="node/1/uid/en/full"]', $user->getAccountName());
    -    $assert->elementNotExists('css', 'span.field--name-uid a');
    +    $assert->elementTextContains('css', 'div.field--name-created', \Drupal::service('date.formatter')->format($node->getCreatedTime()));
    +    $assert->elementTextContains('css', 'div.field--name-uid[data-quickedit-field-id="node/1/uid/en/full"] .field__item[rel="schema:author"]', $user->getAccountName());
    +    $assert->elementNotExists('css', 'div.field--name-uid a');
    +    $assert->elementTextContains('css', 'div.field--name-uid div.field__label', 'Authored by');
    

    I think we need to change this test to test all the themes change here so we have test coverage of all the changes.

lauriii’s picture

Discussed #99.1 with @alexpott in more detail and we thought that even though #3144443: Phase out Drupal\Core\Template\Loader\ThemeRegistryLoader is happening, we still prefer using the Drupal\Core\Template\Loader\ThemeRegistryLoader here because it benefits contrib theme authors without too much of a downside. Most of the downsides listed on that issue are specific to using Drupal\Core\Template\Loader\ThemeRegistryLoader with the Twig extend or embed. That issue will likely end up providing an alternative, more explicit way of loading templates from the theme registry.

We also briefly discussed the benefits of the current approach over the approach taken in #34. We agreed that the current approach is better because it makes this behavior explicit for front end developers. It also makes sure that any pre-existing overrides don't break as a result of setting enable_base_field_custom_preprocess_skipping to true.

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new6.99 KB
new34.18 KB

Patch attached addresses #98 and #99

But leaves one more thing to do which is to fix the test to test Olivero and probably to fix the Olivero theme.

Status: Needs review » Needs work

The last submitted patch, 101: 2993647-102.patch, failed testing. View results

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new615 bytes
new34.19 KB

Fixing the deprecation.

adamps’s picture

Status: Needs review » Needs work

Many thanks @lauriii and @alexpott. #103 looks good to me.

Setting to needs work for "test and fix the Olivero theme." I'll get to it as soon as I can but probably not this month so if anyone else is keen please go ahead.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

donquixote’s picture

Hello,
It is nice we are trying to fix this, but to me this seems like the wrong approach:

  • Lots of repetition (already the case now, we are adding to it).
  • Logic in the template, that should be elsewhere.
  • Choosing the template based on the field name seems like generally the wrong solution to the problem.

Alternative: field--inline.html.twig

Instead we should simply have a field--inline.html.twig and a regular field.html.twig, and then make the distinction on render element level or on theme hook suggestion level.

Possible problems and challenges with this idea:

  • Backwards compatibility: How can we make sure themes, modules or custom hacks that rely on e.g. field--node--title.html.twig still work?
  • Name clash: What if an entity type, bundle or field is named 'inline', would this accidentally trigger the 'field--inline.html.twig' template? We could avoid this by naming this template differently, perhaps even prefix it with something and then artificially set 'field' as the base theme hook.
adamps’s picture

@donquixote Thanks for your comment. We did already consider that idea, and in fact you have exactly highlighted the problem we also noticed with it. Backward-compatibility is a big challenge with this issue and the whole META issue #2353867: [META] Expose Title and other base fields in Manage Display. We must care for the majority of sites that don't change their templates and ensure nothing gets worse. If we start invoking the theme field--inline in cases that previously used field then we break sites because custom hooks/templates will no longer be called.

The disadvantages you list are only temporary. Once the whole META issue is completed they will all go away becoming much better than now. Eventually we don't want to invoke a different template for those 3 fields instead we want to remove that whole special case and treat them like any other field. So introducing field--inline now actually creates a problem when we want to get rid of it again later. So in D10 when we can remove the deprecated code we will have the perfect solution. Until then it is slightly more complicated but I don't see any alternative.

The strategy chosen here has now been reviewed by many key members of the Drupal.org community and they have collectively agreed it is the correct approach.

donquixote’s picture

@AdamPS Thanks for the explanation!

The strategy chosen here has now been reviewed by many key members of the Drupal.org community and they have collectively agreed it is the correct approach.

If this is indeed the best or only BC-friendly solution, then I am ok with it for D9.

So in D10 when we can remove the deprecated code we will have the perfect solution.

Where would I learn about the "perfect" solution in D10? In #2353867: [META] Expose Title and other base fields in Manage Display?
So in D10, the title field would be rendered like any other field using the regular field template? So the markup would be something like <div class="field ..."><h2>...</h2></div>, where the <h2> would be coming from the field formatter? Or is this not fully planned yet?

I think there are other use cases where it would be useful to switch the field template independently from the field name and the formatter. Currently this can be done in contrib, e.g. using Display suite field templates. But any such contrib solution will need to incorporate or work around the theme hook suggestion mechanism. E.g. any contrib module that wants to introduce a field--inline.html.twig will need to consider the case where "inline" actually matches an existing theme hook suggestion. Currently this could only happen if there is either a field type or an entity type named "inline" (field names are typically prefixed), which seems unlikely. But the current suggestion mechanism does limit the namespace that such contrib modules could use. Perhaps we need to rethink the suggestion mechanism for D10.

But I guess we should keep this issue strictly about D9, and discuss anything related to D10 elsewhere.

donquixote’s picture

Some code review for #103.

+function node_preprocess_field__node(&$variables) {

Is the '__node' reliable?
I think it will match or fail depending on the field template the theme uses.
It will fail on "field__{$field_type}" or "field__{$field_name}", but it will match "field", "field__{$entity_type}", "field__{$entity_type}__{$bundle}", "field__{$entity_type}__{$field_name}" and "field__{$entity_type}__{$field_name}__{$bundle}". At least this is what I remember from last time I checked how this mechanism works.

+    $node = $variables['element']['#object'];

We should add /** @var \Drupal\node\NodeInterface $node */ in the line above, to allow static code analysis by the IDE.

+    $variables['is_inline'] = !($node->getFieldDefinition($variables['field_name'])->isDisplayConfigurable('view') && $skip_custom_preprocessing);

For my taste, there is too much happening in one line here.
But then I looked at existing places where we do this as an if (..) condition, they also have this check in one line.

However, we can eliminate the parentheses and replace && with ||, this also makes us more consistent with other places in code. And swap the two sides of the ||, like so:

$variables['is_inline'] = !$skip_custom_preprocessing || !$node->getFieldDefinition($variables['field_name'])->isDisplayConfigurable('view');

---------

Besides this, I wonder, is preprocess the right place to do this?
Perhaps it is. But for contrib, should we provide ways to control this behavior from the render element? E.g. to allow formatters to set an '#is_inline' flag?

The two distinct settings 'display configurable' and 'enable_base_field_custom_preprocess_skipping' seem awkward to me. Since both are boolean, there are 4 different combinations/scenarios per field. I wonder if each of those 4 are meaningful choices, and whether we have a well-designed "expected behavior" for all of those 4 combos.
This was already introduced in #2923701: Mechanism to disable preprocessing of node base fields so they can be configured via the field UI, so there is no point to change it now. But we should at least document what we expect to happen in each of those cases.

donquixote’s picture

Besides this, I wonder, is preprocess the right place to do this?

Some observations

With current code and this patch, I found the following places where we are going to check for 'enable_base_field_custom_preprocess_skipping' and ->isDisplayConfigurable():

  • hook_entity_extra_field_info(), introduced in #2923701: Mechanism to disable preprocessing of node base fields so they can be configured via the field UI:
    • aggregator_entity_extra_field_info(), for 'aggregator_feed:image', 'aggregator_feed:description', 'aggregator_item:description'.
  • Entity preprocess hook, introduced in #2923701: Mechanism to disable preprocessing of node base fields so they can be configured via the field UI:
    • template_preprocess_aggregator_item(), setting 'title' from $entity->label().
    • template_preprocess_aggregator_feed(), setting 'title' from $entity->label().
    • template_preprocess_node(), for 'date', 'author_name', 'title', each from $variables['elements'][$field_name].
    • template_preprocess_taxonomy_term(), setting 'name' from $variables['elements']['name'].
  • Field preprocess hook, proposed in this issue, for now only for node fields, but possible follow-up for other entity types?
    • node_preprocess_field__node(), setting 'is_inline' for 'created', 'uid', 'title'.

    This made me wonder: Why don't we have a field template override for taxonomy term name?
    I installed D9 with umami, set up a view mode for terms, and found this html in a term view mode:

    <h2><a .. href=".."><div class="field ...">Accompaniments</div></a></h2>. So we are not changing term names to "inline" currently.
    
    Also interesting to see how some fields use <code>$entity->label()

    , instead of using the field.

    Proposal

    It seems to me that:

    • Whatever is in $variables['label'] should render as inline, either using <span class="field ...">, or no wrappers at all.
    • Whatever remains in $variables['elements']['title'] should have the regular field wrapper markup with <div class="field ...">.

    Therefore, could we set the 'is_inline' in template_preprocess_node()?
    Like so:

      if (isset($variables['elements']['title']) && (!$skip_custom_preprocessing || !$node->getFieldDefinition('title')->isDisplayConfigurable('view'))) {
        $variables['label'] = $variables['elements']['title'];
        // Trigger the inline display in the field template.
        // Respect contrib modules that set '#is_inline' explicitly.
        $variables['label'] += ['#is_inline' => TRUE];
        unset($variables['elements']['title']);
      }
    

    We could then add 'is_inline' to the variables in the 'field' theme hook, so it will be added to the $variables array.
    Also, by doing this, we perhaps no longer need the '#is_page_title'.

    As a next step, we could move this entire logic from the entity preprocess phase to hook_entity_view_alter(), so it would happen on render element level. We could also allow a setting in the view mode render element, that could be set in contrib, and that would control this behavior per view mode.

    I don't know yet if any of these ideas would be problematic for BC.

adamps’s picture

Re #108:

Where would I learn about the "perfect" solution in D10?

You could look at #3015623: [PP-many] Remove outdated code relating to "Expose Title in Manage Display" which explains the parts that will be deprecated. All the messy, ugly parts that you are uneasy about are scheduled for removal.

So in D10, the title field would be rendered like any other field using the regular field template?

Exactly right.

But I guess we should keep this issue strictly about D9, and discuss anything related to D10 elsewhere.

Yes - you have some interesting ideas however this issue has a very specific purpose.

adamps’s picture

#110 is hard for me to follow.

The problem in this issue is entirely specific to these 3 specific node fields. They are the only ones that have a per-field override that generates inline content in a hardcoded way. Whatever you are seeing for taxonomy terms is not this bug it's something else.

This issue is trying to solve a specific bug with minimal changes to code in as safe as possible way. So the answer to "why don't we" or "we could then add", "As a next step, we could move" is that those things are not required to solve the bug. What's more, almost anything you move from one place to another usually breaks BC in complicated ways.

It took many hours of patient careful study and peer review to find the solution here. If can find a clear problem with it then sure write it down and I will discuss. I'm afraid I can't realistically answer (or even always remember) every one of your ideas in detail as to why it doesn't work. However as quick example where I can see what appears to be a problem: we don't use the node preprocess/template as it is only called when rendering an entire node. It is missed for a single field render perhaps via Ajax, such as quickedit.

adamps’s picture

Re #109

Is the '__node' reliable?

Well the tests pass! I think what saves us is that the templates we care about are all node specific: field--node-uid.html.twig and so on. Similar code already exists in rdf_preprocess_field__node__uid. If you still think there is a problem please can you explain precisely how to hit it?

We should add /** @var \Drupal\node\NodeInterface $node */ in the line above, to allow static code analysis by the IDE.

Good idea, will do.

However, we can eliminate the parentheses and replace && with ||

So you have applied "De Morgan's laws". I don't believe that there is a universally agreed view that this makes things simpler. In this case, the logic I wrote exactly corresponds to the comment above so I think it's clearer to stay as it is.

The two distinct settings 'display configurable' and 'enable_base_field_custom_preprocess_skipping' seem awkward to me

The first is an important mechanism that applies to all fields on all entities. The second is a slightly awkward temporary BC mechanism. However I don't want to get drawn into this as I believe that is part of another another issue, not this one.

adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new37.17 KB
new3.76 KB

New patches fixes:

  • #101 Test Olivero
  • #109 Add variable comment
  • Fix starterkit_theme

Status: Needs review » Needs work

The last submitted patch, 114: inline-field.2993647-114.patch, failed testing. View results

adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new37.29 KB
new682 bytes
jonathanshaw’s picture

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

So you have applied "De Morgan's laws". I don't believe that there is a universally agreed view that this makes things simpler. In this case, the logic I wrote exactly corresponds to the comment above so I think it's clearer to stay as it is.

Yes, I forgot how it is called, too long ago :)
I cannot point to a specific Drupal convention, but I do find that comparable places in code use a negation normal form.
(I just looked this up, I am not trying to prove any authority on the matter)

Here is the result of a search:

~/projects/d8/www $ ag if.*skip_custom_preprocessing core/
core/modules/node/node.module
494:  if (!$skip_custom_preprocessing || !$submitted_configurable) {
501:  if (isset($variables['elements']['title']) && (!$skip_custom_preprocessing || !$node->getFieldDefinition('title')->isDisplayConfigurable('view'))) {

core/modules/aggregator/aggregator.theme.inc
44:  if (!$skip_custom_preprocessing || !$item->getFieldDefinition('title')->isDisplayConfigurable('view')) {
81:  if (!$skip_custom_preprocessing || !$feed->getFieldDefinition('title')->isDisplayConfigurable('view')) {

core/modules/aggregator/aggregator.module
120:  if (!$skip_custom_preprocessing || !$base_field_definitions['image']->isDisplayConfigurable('view')) {
128:  if (!$skip_custom_preprocessing || !$base_field_definitions['description']->isDisplayConfigurable('view')) {
144:  if (!$skip_custom_preprocessing || !$base_field_definitions['description']->isDisplayConfigurable('view')) {

core/modules/taxonomy/taxonomy.module
154:  if (!$skip_custom_preprocessing || !$term->getFieldDefinition('name')->isDisplayConfigurable('view')) {

There is also a performance argument to be made: evaluating the variable should be faster than doing the method call, so it would make sense to put the variable first.

adamps’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new37.29 KB
new677 bytes

I cannot point to a specific Drupal convention, but I do find that comparable places in code use a negation normal form.

That's a very good point - let's be consistent.

jonathanshaw’s picture

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

Status: Reviewed & tested by the community » Needs review

+1 to the approach here. Looks really good.

+++ b/core/modules/node/tests/src/Functional/NodeDisplayConfigurableTest.php
@@ -35,17 +61,14 @@ public function testDisplayConfigurable() {
-    $assert->elementTextContains('css', 'span.field--name-created', \Drupal::service('date.formatter')->format($node->getCreatedTime()));
-    $assert->elementTextContains('css', 'span.field--name-uid[data-quickedit-field-id="node/1/uid/en/full"]', $user->getAccountName());
-    $assert->elementTextContains('css', 'div.node__submitted', 'Submitted by');
-    $assert->elementTextContains('css', 'span.field--name-title', $node->getTitle());

It looks like the assertions that replaced these removed the CSS classes (e.g., .field--name-created) from the selectors. Is that because some of the themes don't include those CSS classes? Do we want to add additional assertions for the themes that do? Otherwise, seems like we might introduce a regression that removes the classes without a test that catches that.

One could certainly argue that asserting for these classes isn't really part of the scope of this test, but I don't think we have any other test that does it. Bonus points if we figure out a better test (or create a new one) to put that into.

adamps’s picture

Thanks for the review.

Is that because some of the themes don't include those CSS classes?

Yes - the two stable ones don't have them.

One could certainly argue that asserting for these classes isn't really part of the scope of this test

Yes I was tempted to😃.

Bonus points if we figure out a better test

Here it is - I added an option whether to check the classes on each theme. I hope that "bonus points" might lead to a commit soon. This issue has been close to commit for about 3 years and it would be great to finish it.

jonathanshaw’s picture

Status: Needs review » Reviewed & tested by the community

Nice

effulgentsia’s picture

Thank you for the test changes. Adding issue credits for reviewers.

  • effulgentsia committed fe09f58 on 9.3.x
    Issue #2993647 by AdamPS, alexpott, ravi.shankar, jonathanshaw,...
effulgentsia’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Fixed
Issue tags: +9.3.0 release notes

Pushed to 9.3.x, published the CR, and added a release note snippet to the issue summary (feel free to edit that snippet as needed) for when it's time to make release notes for 9.3.0.

Thank you everyone for all your work and patience on this.

adrian83’s picture

Congratulations! Thank you to all.

andypost’s picture

Looks CR is wrong about inline_field usage in template, it should be is_inline

adamps’s picture

Great many thanks @effulgentsia. Well spotted @andypost CR now fixed.

The focus for this [META] area now moves to the related issue that is also RTBC: #2941208: Title formatting broken due to flawed EntityViewController->buildTitle.

andypost’s picture

polished CR

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.