Problem

This issue covers multiple problems relating to the function EntityViewController->buildTitle(). This issue blocks #2353867: [META] Expose Title and other base fields in Manage Display and has adverse consequences in current vanilla core.

1 Malformed HTML output

In certain scenarios the page title region contains a div or h2 element inside h1, which is invalid markup.

Example scenario:

  • Enable the media module.
  • Create a media type and manage display to enable the name field
  • Create a media entity, and view it at /media/1.
  • Actual result: invalid markup div inside h1.
  • Expected result: valid markup.

Cause is that buildTitle inserts the rendered output of a field into $page['#title']. In vanilla core:

  • the field output comes from field.html.twig and contains a div
  • the formatter may add further tags such as h2
  • the page title output comes page-title.html.twig and wraps the title in h1

This bug does not affect user entity (no label) or node entity (specific workaround by means of field--node--title.html.twig - but that workaround causes problem 4).

2 Prevents manage display of label field

On the entity own page (such as /media/XX) the settings of manage display are ignored. The label field is missing from the main content, even if the title block is hidden.

This has been split off to a separate issue, #3043592: Allow entity to display label field as normal.

3 Inconsistent, only works selectively

The buildTitle function does not get called if the label field has been disabled by means of manage display. Hence the UX of the title block varies depending on a manage display setting (even though that setting potentially has no effect due to 2).

I analysed the tests that failed when removing buildTitle and discovered that we are relying on it for two unexpected things.

  1. HTML tags in page title: buildTitle escapes them, but template_preprocess_html strips them.
  2. Wrapper: for nodes field--node--title.html.twig is used and by default it wraps the page header title in a span

However both of these stop happening if the label field is disabled - inconsistency which is confusing and undesirable. For example it means that #2930788: Do not show name by default in media displays has surprising consequences.

4 Node titles missing label

If the site owner has hooked the node title to setDisplayConfigurable, then the title field display is incorrect, for example the label is missing.

Cause is the workaround code added for 1. The template field--node--title.html.twig overrides the normal field template with special case handling applicable if the display is not configurable. However the template gets used for configurable display too.

Overall effect

For any entity (such as core Media Entity) that allows manage display of the label, there is no safe option.

  • If display is enabled, then get bad markup from 1).
  • If display is disabled, then get potentially missing markup from 3).

There are contrib modules and core patches to extend manage display of label to more entities.

FYI Comment incorrect

The comment in buildTitle claims that the purpose is

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

However RDFa works handles the title field in rdf_preprocess_node in a way that does not rely on buildTitle.

Proposed Solution

Enhance EntityViewController->buildTitle() to switch between two alternatives.
1) "Legacy" = as existing code: set page title to the rendered title field formatter instead of the default plain text title. This is the default in Drupal 8, but is deprecated and will be removed before Drupal 9. This method has bugs if a module makes the field's display configurable via the field UI by means of of BaseFieldDefinition::setDisplayConfigurable().

2) "Template". Set page title to the output from the entity_page_title template; modules can use hook_preprocess_entity_page_title() to add attributes. Disable output of the label field in the main content. This will be the default in Drupal 9. It's not the default in Drupal 8, because it is not fully back-compatible with modules that rely on hook_preprocess_field() to set attributes on the page title.

Use the new "Template" if the label

  • a module makes the field's display configurable via the field UI by means of BaseFieldDefinition::setDisplayConfigurable()
  • AND the additional entity type property 'enable_page_title_template' has been set using hook_entity_type_build().

Rejected solution

Continue putting field into page title and fix all the bugs.

