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.
- HTML tags in page title: buildTitle escapes them, but template_preprocess_html strips them.
- 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
- The code for putting field into page title is already somewhat complex and mysterious.
- 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.
- 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.
- 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.)
Comment | File | Size | Author |
---|---|---|---|
#147 | entity.title-2941208-147.patch | 10.6 KB | AdamPS |
Issue fork drupal-2941208
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:
Comments
Comment #2
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedComment #3
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedFirst patch that simply removes buildTitle - let's see if anything breaks.
Comment #4
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedComment #6
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedComment #7
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedNew patch matches solution added to IS
Comment #9
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedComment #10
jonathanshawWorth noting that the current approach was introduced for performance reasons in #2498849: Entity view controller title rendering is expensive.
Comment #11
jonathanshawThis 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.
Comment #12
AdamPS CreditAttribution: AdamPS at AlbanyWeb commented@jonathanshaw
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.
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.
Comment #13
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedOK, updated IS with my new idea as solution 1. Old idea demoted to solution 2.
Comment #14
jonathanshawI 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:
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.
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.
Comment #15
AdamPS CreditAttribution: AdamPS at AlbanyWeb commented@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.
Comment #16
jonathanshawSorry 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.
Comment #17
AdamPS CreditAttribution: AdamPS at AlbanyWeb commented@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...
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).
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....
Please can you explain why you feel that way? I would say that buildTitle neatly solves two jobs:
I agree - the title block should control printing of its own content and nothing outside that.
Comment #18
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedNew patch based on new solution 1.
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.
Comment #20
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedComment #22
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedComment #23
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedThe 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 #24
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedComment #26
jofitz CreditAttribution: jofitz at ComputerMinds commentedRe-rolled the patch from #22 against the latest codebase.
Comment #28
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedComment #29
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedBringing 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).
Comment #30
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedOK, 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.
Comment #31
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedComment #32
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedActually 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.
Comment #34
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedComment #36
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedComment #37
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedComment #38
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedComment #40
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedComment #41
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedSimplified 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).
Comment #43
jonathanshawAdam 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.
Comment #44
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedThanks @jonathanshaw. Let's see if I can help at all. Firstly in terms of your background OOTB I would say it like this:
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.
Is it really so hard?
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.
Comment #45
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedCreate a separate issue #3043592: Allow entity to display label field as normal.
Comment #46
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedAnother 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:
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.
Comment #47
jonathanshaw@AdamPS has explored this problem space very thoroughly, and it tested in contrib in the 'Manage display' module.
Comment #48
larowlanI 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.
Comment #49
AdamPS CreditAttribution: AdamPS at AlbanyWeb commented@larowlan Thanks for the review - here is an updated patch.
Comment #50
jonathanshawComment #52
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedRandom fail
Comment #53
plachJust a quick code review, I still need to have a closer look.
This is missing a
$entity instanceof RevisionableInterface
check.Comment #54
plachThanks for the thorough issue summary and careful planning, I think we are very close here!
I think we should do
$page[$label_field]['#access'] = FALSE
here for two reasons:enable_page_title_template
flag is set and theenable_base_field_custom_preprocess_skipping
is not, the following notice is raised for nodes: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
anduser
entity types.As mentioned in #53, this is missing an
$entity instanceof RevisionableInterface
check.Comment #55
plachThis will also require a change record.
Comment #56
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedMany 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
Comment #57
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedComment #58
jonathanshawI also struggle to understand how and why to implement #54.2
Comment #59
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedClarification 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:
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.
Comment #60
lauriiiI'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?
I would love if we could add an explanation of why we are doing this as well.
Comment #61
jonathanshaw@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.
Comment #62
AdamPS CreditAttribution: AdamPS at AlbanyWeb commented@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.
Comment #63
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedComment #64
jonathanshawComment #66
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedThis 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?
Comment #67
Nick_vhSame as #2993647. Maybe good feedback, but at Dropsolid we are waiting anxiously on these commits to happen. Ideally before 9 gets released.
Comment #69
xjmThis 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!
Comment #70
aleevasAdded patch for 9.1 branch
Comment #72
aleevasTrying to fix failed test
Comment #74
sja112 CreditAttribution: sja112 at Srijan | A Material+ Company for Drupal India Association commentedFixing 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.
Comment #75
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedThanks @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?
Comment #76
sja112 CreditAttribution: sja112 at Srijan | A Material+ Company for Drupal India Association commented@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
If so then we can remove/modify this test?
Comment #77
jonathanshaw@sja112 do you think #72 is right? It didn't fix the test in the way it intended to.
Comment #78
sja112 CreditAttribution: sja112 at Srijan | A Material+ Company for Drupal India Association commented@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?
Comment #79
jonathanshawWhat 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.
Comment #80
sja112 CreditAttribution: sja112 at Srijan | A Material+ Company for Drupal India Association commented@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.
Comment #81
jonathanshawSeems right. Thanks @sja112!
Comment #82
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedHmm 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.
Comment #83
jonathanshawAccording to [#2580687]:
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.
Comment #84
jonathanshawComment #85
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedI 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?
Comment #86
jonathanshawI 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:
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.
This should be changed to:
Comment #87
jonathanshawComment #88
AdamPS CreditAttribution: AdamPS at AlbanyWeb commented@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.
Comment #89
aleevas@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!
Comment #90
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedThanks @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.Comment #91
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedLet's try like this
Comment #92
jonathanshawYay!
Comment #93
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedFor other entities there might not be a langcode field so let's do it like this instead
Comment #94
jonathanshawMakes sense.
Comment #96
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedFail was just a random
Comment #99
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedJust a random fail
Comment #100
MrPaulDriver CreditAttribution: MrPaulDriver commentedThis has been a long time coming. Are we nearly there yet?
Comment #101
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedThis 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.
Comment #102
DuaelFrThank you all for the great work here!
Let's try to trigger some subsystem maintainer and commiter with a few tags they might follow.
Comment #103
MrPaulDriver CreditAttribution: MrPaulDriver commentedComment #104
MrPaulDriver CreditAttribution: MrPaulDriver commentedComment #105
catchI 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.
Comment #106
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedThanks @catch
Comment #107
SpokjeRe-uploading
entity.title-2941208-93.patch
so it gets retested every 2 days against9.2.x-dev
.Currently it's tested every 2 days against
9.1.x-dev
.Comment #108
alexpottWe should have documented
enable_base_field_custom_preprocess_skipping
better when we added it. This issue is addingenable_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?
Comment #109
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedThanks @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 fortemplate_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 onEntityViewController::buildTitle()
.Comment #110
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedComment #111
jonathanshawThere'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.
There's also
But if we want to document additional properties, maybe that should be a seperate issue.
Comment #112
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedThanks @jonathanshaw
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.Comment #113
jonathanshawNice
Comment #114
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedBeg 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)Comment #115
jonathanshawMaybe 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.We're missing the entity and view_mode variables from the comments on the template. NW for that.
Comment #116
sja112 CreditAttribution: sja112 at Srijan | A Material+ Company for Drupal India Association commentedAdded missing the entity and view_mode variables from the comments on the template.
Comment #117
sja112 CreditAttribution: sja112 at Srijan | A Material+ Company for Drupal India Association commentedComment #118
sja112 CreditAttribution: sja112 at Srijan | A Material+ Company for Drupal India Association commentedComment #119
jonathanshawThere'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.
Comment #120
anmolgoyal74 CreditAttribution: anmolgoyal74 at OpenSense Labs for DrupalFit commentedAdded to remaining templates as well.
Comment #121
jonathanshawComment #122
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedElsewhere in core there are always periods so here is a patch that adds them.
Comment #123
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedComment #125
SpokjeTest fail looks like a random test failure. Ordered a retest to make sure.
Comment #126
jonathanshawComment #128
benjifisherPlease do not ask the testbot to try again until #3207086: [HEAD BROKEN] Consistent failure in MonthDatePluginTest is fixed.
Comment #129
alexpott#3207086: [HEAD BROKEN] Consistent failure in MonthDatePluginTest is fixed.
Comment #132
catchRestoring status after HEAD was broken.
Comment #133
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedReroll
Comment #134
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedIt's only a reroll, basically exactly the same patch as before so putting back to RTBC
Comment #135
Rinku Jacob 13 CreditAttribution: Rinku Jacob 13 at Zyxware Technologies commentedpatch #133 successfully applied for drupal 9.3.x-dev. thank's @AdamPS
Comment #136
andypostComment #137
andypostComment #138
andypostre-roll
Comment #139
jonathanshawComment #140
andypostprobably this files should be added to test
core/tests/Drupal/KernelTests/Core/Theme/ConfirmClassyCopiesTest.php
but it needs frontend reviewComment #141
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedRe-roll
Comment #142
dpiComment #144
dpiRerolled/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
Comment #145
andypostit needs review, probably stable[9] should not be changed
Comment #146
jonathanshawI 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.
Comment #147
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedVery well spotted, thanks @jonathanshaw
Comment #148
AdamPS CreditAttribution: AdamPS at AlbanyWeb commented@andypost
# 145
I believe there were earlier patches without changing stable9 and they failed.
#140
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.
Comment #149
dpiYikes, 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* methodsComment #150
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedYes 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.
Thanks
Comment #151
jonathanshawComment #152
Martijn de Witis it possible to bring this also back to 9.3 or is it already to late because it is in beta already ?
Comment #153
andypostAs a bug it needs backport but probably to 9.3.1
Comment #154
delacosta456 CreditAttribution: delacosta456 commentedhi is this also working for D8.9.20.. i am trying to apply patch but not working
Comment #155
imclean CreditAttribution: imclean at Digital Ink commented@delacosta456, judging by #153 it could be available for 9.3.1, but Drupal 8 is no longer supported.
Comment #156
larowlanFinal 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.
nit: I think we typically use 'backwards-compatibility' rather than just 'back'
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
micronit: we can return $page and skip the else here (👊 my campaign against else/elseif continues!)
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
Comment #157
lauriiiI 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.
Comment #158
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedGreat thanks @larowlan and @lauriii.
I have made the changes recommended except the ones listed for follow-up.
Comment #159
jonathanshawComment #160
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedSorry I only put the new comment in one of the copies of the template - now fixed
Comment #161
jonathanshawWhoops, confirmed.
Comment #162
larowlanThis 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.
Comment #165
larowlanCommitted 96ef832 and pushed to 10.0.x.
Cherry-picked to 9.4.x
Published the change record.
Thanks again for the perseverance here folks
Comment #166
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedGreat 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.
Comment #167
larowlanWill give it a follow
Comment #169
Nigel CunninghamGood 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