Downsides

  1. The code for putting field into page title is already somewhat complex and mysterious.
  2. We need to add more complex and mysterious code (see patch #26): pass a flag "is page title" into EntityViewController and EntityViewBuilder. That code doesn't really belong as those classes shouldn't care about page titles.
  3. We need to add more complex and mysterious code to make an inline field template (see patches in #2993647: Correctly determine when to display fields as inline). This likely forces all theme developers to alter their field template.
  4. Even after all this, there is a bug with quickedit. Patch #26 doesn't cover the case when the title is edited, and redrawn. To fix that we would need to make quickedit add an attribute to indicate a page title, and pass that information back on the AJAX request. So more complex and mysterious code.

The sole benefit of putting field into page title is to allow modules to write a preprocess function for all fields, and it 'magically' also works on the page title. However this is a dubious assumption - what works for a normal field isn't necessarily right for a page title - and has zero uses in core. (We will have to fix quickedit_preprocess_field to handle the page title case specially anyway.)

CommentFileSizeAuthor
#147 entity.title-2941208-147.patch10.6 KBAdamPS
#141 entity.title-2941208-141.patch10.29 KBAdamPS
#138 2941208-138.patch8.59 KBandypost
#138 interdiff.txt3.15 KBandypost
#133 entity.title-2941208-133.patch9.56 KBAdamPS
#122 entity.title-2941208-interdiff-120-122.txt1.75 KBAdamPS
#122 entity.title-2941208-122.patch9.56 KBAdamPS
#120 interdiff_116_120.txt1.07 KBanmolgoyal74
#120 2941208-120.patch9.55 KBanmolgoyal74
#116 interdiff-2941208-116-114.txt660 bytessja112
#116 2941208-116.patch9.35 KBsja112
#114 entity.title-2941208-interdiff-112-114.txt772 bytesAdamPS
#114 entity.title-2941208-114.patch9.25 KBAdamPS
#112 entity.title-2941208-interdiff-110-112.txt2.55 KBAdamPS
#112 entity.title-2941208-112.patch9.33 KBAdamPS
#110 entity.title-2941208-interdiff-93-110.txt731 bytesAdamPS
#110 entity.title-2941208-110.patch9.39 KBAdamPS
#107 entity.title-2941208-93.patch8.89 KBSpokje
#93 entity.title-2941208-interdiff-91-93.txt679 bytesAdamPS
#93 entity.title-2941208-93.patch8.89 KBAdamPS
#91 entity.title-2941208-interdiff-72-91.txt1.16 KBAdamPS
#91 entity.title-2941208-91.patch8.89 KBAdamPS
#89 interdiff.2941208.72-89.txt3.58 KBaleevas
#89 2941208-9.1-89.patch11.15 KBaleevas
#80 2941208-74-80.txt2.72 KBsja112
#80 2941208-9.1-80.patch8.99 KBsja112
#74 interdiff-72-74.txt1.58 KBsja112
#74 2941208-9.1-74.patch10.55 KBsja112
#72 interdiff.2941208.70-72.txt983 bytesaleevas
#72 2941208-9.1-72.patch8.97 KBaleevas
#70 interdiff.9_1.2941208.57-70.txt5.63 KBaleevas
#70 2941208-9.1-70.patch8.41 KBaleevas
#63 entity.title-2941208-interdiff-57-63.txt1.74 KBAdamPS
#63 entity.title-2941208-63.patch8.41 KBAdamPS
#57 entity.title-2941208-interdiff-56-57.txt1.09 KBAdamPS
#57 entity.title-2941208-57.patch7.78 KBAdamPS
#56 entity.title-2941208-interdiff-49-56.txt1.26 KBAdamPS
#56 entity.title-2941208-56.patch7.78 KBAdamPS
#49 entity.title-2941208-interdiff-41-49.txt832 bytesAdamPS
#49 entity.title-2941208-49.patch7.7 KBAdamPS
#41 entity.title-2941208-interdiff-38-41.txt15.12 KBAdamPS
#41 entity.title-2941208-41.patch7.69 KBAdamPS
#40 entity.title-2941208-interdiff-36-38.txt408 bytesAdamPS
#40 entity.title-2941208-38.patch15.19 KBAdamPS
#36 entity.title-2941208-interdiff-34-36.txt3.32 KBAdamPS
#36 entity.title-2941208-36.patch14.64 KBAdamPS
#34 entity.title-2941208-interdiff-32-34.txt1.72 KBAdamPS
#34 entity.title-2941208-34.patch11.73 KBAdamPS
#32 entity.title-2941208-32.patch9.88 KBAdamPS
#26 2941208-26.patch7.79 KBjofitz
#22 entity.title-2941208-interdiff-20-22.txt1.92 KBAdamPS
#22 entity.title-2941208-22.patch7.73 KBAdamPS
#20 entity.title-2941208-interdiff-18-20.txt660 bytesAdamPS
#20 entity.title-2941208-20.patch6.56 KBAdamPS
#18 entity.title-2941208-18.patch5.75 KBAdamPS
#7 entity.title-2941208-interdiff-3-7.txt2.25 KBAdamPS
#7 entity.title-2941208-7.patch2.35 KBAdamPS
#3 entity.title-2941208-3.patch1.71 KBAdamPS
#135 Screenshot from 2021-06-09 15-15-03.png90.22 KBRinku Jacob 13

Issue fork drupal-2941208

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

AdamPS created an issue. See original summary.

AdamPS’s picture

Issue summary: View changes
AdamPS’s picture

Status: Active » Needs review
FileSize
1.71 KB

First patch that simply removes buildTitle - let's see if anything breaks.

AdamPS’s picture

Issue summary: View changes

Status: Needs review » Needs work

The last submitted patch, 3: entity.title-2941208-3.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

AdamPS’s picture

Issue summary: View changes
AdamPS’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
2.35 KB
2.25 KB

New patch matches solution added to IS

Status: Needs review » Needs work

The last submitted patch, 7: entity.title-2941208-7.patch, failed testing. View results

AdamPS’s picture

Issue summary: View changes
jonathanshaw’s picture

Worth noting that the current approach was introduced for performance reasons in #2498849: Entity view controller title rendering is expensive.

jonathanshaw’s picture

Discard the existing behaviour that field templates affect the page title. The page-title.html.twig template is the logical place to govern that giving consistent formatting across the site.

This seems like the fundamentally correct solution. The way page titles are currently built is just too different from how field displays work for them to automatically share templates. I imagine that the output of buildTitle() is also used in the browser's window title too (the HTML head section)? A very different use to the page title block.

It also feels like there should be a page-title--node etc. template suggestions in the system somewhere, to allow overriding of page titles on a entity-by-entity basis.

How about doing stopping the field template affecting the title only if the field display is configurable? This might help BC, by mostly retaining existing behavior, while everyone gradually transitions to a bright configurable future.

AdamPS’s picture

@jonathanshaw

Worth noting that the current approach was introduced for performance reasons in

I looked at the blame a few days back and my recollection is that #2498849 just refactored the code so that in only ran when needed - the same behaviour was there before but in a different function.

How about doing stopping the field template affecting the title only if the field display is configurable? This might help BC, by mostly retaining existing behavior, while everyone gradually transitions to a bright configurable future.

Yes I can see that helps BC, but it is a big downside for consistency. I am not really attracted to a world whereby enabling manage_display or a similar module causes unexpected changes to the site. In particular it seems undesirable to suddenly find that titles had html tags stripped rather than escaped.

I do agree however that the lack of BC is likely to be a blocker here. I have a new idea that I'm still thinking through so I'll add a comment soon.

AdamPS’s picture

Issue summary: View changes

OK, updated IS with my new idea as solution 1. Old idea demoted to solution 2.

jonathanshaw’s picture

I think there's a bigger picture that I'm not sure we're yet addressing. Or I'm still getting my head around. It seems to me that the fundamental issues here are:

  1. there is a #title variable in the page render array, which controls much more than the context of the page title block. It also controls the window title, and is a fundamental piece of metadata
  2. like any good controller, the EntityViewController populates the page's #title property. It happens to do this using a prerender callback with its buildTitle method. It uses the entity's label field.
  3. there is a page title block, which for convenience and universality gets the title to show from the #title property
  4. entity's have a default view display; this is used OOTB as the fallback when any view mode, including 'full' is not specifically configured. Therefore if the label field is configurable and enabled on it then there is a potential for duplication in the full mode which is not a good OOTB default, and if it is configurable and not enabled then labels will be missing, which in non-full contexts is not a good OOTB default.
  5. this problem (4) is currently worked-around by having #printed set on the label field in the EntityViewController's buildTitle method,
    which suppresses further output as part of {{ content }}, and this only takes effect in the full view mode as only then is the EntityViewController in use.
  6. The problem (4) is hard and important.

    The current solution (5) is a nasty hack. Most obviously it suppresses the label on full entity pages even when the page title block is not in use. More fundamentally it links the building of the page's title property with the display of the label in the body of the page, and these are things that should be completely independent because the page title property is a more akin to metadata than a part of the entity display.

    The conclusion I draw from this is that it is just wrong for the buildTitle method to be calling render and setting #printed. It should use a less invasive approach to preparing a title from the entity's label, an approach that respects the fact that it may just be gathering a piece of metadata and not necessarily preparing the principal rendering of the label.

    Instead I suggest that it is the page title block that should be responsible for suppressing default later display of the label if it has taken over label display from the main entity display.

    The best solution might be to have buildTitle not do any rendering, and leave the rendering up to the page title block.

    An alternative would be to have buildTitle not set #printed, but add a #title_fields property to the #title or #page, holding the machine names of entity fields used in preparing the title. Then the page title block could unset (or set to #printed) these fields from the page if it is choosing to take over printing the #title. This also puts the responsibility in the correct place.

    I'm not sure how adding a hook really helps here. If modules want to override they already can, by swapping in an alternative EntityViewController. Isn't the problem we're facing is not how to override this but how to change the default in a BC way.

    Bottom line: it's really hard to reconcile configurable titles with default view modes.

    And that's even before all the other related wrinkles you've found.

AdamPS’s picture

Issue summary: View changes

@jonathanshaw Excellent, this sort of creative discussion is exactly what we need.

I feel you are currently thinking the way I was when I wrote my first patches, and what has now become solution 2. Aspects of the current system seem confusing, and awkward and it's tempting to try and throw them all away. The problem is that I feel we are unlikely to get any major non-BC changes accepted. If you want to influence that widely, it probably means become part of a major initiative working group.

I feel it's important to focus on the actual problems, of which I believe there are three, as per the IS. Your list of items are mostly statements I agree with, but that just means some factors we have to deal with in a solution. FYI I think you are still tending to have a node-specific view point in regard to view modes, whereas we are solving a problem for all entities.

I believe I have a solution, and it looks like I haven't explained it well enough. The idea is that each of the bullets under "1: safe but more complex" describes a code change that corresponds to the matching numbered solution. Hopefully these are the only code changes needed. I have altered the IS to remove the word hook which hopefully helps. I'll try to expand a little.

1) The first problem of bad markup inside h1 is only relevant in the case where the site-builder wants to the use the title block on the entity own-page. This mostly works well transferring the information by means of various existing hooks (even we feel the mechanisms are odd) except for one thing: the actual markup is wrong. Basically I feel that EntityViewController should ignore the actual formatter settings for the label field and substitute a special "entity page title" formatter which just pops the title in a span and adds the attributes.

2) The second problem of already printed fields is only relevant in the case where the site-builder wants to keep the label with the rest of the content. Basically the solution is easy - there must be a way to disable the code for 1). In fact a module can already do that by hooking to remove the buildTitle handler. However we could try to make it a little easier.

3) The third problem is that the code for 1) doesn't work if the field was disabled. My answer to 1) said "ignore actual formatter settings". To solve 3), it merely needs to "really ignore the actual formatter settings, even if they say the field is disabled".

I hope we can have a patch with only a few 10s of lines of code that are fully BC. 1) is the hardest. I haven't yet had a chance to find the existing code that we would need to slip into.

jonathanshaw’s picture

Sorry Adam, I had somehow missed the meat of your IS proposal. I think your way of dividing the problem up makes basic sense.

We already have a simple hook that solves problem 2 though: you can undo #printed in an entity preprocess. Simpler than swapping in a new controller. So we have workarounds already, I see the question as being whether there is any way to avoid the very need for them. I'd be surprised if there was much appetite for adding yet another workaround.

With regard to 1 and 3, I agree that a different output mechanism is needed in buildTitle, something that is independent of the entity's display configuration. I think it's fairly safe to assume the label is a string, although someone out there probably has the label key pointing to an entity reference field.

I agree with you on the BC concerns. BuildTitle ideally needs to stop setting #printed, but some people will be unknowingly relying on this. People not using the supplied page title block are my biggest concern because they get left out if we transfer responsibilities to it.

AdamPS’s picture

@jonathanshaw I know that I haven't had a chance to describe my ideas in full detail yet, just a rough outline. I worry that you are raising concerns about specific problems you are worried about but in fact are not things I am going to suggest. It might be easiest to wait until I have written my ideas more fully before raising detailed comments. However I will try to answer your questions...

I'd be surprised if there was much appetite for adding yet another workaround.

And I am not proposing to "add" a workaround in terms of any code change. I have described one workaround you have described another, someone else may think of a different one - each person is free to make their own mind up. (Personally I feel that #printed is more of a hack as it's an undocumented interface and unnecessary early rendering.)

For a site that chooses to keep the label in the main content and without any core changes, I think it is sufficient to unset the existing buildTitle callback (no need to add a new controller).

it's fairly safe to assume the label is a string

For 1 and 3, the label is most definitely a string, in the sense that Entity->label() returns string: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21....

BuildTitle ideally needs to stop setting #printed

Please can you explain why you feel that way? I would say that buildTitle neatly solves two jobs:

  • pass attributes through to #title so that they appear in the page title
  • prevent printing the title in the main content type because that would be double-display.

People not using the supplied page title block are my biggest concern because they get left out if we transfer responsibilities to it.

I agree - the title block should control printing of its own content and nothing outside that.

AdamPS’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
5.75 KB

New patch based on new solution 1.

  1. When displaying the label field in the page title, ignore the configured display and instead always use basic_string.
  2. Modules can selectively disable displaying the title field in the page title, instead allowing it to appear with the rest of the content by means of a hook to set $page['#page_title'] to FALSE.
  3. Ensure that point 1) of this solution occurs even if the label field is disabled.

There is another part of the work, which is to switch the page title to a new "inline field" template that uses span not div. This will shortly appear in #2923701: Mechanism to disable preprocessing of node base fields so they can be configured via the field UI because it overlaps with code patched there.

Status: Needs review » Needs work

The last submitted patch, 18: entity.title-2941208-18.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

AdamPS’s picture

Status: Needs work » Needs review
FileSize
6.56 KB
660 bytes

Status: Needs review » Needs work

The last submitted patch, 20: entity.title-2941208-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

The boundaries of this issue and the related #2923701: Mechanism to disable preprocessing of node base fields so they can be configured via the field UI have been changing, and so have the patches. Here is a clarification of current status.

Issue Summary

I have updated that IS to add item 4) moved here from other issue (because there is shared code in the patch)

Patch scope

The patch here relates to the IS as follows:
covers items 1) and 3)
4) is not yet started yet
2) I don't know if I can think of sensible code at this stage (out of scope of this issue to create a new UI) - modules can fairly easily write a hook

Patch code

The mechanism of passing EntityViewController -> EntityViewBuilder -> EntityViewDisplay is a bit awkward but I can't think of any better

MediaDisplayTest the existing test is confusing and checks for the bugged behaviour.

  • Comment "Verify the "name" field is really not present" the name definitely is there, simply it doesn't match that selector.
  • Comment "Verify the name is present, and its text matches what is expected" this is currently matching against the nested divs inside the h1.
AdamPS’s picture

Status: Needs review » Needs work

The last submitted patch, 22: entity.title-2941208-22.patch, failed testing. View results

jofitz’s picture

Status: Needs work » Needs review
FileSize
7.79 KB

Re-rolled the patch from #22 against the latest codebase.

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

Issue summary: View changes
AdamPS’s picture

Issue summary: View changes

Bringing item (1) back into this issue again. Aim is to simplify #2993647: Correctly determine when to display fields as inline and hopefully be able to commit it in D8.7, fixing item (4).

AdamPS’s picture

Issue summary: View changes
Status: Needs review » Needs work

OK, after very detailed investigations, I have concluded that the only sane approach is to wait until D9 and make a non-BC fix. I have updated the issue summary.

I will come back later with an updated patch.

In the meantime for D8, contrib module Manage Display has a hacky 90% workaround without needing a core patch.

AdamPS’s picture

Status: Needs work » Needs review
Issue tags: +Needs tests
FileSize
9.88 KB

Actually we could do it in a BC way in D8.

By default EntityViewController->buildTitle() works the existing way, call this 'legacy' mode, make it @deprecated.

Modules can use a hook to switch to the new way, which becomes the default in D9.

The patch is bit rough and needs tests. However now is a good time for people to comment on the general approach.

Status: Needs review » Needs work

The last submitted patch, 32: entity.title-2941208-32.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

AdamPS’s picture

Status: Needs review » Needs work

The last submitted patch, 34: entity.title-2941208-34.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
AdamPS’s picture

Issue summary: View changes

Status: Needs review » Needs work

The last submitted patch, 36: entity.title-2941208-36.patch, failed testing. View results

AdamPS’s picture

Issue summary: View changes
Issue tags: -Needs tests
FileSize
7.69 KB
15.12 KB

Simplified version, taking a very similar approach to the one used in #2923701: Mechanism to disable preprocessing of node base fields so they can be configured via the field UI (patch now committed).

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.

jonathanshaw’s picture

Adam asked me if I could review this patch; I can't because I'm struggling to envisage a satisfactory D9 future for sitebuilder-managed title fields and that's getting in the way of me engaging with this particular issue; Adam asked me to try to express my concerns here.

The background we all know is:

- OOTB, entities have only the 'default' pseudo-view-mode
- OOTB, entities need to provide a reasonable view of themselves (including their title) when rendered in non-full-page contexts, AND a view of themselves on their canonical full-page route that does not have a duplicate title (one in the page title block and one in the content block).
- Therefore OOTB we need to do some fancy work to show/hide the title depending on which context we're in.

D8 handles this by excluding the title field from the view mode UI. It's handled automatically behind the scenes. This keeps things relatively simple, but prevents sitebuilders from using the view mode UI to configure the title in view modes, which is a very normal thing for them to want to do.

Therefore in D9 we want the title to be manageable in the view mode UI like any other field. Which raises the question of how to reconcile the title configured in the view mode with the title in the page title block.

We want all these things:
1) No duplicate title OOTB in full-page route
2) (Maybe) Title formatter on full-page view mode is controlled by view mode UI
3) Presence & position of title amidst other fields on non-full-page view mode is controlled by view mode UI
4) Title formatter on non-full-page view mode is controlled by view mode UI

And they're very hard to reconcile.

What I dislike about the direction Adam is going in, if I understand it, is that OOTB in D9 we would have the title floating in the default view mode, but the positioning of the title amidst other fields is ignored. Probably what formatter you choose will effect the page title block, but otherwise you can drag the title around in the default view mode and it effects the entity rendering in all contexts except the full page.

This feels like weird magic that increases code complexity and obstructs developers and sitebuilders developing a mental model of how view modes work.

But I don't have a better solution. I seriously wonder if in D9 we should force entities to have explicit 'full' and 'title' view modes, so we're not relying on magic to handle all this.

The reason I didn't say all this until Adam asked me to is that I'm not sure it's constructive and it's also likely out of scope. But i find myself unable to evaluate the proposals in this issue without a satisfactory overall direction of travel for D9.

AdamPS’s picture

Thanks @jonathanshaw. Let's see if I can help at all. Firstly in terms of your background OOTB I would say it like this:

  • Entities optionally can designate one field as a label.
  • Entities optionally can expose the label field to be display configurable (and hooks can alter that).
  • On the Entity own page, Drupal renders the label field into the title and hence hides it from the rendered main content (true whether or not the label field is display configurable.

D8 handles this by excluding the title field from the view mode UI

I don't agree - D8 respects the settings of each entity. The media entity 'name' is display configurable. The node entity 'title' is by default not display configurable, but many people would like to expose it.

We want all these things ... and they're very hard to reconcile

Is it really so hard?

  • 1, 3, and 4 are already true in D8, and this issue doesn't change that.
  • 2 (which you only maybe want) is true now, but actually I feel it's not desirable and the latest patch changes it.

OOTB in D9 we would have the title floating in the default view mode, but the positioning of the title amidst other fields is ignored.

Not really. NB "default view mode" does not imply "entity own page". As you said yourself, entities might only have a single view mode, or custom display might be turned off for all non-default view modes. Even for nodes, it is possible to configure a view of nodes rendered as "full content" view mode. What's more, with node preview, any view mode can end up as "entity own page".

So in manage display GUI, the label field has its normal meaning except if "entity own page".

I agree the 'except' part can surprise people (and we can potentially try to add GUI hints to fix that when we come to the later issues that affect the GUI), but apart from that it's consistent and clear - so I'm not sure about "weird magic, increase in code complexity", etc.

Entity own page

This is the key question, the scope of this issue.

1) Now: label field is automatically hidden from main content. Future: make that an option (but defer that to a separate issue as we are not yet adding new GUI settings, just fixing existing underlying behaviour).

2) Now: format the title block based on settings from the current view mode. Future: format the title block based on a simple separate template.

Why? Well firstly, the output of an arbitrary formatter is not valid inside a h1 tag in the title block. Secondly, I don't see that developers will desire to have the settings for the view mode also used in the title block. It seems much more likely that the title block should have a consistent appearance throughout the site. We can at least make this the default as it works well for most. There is nothing to prevent future issues or contrib from allowing detailed customisation of the title block display, and I don't see that anything we do here prevents that.

In summary this is a simple change to take something that is broken for 90% (of cases where the label is display configurable) and make it work for 90%. Don't forget that to to commit to core we need to break the overall problem into simple steps that each solve a specific problem.

AdamPS’s picture

AdamPS’s picture

Another way of looking at it:

NOW: the display of the title block is controlled by the entity display settings. This works for nodes provided that the title is not exposed in manage display. However in general it created problems:

  1. It seems counter intuitive.
  2. It's often not desirable - "title block" and "entity display" are two quite different parts of the page so why should they have the same appearance?
  3. It generates bad HTML because output of a formatter is not suitable for display inside h1.

AFTER: the display of the title block is controlled by its own 'theme'. It is fully customisable by templates/hooks in the usual way, controlled separately from the entity display.

I think it really would help if someone can set RTBC, because our personal views are the main factor - the experts will come along and comment when they see RTBC.

jonathanshaw’s picture

Status: Needs review » Reviewed & tested by the community

@AdamPS has explored this problem space very thoroughly, and it tested in contrib in the 'Manage display' module.

larowlan’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/lib/Drupal/Core/Entity/Controller/EntityViewController.php
@@ -70,14 +70,32 @@ public static function create(ContainerInterface $container) {
+      if ($template_enabled && $entity->getFieldDefinition($label_field)->isDisplayConfigurable('view')) {

I think we need to handle the case where there is no label field (yes, it can happen in contrib/custom)

E.g. I have client code where the label is derived from other fields (implemented in ::label()) method so there is no label field.

AdamPS’s picture

@larowlan Thanks for the review - here is an updated patch.

jonathanshaw’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 49: entity.title-2941208-49.patch, failed testing. View results

AdamPS’s picture

Status: Needs work » Reviewed & tested by the community

Random fail

plach’s picture

Just a quick code review, I still need to have a closer look.

+++ b/core/modules/quickedit/quickedit.module
@@ -125,6 +125,20 @@ function quickedit_preprocess_page_title(&$variables) {
+  if (!\Drupal::currentUser()->hasPermission('access in-place editing') || !$entity->isLatestRevision()) {

This is missing a $entity instanceof RevisionableInterface check.

plach’s picture

Status: Reviewed & tested by the community » Needs review

Thanks for the thorough issue summary and careful planning, I think we are very close here!

  1. +++ b/core/lib/Drupal/Core/Entity/Controller/EntityViewController.php
    @@ -70,14 +70,32 @@ public static function create(ContainerInterface $container) {
    +        // Prevent output of the label field in the main content.
    +        unset($page[$label_field]);
    

    I think we should do $page[$label_field]['#access'] = FALSE here for two reasons:

    • if the enable_page_title_template flag is set and the enable_base_field_custom_preprocess_skipping is not, the following notice is raised for nodes:
      Notice: Undefined index: title in template_preprocess_node() (line 648 of core/modules/node/node.module).
      
    • If the field needs to be displayed later in the process by some custom/contrib code it's easier to restore it, otherwise the field render array needs to be built again.
  2. +++ b/core/modules/node/tests/modules/node_display_configurable_test/node_display_configurable_test.module
    @@ -25,4 +25,5 @@ function node_display_configurable_test_entity_base_field_info_alter(&$base_fiel
     function node_display_configurable_test_entity_type_build(array &$entity_types) {
       // Allow skipping of extra preprocessing for configurable display.
       $entity_types['node']->set('enable_base_field_custom_preprocess_skipping', TRUE);
    +  $entity_types['node']->set('enable_page_title_template', TRUE);
    

    Test coverage for nodes looks good, but since we are introducing a feature that any entity can leverage, we should have it tested for all supported entity types. For instance, content translation has a base test class that all supported entity types can extend with little effort. It would be valuable to do something like this here, especially because we are special casing node and user entity types.

  3. +++ b/core/modules/quickedit/quickedit.module
    @@ -125,6 +125,20 @@ function quickedit_preprocess_page_title(&$variables) {
    +  if (!\Drupal::currentUser()->hasPermission('access in-place editing') || !$entity->isLatestRevision()) {
    

    As mentioned in #53, this is missing an $entity instanceof RevisionableInterface check.

plach’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests, +Needs change record

This will also require a change record.

AdamPS’s picture

Many thanks @plach. I have added a CR.

1. Done

2. I have investigated your suggestion. It's not clear to me how we can write general test code because the details of the rendered HTML are different for each entity type. Also note that the code in this patch is not entity-type-specific and the community interest is almost entirely for the Node entity type.

As part of #3036862: Expose Title and other base fields in Manage Display in Drupal Core we will make specific changes to 4-5 entity types and so of course will need to write tests for all of them. Media entity type is the main other one that is relevant to this issue. I propose that we could defer the detailed entity-specific testing to that other issue rather than adding it here.

3. Done

AdamPS’s picture

jonathanshaw’s picture

Status: Needs review » Reviewed & tested by the community

I also struggle to understand how and why to implement #54.2

AdamPS’s picture

Clarification regarding the testing #54 point 2.

Testing only node seems like exactly the correct approach right now because we are in a temporary state where:

  1. it's difficult to test "Manage Display" because there is no UI to enable it in core
  2. any tests we add now will need to be changed later
  3. the code isn't specific to any entity.

In #3036862: Expose Title and other base fields in Manage Display in Drupal Core we will write full tests for every entity that is affected which will make complete sense because all of the above problems will have gone away.

lauriii’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/lib/Drupal/Core/Entity/Controller/EntityViewController.php
    @@ -71,14 +71,32 @@ public static function create(ContainerInterface $container) {
    +        // Prevent output of the label field in the main content.
    +        $page[$label_field]['#access'] = FALSE;
    

    I'm not sure I agree we should be hiding the label field in the main content. This creates confusing behavior because site builders could see the label in field UI but it doesn't render on the page. Shouldn't it be up to the site builder to configure this?

  2. What is the plan to address the problems related missing label caused by field--node--title.html.twig template override? Should we at least open a follow-up to try to solve that?
  3. +++ b/core/lib/Drupal/Core/Entity/Controller/EntityViewController.php
    @@ -71,14 +71,32 @@ public static function create(ContainerInterface $container) {
    +        // Set page title to the output from the entity_page_title template.
    

    I would love if we could add an explanation of why we are doing this as well.

jonathanshaw’s picture

@lauriii "I'm not sure I agree we should be hiding the label field in the main content. This creates confusing behavior because site builders could see the label in field UI but it doesn't render on the page."

I share these reservations, but Adam has repeatedly pointed out to me that if we don't do this then you get a duplicate title on the page (title block & content block) which is arguably equally confusing.

If you're sure this concern blocks commit, could you suggest a process where as a community we could figure out how to solve this UI problem? Our current paradigms don't seem to offer a neat answer.

AdamPS’s picture

@lauriii thank you for your comment.

The parent meta issues describes all the different stages of solving this problem and the roposed phasing. @Berdir and others have taught me the key principle of keeping each issue small and relating to a single problem.

1. I agree. See issue summary point 2, this is covered by a separate issue #3043592: Allow entity to display label field as normal.

This issue has not made the other problem worse or harder to solve. Already the Media entity behaves in exactyle the confusing way that you refer to. Already the node title/label variable becomes blank in the node template for the node page. At this stage we are making preparatory changes without any GUI changes. We don't yet have any core GUI to enable the manage display of base fields so it's hard to see how to make a GUI to control specific aspects..

2. We have the issue #2993647: Correctly determine when to display fields as inline and it is RTBC.

3. Sure it's always good to have better comments. I am travelling now so can't make patches. Also I have the difficulty as the patch author that it's clear to me how it works so I might fail to see how best to explain it. If @jonthanshaw or anyone else can add a comment in a new patch that would be great. Also feel free to suggest a good comment and I can do it when I get back. I hope that the IS explains why we are doing it.

jonathanshaw’s picture

Status: Needs review » Reviewed & tested by the community

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

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?

Nick_vh’s picture

Same as #2993647. 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

Status: Reviewed & tested by the community » Needs work

This is failing on 9.1.x:

https://www.drupal.org/pift-ci-job/1672842

We need a different version of the patch for D9. Thanks!

aleevas’s picture

Added patch for 9.1 branch

Status: Needs review » Needs work

The last submitted patch, 70: 2941208-9.1-70.patch, failed testing. View results

aleevas’s picture

Status: Needs work » Needs review
FileSize
8.97 KB
983 bytes

Trying to fix failed test

Status: Needs review » Needs work

The last submitted patch, 72: 2941208-9.1-72.patch, failed testing. View results

sja112’s picture

Status: Needs work » Needs review
FileSize
10.55 KB
1.58 KB

Fixing this:

1) Drupal\KernelTests\Core\Theme\StableDecoupledTest::testDecoupledStable with data set "claro" ('core/themes/claro', array('block.admin.css', 'filter.caption.css', 'progress.module.css', 'status-report.html.twig', 'system-modules-details.html.twig', 'system-modules-uninstall.html.twig'))
Failed asserting that an array is empty.

AdamPS’s picture

Status: Needs review » Needs work

Thanks @sja112 and @aleevas.

Unfortunately I don't think #74 is right. The entity-page-title.html.twig template would be used in any theme if the enable_page_title_template option is enabled.

I believe there is no need to override the template in each theme because the version in core is fine. So I don't understand why that test failed in #72. In this case the templates in core and stable are supposed to be identical so it should not be returned by assetsThatDifferInStable.

Can anyone see an unintended trivial difference between the files? Might there be a known bug that this test fails when a new template is added?

sja112’s picture

@adamps,

Because method testDecoupledStable confirms that theme assets are decoupled from stable and we have added new template entity-page-title.html.twig in the stable which differs from core themes, this test case is failing.

In #74 the solution I proposed was of adding the new included theme in the to-skip array (the asset filenames to be ignored). Because another option that I can see of passing this test is of adding a template in core themes which in my view is not correct.

See https://www.drupal.org/project/drupal/issues/3115223. This issue states that

Stable will be moved to contrib during Drupal 9. After we have ensured that core themes (Bartik, Claro, Seven, Umami) are not using Stable templates or libraries, we can remove Stable as a base theme of these themes.

If so then we can remove/modify this test?

jonathanshaw’s picture

@sja112 do you think #72 is right? It didn't fix the test in the way it intended to.

sja112’s picture

@jonathanshaw the only test case failing in #72 is Drupal\KernelTests\Core\Theme\StableDecoupledTest::testDecoupledStable because of the newly added template in stable.

After further investigating this issue I found the solution of fixing this test either by adding the new template in the core themes (Bartik, Claro, Seven, Umami) or adding it in the to-skip (the asset filenames to be ignored) array.

I have added the patch including the later solution in #74.

Also like I have mentioned in #76 as per the logged issue #3115223 stable will be moved to contrib during Drupal9. After we have ensured that core themes (Bartik, Claro, Seven, Umami) are not using Stable templates. If so then can we remove/modify this test?

To move forward I want to know the right approach we should take to fix the issue.
Does anyone in the comments have any thoughts on this?

jonathanshaw’s picture

What I'm saying is:

- #70 had a test failure
- #72 added a new template to stable as to fix the failure from #70
- this caused a new different failure
- #74 fixed the failure from #72

What Adam and I are saying is that we suspect #72 is a mistake, we should be trying to fix the failure from #70 without adding a new template to stable.

sja112’s picture

Status: Needs work » Needs review
FileSize
8.99 KB
2.72 KB

@jonathanshaw thanks for highlighting the issue.

After investing patch submitted in #70 yes I can see that entity-page-title.html.twig template was added in stable to pass the test which leads to another problem.

Since we are removing dependencies from the stable of the existing core themes. I have added the new template in $templatesToSkip array.

jonathanshaw’s picture

Status: Needs review » Reviewed & tested by the community

Seems right. Thanks @sja112!

AdamPS’s picture

Hmm sorry I still don't get it. We aren't do anything unusual here. We have added a template to Core. We chose not to provide an override in the main Core themes because the Core one is fine. We don't have any unusual requirement for stable so should just copy what everyone else does.

So please can someone explain why we need to make any additions to an "OverrideTest"? These overrides have only a handful of entries in and it seems to me that the community is working to remove all entries. If we try to add one then I suspect that our patch will not be accepted.

jonathanshaw’s picture

According to [#2580687]:

The Stable theme will function as a backwards compatibility layer for Drupal 8's core markup, CSS and JS.
...
This change allows core markup, CSS and JS to further evolve throughout Drupal 8, while still allowing themes to have a stable base for the clean, minimal markup provided by Drupal 8 core.

I'm not familiar with these matters, but I suspect that in order to function as a BC layer, stable MUST have a duplicate of the original version of every template present in core. This would allow core templates to change without breaking themes that use stable.

And so as we're adding a new template to core, we should add it to stable. Stable is being moved to contrib, but it hasn't been yet.

This makes we wonder if @sja112 had it right in #74 after all.

jonathanshaw’s picture

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

I really don't know the answer whether there should be a template in stable or not so I'm happy to go with either way.

But #74 still has several entries in an "OverrideTest". That seems suspicious to me. There are likely 100s of templates in core that don't have any overrides. My questions is why can't we do whatever they are doing and also not have overrides?

jonathanshaw’s picture

I think you're referring to StableDecoupledTest (which comes from #3113211: Create test for theme asset decoupling from Stable and address any regressions that decoupling may cause).

According to that issue, and the docs of StableDecoupledTest, it should only be concerned with assets that are in core but not in stable. Which would not include our template once it was added to stable by #72. This is what you pointed out already in #75.

I think the answer to why #72 fails in StableDecoupledTest might be this:

/core/tests/Drupal/KernelTests/Core/Theme/StableDecoupledTest.php
@@ -0,0 +1,305 @@
      $before = [
        '* Default theme implementation',
...
      $after = [
        '* Theme override',

It looks like the test has an opinion of how Stable's templates should be documented, different to how core's should be.

So #72 doesn't document Stable's template correctly.

+++ b/core/themes/stable/templates/field/entity-page-title.html.twig
@@ -0,0 +1,15 @@
+ * @file
+ * Default theme implementation for entity page title.

This should be changed to:

+++ b/core/themes/stable/templates/field/entity-page-title.html.twig
@@ -0,0 +1,15 @@
+ * @file
+ * Theme override for entity page title.
jonathanshaw’s picture

Status: Needs review » Needs work
AdamPS’s picture

@jonathanshaw +1 to #86 that makes sense to me. I have hidden #74 and #80. Hopefully a minor modification to #72 will fix the broken tests.

aleevas’s picture

Status: Needs work » Needs review
FileSize
11.15 KB
3.58 KB

@jonathanshaw and @AdamPS
the change from #86 not enough to fix test.
If we pay attetion to failure test. to we can see, that test try to find template files in themes dir (\Drupal\KernelTests\Core\Theme\StableDecoupledTest::providerTestDecoupledStable), but doens't them.
So I added template files to themes dir and now test should pass (it was done on my local env at least)
Let's see that test bot say!

AdamPS’s picture

Status: Needs review » Needs work

Thanks @aleevas for your patience. The tests pass but unfortunately I don't think it's right. The seven theme is missing many other templates such as checkboxes.html.twig so clearly it's OK to miss templates.

In my view the patches since #72 have tried to cover up the actual problem. We need to make sure that our new template is not returned by assetsThatDifferInStable(). #86 is showing the right approach, but perhaps the explanation was not complete - notice that in total 7 strings are substituted. We can compare other templates in core and stable to get the pattern right for the exact wording in the comments.

AdamPS’s picture

Let's try like this

jonathanshaw’s picture

Status: Needs review » Reviewed & tested by the community

Yay!

AdamPS’s picture

For other entities there might not be a langcode field so let's do it like this instead

jonathanshaw’s picture

Status: Needs review » Reviewed & tested by the community

Makes sense.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 93: entity.title-2941208-93.patch, failed testing. View results

AdamPS’s picture

Status: Needs work » Reviewed & tested by the community

Fail was just a random

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, 93: entity.title-2941208-93.patch, failed testing. View results

AdamPS’s picture

Status: Needs work » Reviewed & tested by the community

Just a random fail

MrPaulDriver’s picture

This has been a long time coming. Are we nearly there yet?

AdamPS’s picture

This issue has been RTBC for 14 months (with some gaps only to get it back working after it was broken by other commits) and no response from any Core committer/maintainer. I have no idea what else we can do or what might be missing/wrong.

DuaelFr’s picture

Thank you all for the great work here!
Let's try to trigger some subsystem maintainer and commiter with a few tags they might follow.

MrPaulDriver’s picture

Issue tags: +Needs usability review
MrPaulDriver’s picture

Issue tags: -Needs usability review
catch’s picture

I think this really needs front end framework manager review so tagging with that.

The logic looks OK to me and the comments are clear, but I don't have an opinion on the new template.

AdamPS’s picture

Thanks @catch

Spokje’s picture

Re-uploading entity.title-2941208-93.patch so it gets retested every 2 days against 9.2.x-dev.

Currently it's tested every 2 days against 9.1.x-dev.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/node/tests/modules/node_display_configurable_test/node_display_configurable_test.module
@@ -25,4 +25,5 @@ function node_display_configurable_test_entity_base_field_info_alter(&$base_fiel
   $entity_types['node']->set('enable_base_field_custom_preprocess_skipping', TRUE);
+  $entity_types['node']->set('enable_page_title_template', TRUE);

We should have documented enable_base_field_custom_preprocess_skipping better when we added it. This issue is adding enable_page_title_template. The past mistake doesn't mean we should do better here.

This makes me wonder if we should be adding it to annotation on \Drupal\node\Entity\Node and set to FALSE - the default - if we do that we'll need to cope with entity type info updating. But at least it is more discoverable.

Or should we be documenting it on \Drupal\Core\Entity\EntityType or \Drupal\Core\Entity\ContentEntityType?

AdamPS’s picture

Thanks @alexpott. I can certainly understand your desire for clear comments. However I think the problem is much wider than this issue as there doesn't seem to be any established way to document entity type properties. For example I searched the entire core codebase for label_singular and there was not a single comment about it.

The property enable_base_field_custom_preprocess_skipping is documented in the comment for template_preprocess_node and similar for all the other entity types that it applies to. Given the above, that seems about as good as we could do.

The property enable_page_title_template is not specific to certain entity types - it could be used for any fieldable entity type with a label. So it doesn't seem right to document it on one specific entity type. What I propose instead is that we make a clear comment on EntityViewController::buildTitle().

AdamPS’s picture

Status: Needs work » Needs review
FileSize
9.39 KB
731 bytes
jonathanshaw’s picture

Status: Needs review » Reviewed & tested by the community

There's no general documentation on the EntityType classes, so I don't see how a documentation would find a home there.

Unless @alexpott was thinking of changing the fix as well to do something more explicit by declaring the property on the entity type e.g.

  /**
   * Indicates whether page title should use a template.
   *
   * @var bool
   */
  protected $enable_page_title_template = NULL;

There's also

  /**
   * Any additional properties and values.
   *
   * @var array
   */
  protected $additional = [];

But if we want to document additional properties, maybe that should be a seperate issue.

AdamPS’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
9.33 KB
2.55 KB

Thanks @jonathanshaw

Unless @alexpott was thinking of changing the fix as well to do something more explicit by declaring the property on the entity type

enable_page_title_template is intended as a temporary flag to aid migration with the aim that it would eventually be removed. Adding a field is likely to make that more difficult so I feel we should avoid that.

Here is an updated patch where I have adjusted the comments to move the extra explanation about enable_page_title_template to the procedure comment so visible in the docs rather than buried inside a code comment.

jonathanshaw’s picture

Status: Needs review » Reviewed & tested by the community

Nice

AdamPS’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
9.25 KB
772 bytes

Beg pardon for yet another version and thank you @jonathanshaw for your patience.

I believe the logic of the if test was slightly wrong and the call to isDisplayConfigurable() should not be present. The malformed output can occur in exactly the same way even if the display is not configurable - for example with this code (not tested)

function XXX_entity_base_field_info_alter(&$base_field_definitions, EntityTypeInterface $entity_type) {
  if ($entity_type->id() == 'media') {
    $base_field_definitions['name']->setDisplayConfigurable('view', FALSE);
  }
}
jonathanshaw’s picture

Status: Needs review » Needs work
  1. Yes to #114
  2. +++ b/core/lib/Drupal/Core/Entity/Controller/EntityViewController.php
    @@ -64,14 +77,34 @@ public static function create(ContainerInterface $container) {
    +        $page_title = [
    +          '#theme' => 'entity_page_title',
    +          '#title' => $entity->label(),
    +          '#entity' => $entity,
    +          '#view_mode' => $page['#view_mode'],
    

    Maybe we should add $page_title['#formatted'] = $page[$label_field]; so that a themer could use the output of a configured custom formatter in a custom template if they wanted to. The default template should still use {{ title }} because only the plain label can be trusted to have the right markup.

  3. +++ b/core/modules/system/templates/entity-page-title.html.twig
    @@ -0,0 +1,15 @@
    + * Available variables:
    + * - attributes: HTML attributes for the containing span element.
    + * - title: Entity label
    

    We're missing the entity and view_mode variables from the comments on the template. NW for that.

sja112’s picture

Added missing the entity and view_mode variables from the comments on the template.

sja112’s picture

Assigned: Unassigned » sja112
Status: Needs work » Needs review
sja112’s picture

Assigned: sja112 » Unassigned
jonathanshaw’s picture

Status: Needs review » Needs work

There's 3 templates, #116 only adds to one.

Nit: title and entity don't have a period at the end of their line of the comment, whereas the others do. I'm not sure which is right, but we should be consistent.

anmolgoyal74’s picture

Status: Needs work » Needs review
FileSize
9.55 KB
1.07 KB

Added to remaining templates as well.

jonathanshaw’s picture

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

Nit: title and entity don't have a period at the end of their line of the comment, whereas the others do. I'm not sure which is right, but we should be consistent.

Elsewhere in core there are always periods so here is a patch that adds them.

AdamPS’s picture

Status: Reviewed & tested by the community » Needs review

Status: Needs review » Needs work

The last submitted patch, 122: entity.title-2941208-122.patch, failed testing. View results

Spokje’s picture

Status: Needs work » Needs review

Test fail looks like a random test failure. Ordered a retest to make sure.

jonathanshaw’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 122: entity.title-2941208-122.patch, failed testing. View results

benjifisher’s picture

Please do not ask the testbot to try again until #3207086: [HEAD BROKEN] Consistent failure in MonthDatePluginTest is fixed.

alexpott’s picture

Status: Needs work » Reviewed & tested by the community

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.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 122: entity.title-2941208-122.patch, failed testing. View results

catch’s picture

Status: Needs work » Reviewed & tested by the community

Restoring status after HEAD was broken.

AdamPS’s picture

Status: Needs review » Reviewed & tested by the community

It's only a reroll, basically exactly the same patch as before so putting back to RTBC

Rinku Jacob 13’s picture

patch #133 successfully applied for drupal 9.3.x-dev. thank's @AdamPS

andypost’s picture

andypost’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll
andypost’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
3.15 KB
8.59 KB

re-roll

jonathanshaw’s picture

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

+++ b/core/themes/stable/templates/field/entity-page-title.html.twig
@@ -0,0 +1,15 @@
+ * Theme override for entity page title.

+++ b/core/themes/stable9/templates/field/entity-page-title.html.twig
@@ -0,0 +1,15 @@
+ * Theme override for entity page title.

probably this files should be added to test core/tests/Drupal/KernelTests/Core/Theme/ConfirmClassyCopiesTest.php but it needs frontend review

AdamPS’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
10.29 KB

Re-roll

dpi’s picture

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

dpi’s picture

Rerolled/rebased on 9.4.x, resolved conflicts after #3138078: [D9.3 beta - w/c Nov 8, 2021] Add a 'void' return typehint to custom assert* methods.

Patch from MR also applies to 9.3.0-rc1

andypost’s picture

+++ b/core/themes/stable/templates/field/entity-page-title.html.twig
@@ -0,0 +1,15 @@
+ * Theme override for entity page title.
...
+<span{{ attributes }}>
+  {{ title }}
+</span>

+++ b/core/themes/stable9/templates/field/entity-page-title.html.twig
@@ -0,0 +1,15 @@
+ * Theme override for entity page title.
...
+<span{{ attributes }}>
+  {{ title }}
+</span>

it needs review, probably stable[9] should not be changed

jonathanshaw’s picture

Status: Needs review » Needs work

I think #142 may be a bad reroll, it seems to revert changes introduced by #2993647: Correctly determine when to display fields as inline in EntityViewController.

AdamPS’s picture

Status: Needs work » Needs review
FileSize
10.6 KB

Very well spotted, thanks @jonathanshaw

AdamPS’s picture

@andypost
# 145

it needs review, probably stable[9] should not be changed

I believe there were earlier patches without changing stable9 and they failed.

#140

probably this files should be added to test core/tests/Drupal/KernelTests/Core/Theme/ConfirmClassyCopiesTest.php but it needs frontend review

But the patch doesn't add a template to classy??

Anyway as you say, this will get frontend review and they can guide us. If someone could set RTBC please then I have found this attracts the attention of the reviewer.

dpi’s picture

Yikes, thanks @jonathanshaw. Should we be concerned tests still passed?

I applied the patch from #147 to the MR.

I noticed and reverted an unintentional change in 147 to the :void return type for \Drupal\Tests\node\Functional\NodeDisplayConfigurableTest::assertNodeHtml, originally added by #3138078: [D9.3 beta - w/c Nov 8, 2021] Add a 'void' return typehint to custom assert* methods

AdamPS’s picture

Yikes, thanks @jonathanshaw. Should we be concerned tests still passed?

Yes I thought the same. I checked and the situation is that the test enables both features at once: enable_base_field_custom_preprocess_skipping and enable_page_title_template. I feel this is the most likely situation, which will occur when using manage_display module, and it is what we are eventually aiming for in core. It would be awkward to test all the combinations of flags as you would need a testing module for each flag.

I noticed and reverted an unintentional change in 147

Thanks

jonathanshaw’s picture

Status: Needs review » Reviewed & tested by the community
Martijn de Wit’s picture

is it possible to bring this also back to 9.3 or is it already to late because it is in beta already ?

andypost’s picture

As a bug it needs backport but probably to 9.3.1

delacosta456’s picture

hi is this also working for D8.9.20.. i am trying to apply patch but not working

imclean’s picture

@delacosta456, judging by #153 it could be available for 9.3.1, but Drupal 8 is no longer supported.

larowlan’s picture

Final observations, none of this is actionable.

I think the only thing missing here is to get the 'Needs frontend framework manager review' tag removed so that requires another look from @lauriii - I'll ping him.

I discussed this issue with @catch and his preference was that if this were to go into 9.4, sooner would be better.

  • +++ b/core/lib/Drupal/Core/Entity/Controller/EntityViewController.php
    @@ -55,6 +55,19 @@ public static function create(ContainerInterface $container) {
    +   *   back-compatibility to support sites that expect attributes set on the
    

    nit: I think we typically use 'backwards-compatibility' rather than just 'back'

  • +++ b/core/lib/Drupal/Core/Entity/Controller/EntityViewController.php
    @@ -64,18 +77,37 @@ public static function create(ContainerInterface $container) {
    +        $page_title = [
    +          '#theme' => 'entity_page_title',
    +          '#title' => $entity->label(),
    +          '#entity' => $entity,
    +          '#view_mode' => $page['#view_mode'],
    +        ];
    +        $page['#title'] = $this->renderer->render($page_title);
    

    technically a module/theme can implement hook_preprocess_page_title and alter the passed $variables to add additional cache metadata by way of the #cache key (and similarly for #attached) should we be instead rendering this in a render context and collecting any updated cache metadata, then attaching it to the returned render array?

    I guess we weren't doing it before hand, so that can be a followup

  • +++ b/core/lib/Drupal/Core/Entity/Controller/EntityViewController.php
    @@ -64,18 +77,37 @@ public static function create(ContainerInterface $container) {
    +      else {
    

    micronit: we can return $page and skip the else here (👊 my campaign against else/elseif continues!)

  • +++ b/core/modules/quickedit/quickedit.module
    @@ -128,6 +128,23 @@ function quickedit_preprocess_page_title(&$variables) {
    +  $variables['#cache']['contexts'][] = 'user.permissions';
    +  $entity = $variables['entity'];
    

    ah, but we're adding a concrete preprocess that adds new cache contexts, so perhaps we should collect the bubbleable metadata...

    although user.permissions is a required cache context (on all but the most custom of sites) so its probably still something we can defer to a follow-up

  • lauriii’s picture

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

    I added one comment on the MR - overall I think this looks great. The draft CR also looks great. Looking forward to working on #3015623: Remove outdated code relating to "Expose Title in Manage Display" 😁

    Tagging with needs follow-up because of #156.

    AdamPS’s picture

    Status: Needs work » Needs review
    Issue tags: -Needs followup

    Great thanks @larowlan and @lauriii.

    I have made the changes recommended except the ones listed for follow-up.

    jonathanshaw’s picture

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

    Status: Reviewed & tested by the community » Needs review

    Sorry I only put the new comment in one of the copies of the template - now fixed

    jonathanshaw’s picture

    Status: Needs review » Reviewed & tested by the community

    Whoops, confirmed.

    larowlan’s picture

    Issue tags: +Bug Smash Initiative

    This looks good to go to me.

    Queued a test run against 10.0.x - good news is it applied cleanly (at least with a -3)

    Once we get a green run on 10.0.x I'll commit this.

    Thanks @AdamPS and @jonathanshaw for your perseverance here, having an issue on and off RTBC for 3 years is a mammoth effort.

    Adding commit credits for folks I've spoken to about this or who have left reviews above.

    • larowlan committed 96ef832 on 10.0.x
      Issue #2941208 by AdamPS, dpi, sja112, aleevas, andypost, anmolgoyal74,...

    • larowlan committed 22ef75a on 9.4.x
      Issue #2941208 by AdamPS, dpi, sja112, aleevas, andypost, anmolgoyal74,...
    larowlan’s picture

    Status: Reviewed & tested by the community » Fixed

    Committed 96ef832 and pushed to 10.0.x.

    Cherry-picked to 9.4.x

    Published the change record.

    Thanks again for the perseverance here folks

    AdamPS’s picture

    Great many thanks @larowlan for finding time in your busy schedule to get this one in. The user-base of the "Manage Display" module will appreciate this significant step forwards.

    There is one more step to removing the obstacles in Core and the issue is also RTBC #3090187: Mechanism to disable preprocessing of base fields in comment entity type so they can be configured via the field UI.

    Hopefully a simpler one, and we would greatly appreciate the attention of any core committers who might be able to help.

    larowlan’s picture

    Will give it a follow

    Status: Fixed » Closed (fixed)

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

    Nigel Cunningham’s picture

    Good morning all.

    Is there some way that we could have found this change without the dev doing the upgrade to Drupal 9.4 spending a long time stepping through the code? We are using a custom twig template for media, and the titles disappeared post-upgrade due to the #access = FALSE change. Looking through https://www.drupal.org/project/drupal/releases/9.4.0, I don't see anything related to titles so I'm wanting to check whether there's a more efficient way of discovering the cause of such issues that I could have suggested to him.

    Regards,

    Nigel