Problem/Motivation
As discussed in #2353867: [META] Expose Title and other base fields in Manage Display, sitebuilders cannot configure the display of node's title even though they often want to.
Worse, even if developers use a hook to modify the node's title field adding ->setDisplayConfigurable('view', TRUE), and a sitebuilder then enables the title field in a view mode, it makes no difference. The template_preprocess_node and the node.html.twig take over the rendering of the node's title, ignoring the configured view displays. The same problem applies to the 'created' and 'uid' fields.
This issue has been split from #2353867: [META] Expose Title and other base fields in Manage Display to contain minimal, back-compatible changes providing an important first step to solving the original problem.
Proposed resolution
Use an additional entity type property to allow disabling of extra preprocessing of node base fields (title, created and uid).
Remaining tasks
None.
This issue has been thoroughly reviewed including:
- Sub-system maintainer review by @lauriii in #97
- Expert review by @Berdir in #83
- Various community reviewers and testers (also see recent comments on #2353867)
User interface changes
None
API changes
Node title, uid and created fields are subject to special preprocessing that obstructs developers who wish to enable these fields to be configurable via the field UI. A module can now disable this preprocessing by means of an additional entity type property:
function XXX_entity_type_build(array &$entity_types) {
$entity_types['node']->set('enable_base_field_custom_preprocess_skipping', TRUE);
}
Using this feature requires an update to the node template to treat related variables as optional (label, author_name, date). Theme developers should update their themes to match the changes made in core. No changes are required for sites that do not use this feature.
Background explanation for API changes
We considered solving this issue without an additional entity type property. Earlier patches disabled the special preprocessing conditional on whether ->setDisplayConfigurable() had been called. The problem is that there are likely to be existing sites that call ->setDisplayConfigurable(), and workaround the existing bugs in a way that relies on the special preprocessing. By creating an additional entity type property, we guarantee not to break existing sites.
A second motivation for the additional entity type property is a wider goal for D9 and beyond to remove special cases as much as possible. We are aiming to have direct support in core for base fields configurable via the field UI. However it would still be possible for sites to override that if they preferred a hard-coded layout. So in D9 we want to remove the special preprocessing of base fields, yet retain the ability for sites to call ->setDisplayConfigurable(). Therefore the earlier patch that tied "special preprocessing" directly to "configurable via the field UI" was actually creating a problem for the future. The new approach allows D9 to remove the additional entity type property and corresponding special preprocessing yet retain ->setDisplayConfigurable().
Data model changes
None
Release notes snippet
It is now easier to make node base fields configurable via the field UI due to a mechanism to disable preprocessing of node base fields. This a step towards making title display configurable in Drupal Core and in the meantime there is a contrib module to enable it. These changes are fully back-compatible.
| Comment | File | Size | Author |
|---|---|---|---|
| #315 | title.display-D8.6-2923701-305.patch | 27.46 KB | adamps |
| #305 | title.display-2923701-305.patch | 27.91 KB | adamps |
Comments
Comment #2
jonathanshawPatch based on discussion with @AdamPS in #2353867: [META] Expose Title and other base fields in Manage Display.
Comment #3
jonathanshawSorry, previous patch malformed.
Comment #4
jonathanshawComment #7
jonathanshawAargh, first time using Windows powershell.
Comment #8
adamps commented@jonathanshaw great, that looks like the right way to do it. First I have some comments on the code in your patch.
1) In the template I think it would be clearer to name the new variable 'display_title'. This matches the existing 'display_submitted', and template writers and hook writers can see what the variable is for.
2) Templates don't need to test if the variable is defined as it will always be defined.
3) In this code
I propose to tidy up the =TRUE and =FALSE and tweak the comment.
4) Indent looks wrong
5) I think it's better not to fix the alignment of unrelated lines as it makes the patch harder to read
Comment #9
adamps commentedSecondly I would like to comment on what more code we might need to add.
field--node--title.html.twigmust obeylabel_hiddensame as infield.html.twig(but still don't need the bit for multiple), so something like the code below.Comment #10
adamps commentedOr except for classy I wonder if could we just delete field--node--title.html.twig? It's not clear to me how it gives different output from the base template.
Comment #11
adamps commentedAlso template_preprocess_node does
I guess we could consider fixing those in the same way??
Comment #12
adamps commentedSorry in #9 and #10 I've not got it right for the label - there are subtle differences between the ordinary field and the title field, so it will need a bit of juggling.
Comment #13
adamps commentedUnfortunately another complication.
In
\Drupal\Core\Entity\Controller\EntityViewController::buildTitleSo our customer display output ends up in
$page['#title']which means it goes into the title block, which tags, labels and everything. I guess you normally would hide the title block when overriding the title display for the full display mode, which would avoid the problem.As an alternative you might hide the title display for the full display mode and keep the block. This mostly works, but it has missed out on the purpose of EntityViewController::buildTitle:
Well I've got to dash now, but it's another thing to think about.
Comment #14
jonathanshaw#9/#10 - labels: hoping you can figure this out
#11 - other variables unset: let's push that to a follow-up and check all entities not just node.
#13 - the block.
Does this matter? What negative effect?
Comment #15
adamps commented#11 I feel enthusiastic to do it myself
#13 I think I have a solution.
@jonathanshaw Why don't you make all the changes that you can then I'll add my bit after.
Comment #16
jonathanshawI might not be able to for a few days, do move ahead if you can
Comment #17
adamps commentedHere's a new patch
After careful consideration, I have decided to have a clean split: if
isDisplayConfigurablethen don't do any special processing at all. In this case, the derived variables such as 'label' will be blank. Three reasons:template_preprocess_nodeshould 100% respect the configuration, and not alter anything. For example, callingrenderwould set the#printedflag and prevent display.$variables['node']->getTitle()- normally this variable is set to the a render array which can have a span and attributes.Changes from #7:
Not yet included: field--node--title.html.twig. I don't know the template system well. This template displays a string in a span which is only suitable if
!isDisplayConfigurable. Ideally I'd like to make some magic call to discount this template suggestion when the display is configurable and fallback to the default field template. Status: at the moment, enabling label for a title field only works with a customised template.Comment #19
adamps commentedCorrected version
Comment #21
adamps commentedFix again
Comment #23
jonathanshawThis comment seems wrong. I'm not sure what 'blank' is as a technical term. Elsewhere in core it seems to use "(optional)" for for optional twig arguments. How about
+ * - label: (optional) The title of the node, if its display is not configurable.This confuses me. Could it be
{% if label and not page %}?Could we move this hunk to be in the same block as the new comment about date, author_name and title?
This comment can't be quite right as we don't have a title formatter in core. How about "The formatter for the title field has provided ...". Or could this markup come from a somewhere other than a formatter, like a hook of some kind?
I don't get the purpose of this. Is it worth a comment?
I'm concerned about BC here. AFAICS if someone has enabled setDisplayConfigurable for the title field, but has not set #page_title (which they couldn't have known to do as it's new) then this change will hide their page title.
Agreed, your isDisplayConfigurable preserves BC and does not require a default. This is because if someone else had already enabled isDisplayConfigurable, they must have already have added ['label'] in their own preprocess or removed the need for it from their template - we don't have to worry about that.
.
Comment #24
adamps commentedThanks, good feedback, all done, except:
1) I propose that we go with
* - label: (optional) The title of the node.
4/5) I hope the comments are clearer now. The phrase "title field formatter" occurs in the existing code just a few lines earlier, meaning simply 'the formatter that is being used for the title field'. I changed my wording to match that.
6) No I think it's OK. The code only hides the title in two cases
Comment #25
adamps commentedI have expanded the issue summary to include
Comment #27
jonathanshaw#23.6
It's precisely the second case that worries me. Existing sites may already have explicitly disabled the title field, without expecting it to hide the title in the title block. In fact, wouldn't this be quite a normal existing case:
- setDisplayConfigurable to TRUE for title
- explicitly hide title on full view mode
- expect title to still appear in title block on full page view
Maybe I'm not understanding the purpose of this prerender callback properly.
I remain concerned about the scope creep in the introduction of taxonomy fixes in this patch. At the very least I think this needs a change of issue title, a mention in the IS, and a statement that we've searched the codebase to make sure the same issue is not present on any other core content entity. We either need to be node-only, or whole-of-core.
Comment #28
jonathanshaw#25 "I can't figure out the one broken test"
I tried it manually with the patch and can confirm it's broken (although didn't try without the patch):
- enable Aggregator
- create a feed like http://rss.cnn.com/rss/cnn_topstories.rss
- place a block of the feed
- run cron
- view the block
- click the "read more" link at bottom of block
- See no title on feed page :(
Comment #29
adamps commentedOK I understand now. However:
So I think we need to leave the code as in and cover it in the CR: up until now
setDisplayConfigurablewas not supported and the existing behavior "disabled" => "hidden from content, but get title block" was just chance and never intended.I think I had already done both:-)
I agree. I am aiming for the whole-of-core, but there might be edge-cases we ignore for specialist entities with unusual display. I have done some rough searching for other problems and didn't find any. However I didn't come up with a good strategy to find the problems. I would welcome anyone else searching, and am in favour of fixing them.
Good thinking, I'll try that way.
Comment #30
adamps commentedApologies you are right I was wrong. I was thinking about nodes, but there are many other entity types, such as, erm, Aggregators:-) I'll fix it tomorrow.
Comment #31
jonathanshawFor node, I'm concerned that developers might have ignored / not cared about / not noticed these issues, so could be completely ambushed by the title disappearing altogether.
My perspective is completely opposite. For me disabled on an entity view mode means disabled just in that rendered view mode; the title block is a completely different thing from the rendered view mode. In my mind the less they are entangled the better.
For example, I'm currently working on a contrib that allows you to specify a view mode to use in the title block. So that on a page I couldbe controlling the content of the title block using one view mode using the 'title' view mode and the content block using the 'full' view mode. Handy for something like events where the event date is crucial identifying information that should be shown right with the title.
Comment #32
adamps commentedOther entity types
I did a search for {{ title_prefix }} that seemed quite useful and we may need to look at:
Page titles
They are built as a render array into $page['#title'].
So we need a system for code to register callbacks for "entityPageTitle". It could get a bit complicated to manage the interactions - what if modules for both 3) and 4) are installed? You might say that ideally TitleFormatter would run it's special processing but based on the 'title' view mode.
Would it be easiest if we had an online chat do you think?
Comment #33
jonathanshawI searched for instances of template_process_ for entities that used ContentEntityInterface and found none apart from node and term that unset anything, so I think you've succeeded in covering core. Yay!
Re #31/32.4 in my example case I'm planning to replace the default title block not modify it with a hook, so I can take over its logic. It's not something we have to worry about here. I was just questioning the logic of
I can now see where you are coming from in terms of SBX - it might seem weird that moving the title to the disabled region doesn't make it disappear from the page. OTOH it's not any weirder than the fact that the title shows at the top of the page regardless of where you position it amidst the other fields.
My thinking is that the only really clean solution (way out of scope, D9 probably) would seem to be to add a title region to the full display mode and put the title in that. For this issue I suggest we keep things as minimal and BC as possible. After all we're not making the title field display configurable here - we're just removing the nastiest obstacles to that in core. If someone wants to set DisplayConfigurable and have the configured title field interact with the block title in some excellent way, they can make their own custom title block for that.
I'm happy to chat, though not sure it's needed. You can message me through d.o
Comment #34
adamps commentedI'll respond properly to that last comment tomorrow, but I agree it sounds like in fact we don't need to chat. In the meantime I have a new patch that should fix the last test.
I agree, but I'm keen to make the final step for a module to get configurable titles as easy as possible. The latest patch now includes the TitleFormatter class which I feel is generic, slightly tricky and we don't want each module to have to reinvent the wheel. I think that now all it takes to get configurable titles is a single call to
setDisplayConfigurable.Comment #35
adamps commentedIn this comment I'll answer the UX for the default scenario - setting aside legacy, module hooks and so on. I have tried quite a few different options and the current UX seems by far the best. To test out this experience either hook setDisplayConfigurable or install Manage Display module.
For the page title, the site-builder can choose from three options:
Two UX questions related to each other:
Some technical problems:
So absolutely feel free to suggest modifications to the UX, but they need to encompass all of the above, and bear in mind that I have tried a lot of different things already:-)
Comment #36
adamps commented@jonathanshaw Thanks for that check.
I concluded that aggregator-feed did need handling even though it didn't have an unset, so this latest patch adds that in.
Comment #37
adamps commentedPlease can someone review the change record [2925634]
Comment #38
adamps commentedI nearly forgot the node title templates. Up until now there was bad markup with h2 inside span, and the label would not display.
This patch fixes that, falling back to field.html.twig if the title is a "real field" that has come from "Manage Display".
Comment #39
adamps commentedOops fix some warnings
Comment #41
eelkeblokI've been checking out the patch and the manage_display module in the last few days and I must say I very much like where this is going. I was struggling a bit with the behaviour of the submitted block. It seems that it is only available when the "Display author and date information" option is enabled for the node type, but when it is, it does not take into account whether the pseudo field is actually hidden.
Does it make sense to drop the checkbox completely and allow the pseudo field to control whether the submiited data is shown at all? If not, at least I think moving the field to disabled should also hide it.
Edit: Actually, the checkbox seems to now only control whether the pseudo field is shown, not whether the information is printed. WIth the patch and module installed, I can't seem to get rid of the submitted data that is added by the module.
Comment #43
adamps commented@eelkeblok Thanks for taking a look. The submitted data is awkward because it has information from two fields interleaved, so it didn't really fit the pattern all the other fields follow. Please do raise an issue on the manage_display queue and we can take it forward there.
The manage_display module is still a rough first go at the moment, with my intention being to have something that can be used to test out this patch. Until this patch is accepted, or at least it seems likely that it will be accepted, then the module isn't much use! Hence I don't plan to work on manage_display issues until the patch has been looked at by the core committers.
Comment #44
adamps commentedPlease can someone set the status to RTBC?
The code is complete as far as I know, has been reviewed by @jonathanshaw, and tested by several people. Of course I am aware that there are no tests yet. However I think we have reached the stage where we should get input from the core committers to check they are willing to accept a patch like this and that there are no major flaws.
Comment #45
rootworkSo excited for this. Thanks for all your hard work here @AdamPS and @jonathanshaw!
Comment #47
adamps commentedFix the coding standard problem as per codesniffer patch.
I suspect the test failures might be unrelated to this patch to hopefully they will go away.
Comment #49
jonathanshawThe test failures seem to be about the title on media entities, probably a useful indication of a BC oversight in the patch.
Comment #50
adamps commentedI still can't see any connection with the patch. I get strange errors when I try to run on my server. If anyone else can figure it out that would be a big help.
I still think it might be just an odd random error, so I will try to re-test it.
Comment #51
adamps commentedOK, so I have made some progress.
Firstly there seems to be a bug in 8.6.x. If a test fails, then the code crashes when trying to display the error. This is unrelated to the patch here.
Secondly, there is a BC problem with the media entity tests. The media entity currently has a configuration directly in conflict with the strategy of this issue.
That seems wrong to me.
Next steps:
Comment #52
adamps commentedUpdated patch with a hack for media. I am aware that it cannot be committed like this. The current goal is to get an initial review from a core committer that the general approach is valid and find any significant problems in the code. Please can someone set RTBC to bring this to the attention of the core committers?
Comment #53
adamps commentedThe media problems were introduced in #2930788: Do not show name by default in media displays.
Here is an updated patch that is a much more plausible actual solution. I have changed the Media Entity to use the new title formatter by default.
Comment #55
adamps commentedOK, I'll hide #53 for now, and ask for review of #52.
Comment #56
adamps commentedOK, with a bit more time to consider it I think @jonathanshaw is right about the BC problem he raised particularly in #27. On the other hand, I still think I was right with my answer about how the obvious alternatives didn't really work either. Hopefully my new solution is the best of both worlds.
I have removed the risky else case from EntityViewController and add code in TitleFormatter to compensate. There is a new checkbox to allow the "normal" output to be disabled independently of the block.
Review comments welcome please. Interdiff is still against #47 which is the last version that anyone removed, and seems the clearest (the intervening patches basically adding stuff then discarding it again).
Comment #57
samvel commentedHi guys,
It looks strange. May be better use next way:
Comment #58
samvel commentedI mean that it looks strange in translation interface. Better use whole phrases.
Comment #59
eelkeblokBoth are not correct. When you tack on a part of a sentence like this, you are making assumptions about word order, which may not be valid in other languages. You need to have two distinct versions of the translatable string, i.e.:
Although I haven't looked at the code in context, you might also need a period in the string (I've added one, it looks like the sort of string that needs one), which is trivial in this new form, but troublesome in the old.
Edit: I just realised samvel's version has more or less the same effect for the original strings. However, this goes against another translation guideline which says you should not pass variables as translatable strings, because it prevents automatic extraction tools from finding the translatable string.
Comment #60
adamps commentedNew patch:
Comment #62
adamps commentedNew patch fixes coding standards. Surely the ContextualLinksTest failure can't be related to this patch?? I'm finding the tests don't work well in 8.6.x on my server right now.
Comment #63
jonathanshawYou've steered this issue so it now tackles two problems:
A. allowing more entity display fields to be fully configurable (so that node titles can be configured like other fields)
B. making the behavior of page titles not too confusing when title fields are configurable (so there aren't duplicate titles in the block and the field)
The problem of the page title is hard. I can't see a truly good solution, it's like an intrinsic weak spot in Drupal's site-building model.
Possible solutions include:
1. Control the page title via settings on the title formatter on the entity display UI
2. Require the existence of a "page title" region on full/default view modes
3. Require the existence of a "page title" display mode
4. Present additional "page title" settings, either at the top of the UI for the full/default view modes, or in the settings at the bottom of all view modes.
You've done a great proof-of-concept job at showing how the first approach would work. This approach has the great virtues of being hard for sitebuilders to misconfigure and not increasing UI complication.
It also has a lot I don't like. It relies on an invisible magic snowflake to link the page title block and the canonical entity display, unrelated things from different region; someone who knew Drupal architecture from first principles would never guess it worked this way, and would it confuse the mental model of learning site builders. Furthermore the snowflake further complicates the overall situation, deepening the kind of tangle that caused this issue in the first place.
I'm not saying I know a better solution. But because of the problems with the proposed solution, and way the solution touches on a complex intersection of entity, theming, usability and backwards compatibility, it's going to be very very hard to get someone to commit it. I think you'll be here for years and years.
I suggest a 2 pronged approach:
- Spin up a new issue dedicated to the first of the two problems (the one I originally opened this issue to address), and tackle in core the bare minimum that is necessary to make custom development easier and to allow contrib to satisfactorily solve the second problem.
- Try to get people from the layout initiative interested in engaging with this question. It's very very close to the kind of concerns they have. #2884601: Add a Layout Builder to core
I'm really glad you're pursuing this question - I think this is a big Drupal WTF. I'm just trying to suggest how to get the best progress based on what I observe of core development.
I'll try tagging this for product manager review on the off-chance that attracts some direction.
Comment #64
adamps commented@jonathanshaw Wow #63 comes as a big surprise. I had the impression that we were more closely aligned in our thinking.
1 Scope
Please - no new issues. I am 100% with you on your original purpose for this issue:
Hence I claim that "get people from the layout initiative interested" and your points starting "Possible solutions include" are firmly out of scope.
If you feel some parts of the patch don't belong then please give specific review feedback i.e. identifying files and line numbers. If you haven't already looked at the manage_display module then I strongly encourage you to do so. Each of the bits of code in the current patch comes from a specific way in which core blocked writing of the module.
Note that the issue summary lays out the solution in 3 parts.
2 Goals and timescales
My intention here is to create a working non-contentious fully BC patch that can be committed to D8.6. I think this is feasible given the scope - we are not trying to set out the next generation correct solution to the wider problem, but rather removing some very specific obstacles in an entirely BC way as an interim working position.
Please review it on that basis and give specific feedback (rather than vague and discouraging essays about snowflakes:-)).
3 Wider review
I believe that once we have RTBC status we can get attention from a core committer. I feel it's best to leave the setting of that sort of tag to the small group of people whom it primarily concerns.
Comment #65
jonathanshawThanks for laying that rationale out again Adam - it really helped me to get much closer to being on board with you here.
Yes, I think they're awesome.
This is where I begin to get nervous, but I believe you that it's necessary to do something. I think it would help me and other reviewers if you spelled out in the IS in what circumstances these problems arise, what the code chain is that triggers them, and why your solution is the minimal effective one. Also why these problems must be tackled at the same time as the template problems, not in a separate issue.
I would definitely recommend punting it to a follow-up issue or contrib. The bigger the issue, the harder to get reviewed and committed.
This logic flow is really difficult to understand. Can it be re-engineered to remove the $skip_render? I think it could if the last line was moved to the top. This might also allow the comment to be broken up to explain things more step-by step.
I can't immediately understand the purposes of these two settings based on these descriptions.
Core is very minimal in the settings it provides on it's formatters. Both class and tag should probably be removed.
I suggest checking the entity reference formatter for what summary it uses when linking.
The comment feels confusing. Presumably the field's machine name is not title? In which case, let's use that.
Again, better to use field's machine name.
I think both the comment, and the name #title_as_field, show a problem. They make sense now when we feel like we're wrestling with an existing way of doing things. But they're not optimal for someone in the future who doesn't have that history. It's the page title that's really the special case. Is it possible to present things that way?
Also referencing the way the template works from inside the preprocess seems wrong. If we're doing a weird dance with the template for BC reasons, let's say that explicitly.
"If the name field is not configurable, make it available separately."
Let's not use the word 'form' in this context.
Regression/omission: you fixed this before for another template. Should be '(optional)' not '(blank)'?
Comment #66
adamps commented@jonathanshaw Thanks for detailed comments, good ideas. I have update the IS, hopefully that is clearer now.
1 There are two detailed comments already but nevertheless I have added some more. I cannot see how to avoid $skip_render except by confusing duplication of the line of code with the call to render - NB it is vital not to call render in the $skip_render case. I don't really grasp your objection - there is a simple boolean variable skip_render that has an obvious effect. The variable is needed because of nested ifs.
2-4 I have removed TitleFormatter.php.
5-6 I was already using the field's machine name - it was simply that I had chosen to put the field name in quotes. I am no longer doing that, and I have also applied your wording from 8 here too.
7 I had a go to rework it (in module and templates).
8 Done
9 I had a go to reword (same for two other files).
10 Done, well spotted (fixed in several places in that file).
Especially for 1,7,9 if you don't think I've got it right, please can you be exact about what you would prefer so I don't have to just keep guessing.
It would be feasible to create a separate issue, but I don't prefer it. It seems simpler and clearer to tackle the entirety of the problem in one go. The one case where I would agree to split the issue is if a core committer agreed to commit some but not all of the patch - I agree something would be better than nothing. However I don't see how we can know that this will occur, and if so exactly which parts to include.
Comment #67
adamps commentedNew patch uploaded for review. Would be amazing to get this to RTBC.
Comment #69
jonathanshawIt took me half and hour to figure out why we had both
if (isset($page[$label_field]['#page_title']))andif ($page[$label_field]['#page_title']).The way you're using #page_title to hold either an alternate render array or an instruction to suppress the title's rendering altogether surprised me.
Maybe this is easier to understand:
I thought the field's machine names were 'created' and 'uid' not 'date' and 'author_name'?
This seems wrong; it makes isDisplayConfigurable=TRUE lead to #inline_title=TRUE. And shouldn't we be setting #inline_title on $variables['label']?
How about something like:
+ if (!$node->title->getFieldDefinition()->isDisplayConfigurable('view')) {
+ $variables['label'] = $variables['elements']['title'];
+ unset($variables['elements']['title']);
+ // The node template will apply its own markup around the label.
+ // Therefore the node title template needs to be instructed to only
+ // generate inline markup in this situation.
+ // @todo Simplify the node template in D9
+ $variables['label']['#inline_title'] = TRUE;
+ }
Is it OK to leave #inline_title unset when it's not needed?
I'm a bit worried about BC here. What happens if someone has currently has a custom node title template? And a custom node template and custom node title template. Needs thinking through.
Comment #70
adamps commented@jonathanshaw Thanks 1-3 done with minor tweaks to comment wording. Fixing (3) fixes the tests.
Yes looks like we can - done
Good point, and I believe have already thought it through. That person is 100% fine provided that they don't enable setDisplayConfigurable on the node title. If they want the new function then they need to fix their custom templates in line with core. There is a CR draft attached to this issue with text explaining this.
Comment #71
adamps commentedI have asked on drupal answers to see if anyone can help simply the awkward code in EntityViewController.
Comment #73
jonathanshawI'm still not properly understanding these two issues. What causes them and why there are no other solutions.
Seems like we've got 2 problems we're working on:
1. Controlling the title outside of full page contexts
2. Controlling the title inside full page routes
We got the first one sorted. The second one is harder.
I'm not at all convinced that we should be influencing the page title from the entity display mode UI. But I take your point that buildTitle is suppressing further display of the label indiscriminately, regardless of the how the title block is set up. The code stems back to #2498849: Entity view controller title rendering is expensive.
One possible solution:
- reset #printed after rendering in buildTitle (or render a clone to avoid it).
- have an entity preprocess hook or prerender callback, such that any time an entity is being rendered checks if this is a full page context, and sets #printed on the label field if it is.
My favorite solution is: do nothing. If you need to render the title amongst other fields in the main content region on a full page display, then you'll need to have a custom entity preprocess hook that sets #printed=false. Would that work?
Regarding the "h2 inside span in the title block", could we fix that by a custom buildTitle on the NodeViewController that added the #inline_title property?
Comment #74
adamps commentedOn the contrary, I hope there are, and the IS states: This is the best solution we can see given the BC requirement - we would welcome any neater suggestion.
@jonathanshaw I think you need to actually start trying some of your candidate solutions in code and then you will start to understand it more fully. At the moment it seems to me that your alternatives either won't work, or are much more hacky than the current solution.
For b) you are along the right lines that the problem relates to #printed. You cannot arbitrarily reset it though or you will start to get double titles in other cases. I feel that manually setting #printed is a big hack to be avoided. The currently solution is carefully to do the better thing which is to avoid rendering the field and needless triggering #printed.
Thanks to your suggestion to move the TitleFormatter out, this patch no longer contains the code that does that.
Don't forget that this issue applies to all entity types, not just nodes.
Comment #75
adamps commentedFixed one further remaining bug introduced with the recent code simplifications - I had forgotten one case with #inline_title.
Comment #76
adamps commentedOK, I have become convinced to split off the changes in EntityViewController to a separate issue #2941208: Title formatting broken due to flawed EntityViewController->buildTitle. This means we have separated off the remaining complicated/untidy part as @jonathanshaw requested.
The extra information that persuaded me that this is a good split is that I discovered the problems now in the other issue are wider than what we are doing here - i.e. it affects people even if they aren't trying to hook setDisplayConfigurable.
The downside is that users wanting to use the manage_display module will need to take patches from both issues. I'll update manage_display documentation to make that clear once I have all the patches in place.
@jonathanshaw - I hope this means that you will now be willing to set RTBC,
Comment #77
adamps commentedMinor addition to #76 patch to flag lines that can hopefully later be removed.
Comment #79
adamps commentedThat last test fail was just a glitch
Comment #80
jonathanshawObviously we still need tests, but it seems fair to ask a committer to sanction the basic approach before the tests are written.
I'm leaving this set to the 'node' component as this is the most heavily affected.
Comment #81
adamps commented@jonathanshaw Excellent thanks. I updated the IS somewhat.
(essentially to remove detail and leave the reader to refer to the related issue. The detail that was previously present was only part of the problem and the reference to view modes was a slight red herring - view modes are entity-type specific and there is not a guaranteed correspondence with "own-page").
Comment #82
adamps commentedOops sorry accidentally changed the status from browser caching field values - reverting.
Comment #83
berdirLets not rely on __get() for those fields, $feed->getFieldDefinition('title') is IMHO nicer and even a bit shorter.
what does this mean for $variables['display_submitted'] = $node_type->displaySubmitted(); exactly?
I see that you in the template check for all three variables now.
We have two existing related issues, one is #1399990: Remove "Display author and date information" in Display Settings in favor of listing Author and Date in Manage Displays and the other is #1884094: Split "Display author and date information" into 2 vars/options, which I just closed as a duplicate of the first. maybe we should leave those two fields out of this and let the other issue figure out what to do about them and focus on title here?
One problem that this doesn't solve is the problem with title prefix/suffix.
Mabye it doesn't need to, not sure. But it's also about the position, if you customize title but not display_submitted, then you would not be able to get the title to show up above. Of course, without removing that hardcoded position, we can also not easily move a field above the title.
Since core does not yet allow to configure this, might be acceptable. But I guess we eventually want to remove title and similar variables completely for 9.x, and the question is what exactly we need to do to achieve that.
To be honest, I still don't quite understand the purpose of the stable theme. In theory, we're not allowed to change it, but with a change like this, we kind of have to.
This needs to be reviewed by a frontend maintainer to confirm those changes are OK.
Comment #84
jonathanshawThanks so much for the review @berdir!
#83.2
I think you have a point this needs more thought. We have may have a BC breach here. Someone may have set isDisplayConfigurable for the uid field in order to modify the output with a formatter, while still expecting it to render as part of the display_submitted area.
I suggest we preserve the existing behavior if someone is using it, so:
I suggest we leave it in this issue, as this is about a single concern across a wide range of entity and field types, trying to ensure people can customise things if they want to. The other issue OTOH is a good place to discuss changing the OOTB behavior of those particular node fields.
Nothing in this issue makes an immediate difference unless you use a hook to modify the entity types's base field definition to set isDisplayConfigurable=TRUE.
#83.3
I don't understand what title_prefix is all about. But maybe this is slightly more BC preserving:
And at the same time we add the suffix to the node title templates:
Comment #85
berdirI think the only thing that uses those prefix/suffix things in core is contextual links, those would no longer work. And we can't just move them because they wouldn't get populated in a different template. See contextual_preprocess() it needs to be on the entity template.
Comment #86
jonathanshawThanks for the pointer. It seems like {{title_prefix}} and {{title_suffix}} are also used for RDF metadata and shortcut creation.
All these uses cases seem to work fine on full view modes, when $page=FALSE and there is no content between {{title_prefix}} and {{title_suffix}}. The pencil icon appear in line with the top content (the 'submitted' info in that case).
Therefore it looks like the patch as stands should work fine in this regard.
Comment #87
adamps commentedThanks @Berdir for #83.
To give us some means of talking about stuff:
1) Good idea
2) Answers below - net I do not currently perceive any need to change code - please feel free to correct me.
if (isDisplayConfigurable)around any call to unset a variable. If the other issue lands after this one, it can simply remove the whole if statement and contained code relating to those fields.Well they might, but they would have a confusing UI as the site builder can move the field up and down in the order but nothing happens. Don't forget our initial discussions on BC and the wording of the change notice: behavior may change on a heavily customised site, in particular one that already calls setDisplayConfigurable.
3) Answers below - net I do not currently perceive any need to change code - please feel free to correct me.
pageis true, then the prefix and suffix appear but not the title in between. The same will happen when using a field formatter, so it's fine.4) In that case, would you prefer to leave the stable theme as is?? It would still work, but would not support setDisplayConfigurable.
Comment #88
adamps commentedPatch addresses #83.1. Please let me know anything else that needs doing.
Comment #89
jonathanshawThere are other related occurrences of #83.1; can we not change the pattern every time getFieldDefinition is called?
True. But is there are drawback to covering BC in this edge case in the way I suggested?
Comment #90
adamps commented@jonathanshaw re code in #84:
(I think you would need to remove the ! before $variables)
1) Well it could reduce BC in a case where we promised not to, for example: the site has a custom template that uses author_name but doesn't set display_submitted.
I am trying to set out a clear picture on BC.
2) I like that the code we have now has the same pattern for every field on every entity type.
Comment #91
adamps commentedGood idea, I hadn't spotted that - feel free to upload a new patch (or I will probably get to it tomorrow afternoon).
Comment #92
jonathanshawGood point, I'm convinced.
I think your BC approach is sound: try to preserve BC as much as possible, but if it has to break somewhere let that be where the site is already using isDisplayConfigurable.
Is it time for tests?
Comment #93
adamps commentedRe #41 I have raised #2941678: Cannot properly control/hide submitted info
Comment #94
adamps commentedNew patch that covers #89. It would be great if we can get back to RTBC.
If you are offering, then please go ahead:-)
Personally speaking I won't have time for a couple of weeks. I am hoping for a clear indication from a core committer / expert that this patch is ready for commit (aside from tests).
@Berdir I would welcome your view.
Comment #95
jonathanshawI think the matters raised by @Berdir have been addressed.
Not sure how we get a review from a frontend maintainer as @berdir suggested.
RTBC again to seek the guidance you're requesting.
Comment #96
berdirLets try like this.
Comment #97
lauriiiOverall, the changes look great for me. I also think that we can make the changes for the Stable and Classy templates.
I assume we can remove these in D9. Given that this is an opt-in feature, we probably shouldn't place this in Stable since otherwise, this wouldn't be available for people not using Stable. We should probably add a @todo to revisit this before D9.
Changing variables to optional is technically a BC break. We should create a change record for that.
Comment #98
lauriiiUnassigning as well
Comment #99
adamps commented@lauriii many thanks
At top
OK, I am a bit confused, but given your comment in 1) I think that perhaps you meant to say "Bartik" here.
1) Done: removed changes to stable and done @todo.
2) There is already a CR draft.
3) Done Umami. That's completely new to me so please check I figured it out.
Comment #100
adamps commented@lauriii Re Umami I don't understand how the existing code can work to display h1, for example in node--article--full.html.twig.
I would have thought that it would hit the exact problems in this issue and #2941208: Title formatting broken due to flawed EntityViewController->buildTitle:
EntityViewController->buildTitlecalls render of the title fieldI would be very interested to understand this better as it potentially affects these issues.
Comment #101
adamps commentedAfter thinking about #2941208: Title formatting broken due to flawed EntityViewController->buildTitle I propose that we remove the inline_title part from this issue and instead handle it in a better way in the other issue. Please can I have your feedback on that idea?
Background is that there are two related problems
Timing/relationships
Comment #102
jonathanshawI figured it out eventually: #printed suppresses rendering as part of the {{ content }} sub-render-array, but not when the variable is invoked directly in the template as {{ label }}.
Comment #103
adamps commented@jonathanshaw #102 aha thanks for figuring that out
New patch as per #101 removing #inline_title, which I now plan to cover in #2941208.
Perhaps @lauriii is not planning to review again. Can @jonathanshaw or someone else please re-review to check the changes since last review:
Please comment to say that you have reviewed the code, and it is RTBC apart from the lack of tests. Then please set 'Needs work'.
Comment #104
jonathanshawWithout #inline_title doesn't this need to be postponed on #2941208: Title formatting broken due to flawed EntityViewController->buildTitle, i.e. we'd have BC breakage without it?
Comment #105
adamps commentedI don't think so. I believe that we have simply solved slightly less of the total problem in this issue and left more of it to the other issue. Specifically we are no longer solving what was listed as item 2. I have updated the IS.
If you are still not convinced then please can you describe a specific scenario that concerns you?
Comment #106
berdirI'm wondering what to do about the page flag.
The thing is that we not just "deprecate" the label variable but also page flag. To be clear, I think that's great, that was actually one of the reasons why making the label configurable is so tricky, as it is actually not tied to a view mode but a completely separate concept.
It means that showing a node with full view mode will still display the node title while node/N will not.
What this issue needs anyway is a change record, that explains what we are doing here, what it means for contrib/custom modules and themes.
Also, what is your plan with the manage_display module exactly? I think it makes sense to eventually add that to core as a BC layer. Meaning, we'd add a setting to make the field configurable, keep it of by default on existing sites (and on for new sites, maybe also in a second step) and then in 9.x remove the setting again and always have it configurable, removing the old label/page variables?
The second thing is about title_prefix/suffix. I'd love to see a separate issue to discuss what to do about those. My suggestion would actually be to deprecate both of them in favor of some kind of generic variable/placeholder that we just show at the top of the entity. We had similar discussions in media issues and ended up doing something rather strange there (only specifically display contextual links)
Comment #107
adamps commented@Berdir Thanks
Comment #108
jonathanshawRe #105 #inline_title @AdamPS:
OK, that makes sense. We're saying that the title markup problem is not exacerbated by anything done in this issue, it's just a further obstacle that anyone wanting to make their titles configurable will have to work around for now depending on the details of their use case.
I agree that the code here is RTBC bar tests and improvement in change record. Regardless of the road map for the bigger context @berdir asks about, the changes here are minimal, unproblematic, and solve a real pain point that cannot be easily addressed otherwise.
Re #106 @Berdir:
Yes, it's the need for the default view mode to support both full page and other contexts that is the source of a lot of pain here.
Re {{title_prefix}} and {{title_suffix}} I think you want #2004966: Markup and variable cleanup for titles and attributes in all templates (possibly needs rescoping or title change).
Comment #109
jonathanshawComment #110
berdirAh, missed the CR sorry. The change record should include before/after code/template snippets on how to update a node template to respect it being configurable. I would also include an example snippet on how to place the title somewhere else if using configurable titles (basically
{{ content.title }}I guess, with a condition and maybe excluding it in content.And sure, lets continue to discuss how to bring this into core so no module is needed in #2353867: [META] Expose Title and other base fields in Manage Display. Maybe also reference that issue and mention that the plan is to eventually deprecate the label and page variables completely?
About the title_suffix/prefix issue, yeah, sorry for being too lazy to create it myself :) I did of course not imply that you should work on that, quite the opposite. By creating separate issues, you can easily point out reviews that bring that topic up that it will not be addressed here but in that issue. Created #2943911: Figure out what to do with title prefix/title_suffix in entity templates.
Conflicted with #109, if that other issue also covers title prefix/suffix then maybe they can be merged.
Comment #111
adamps commentedThanks for comments, please review updated CR. After that I will set back to needs work for the tests.
@Berdir
I have put this into a "future plans" section. I don't think it applies now as:
Comment #112
berdirBut it's not future. If you set it to configurable, that's how it behaves *now*. So it's something that we should document, with an example.
There's basically two approaches to frontend, those who use standard templates and work with field configuration/weights and just display content.
But a lot of frontend developers either use some thing like patternlab/UI patterns or just want full control over their markup, so they likely end up displaying all fields separately.
Granted, it's unlikely that someone who fully customizes everything does go through the trouble of making it configurable in the first place, but that will get more likely as we add the UI to core. Maybe they rely on it in one case and have one special template or so.
Instead of an arbitrary "In the future", I'd just mention that for the case when the field is made configurable, it needs to be done like that.
Comment #113
adamps commented@Berdir I'm afraid that I still don't follow you. It seems that you a proposing a site that has
This makes no sense to me because the GUI admin user gets a broken UX. A call to setDisplayConfigurable means "the developer grants the GUI admin control over the display". If the frontend developer wants full control of markup via templates, then they should not call setDisplayConfigurable.
Exactly. The point that we add the UI to core is exactly what I mean by "in the future". At that point there will be another CR which can give new instructions. This CR should not give instructions that are inadvisable now, but might become correct at some future date.
Comment #114
jonathanshawThis is the core pattern already. Themers can be selective in how they implement the choices made by sitebuilders in entity displays.
And it's not inconceivable that even a developer who was also the themer would choose to set displayConfigurable and pull the title out from content for separate rendering, if for example they wanted the sitebuilder to control the title's formatter and its settings but not its position.
What Berdir is suggesting is to illustrate how we have made the title available in the content array (if displayConfigurable), in the same way that other fields are. It's not a recommendation, just an illustration of what's possible. Some people understand a code illustration more than a verbal explanation.
Comment #115
berdirExactly. Yes, it is a bit weird, but as @jonathanshaw said, that's already how it works with other fields and this happens far more often than you think. And something that varies by the view mode/template. They might make it configurable for the full view mode where just a different order is enough, but maybe they use a custom layout with two columns, where they need to/want to display each field explicitly.
All I'm saying is that we should document how it works *if* it's enabled.
Comment #116
adamps commentedOK, I understand, thanks for taking the time to explain. It seems weird to me but I'll trust your greater knowledge of what people do. Please could one of you two update the CR as I'm still not sure I've grasped it well enough to explain it clearly.
Comment #117
jonathanshawI did a thorough reworking on the change record, see what you think.
Comment #118
berdirNice work on the CR!
> It is still not configurable by default, a developer must still set it to be configurable.
Suggestion:
"It is still not configurable by default, this must be done by a developer or a modue like manage_display. A setting for this will likely be added to Drupal core in a later phase and will eventually be always configurable." (maybe link that text to https://www.drupal.org/project/drupal/issues/2353867)?
We might be able to leave out the Future plans section then completely with that part?
> A developer now wishing to force the title to always appear on top, while allowing the sitebuilder to configure it in "Manage display" should now use the normal approach
Suggestion:
If those fields are set to "display configurable" so that they can be controlled by a sitebuilder, then they can be displayed in a specific position in the template like any other rendered field:
Comment #119
adamps commentedThanks @jonathanshaw. I'll set this back to "needs work" for the tests.
Request for help
To the 23 other followers of this issue. I have worked to complete the code (through 23 patches!) and we are now RTBC except for tests. I need to take some time off this issue now for other priorities (sadly no one is paying me on this one!).
Can anyone else help to write the tests - or can you reach out and find someone who is looking for a way to contribute? The task should be fairly straight forward and well-defined now, ideal for a student learning to code with a little help from a mentor. Probably it works something like this:
There is one complication that
EntityViewController->buildTitlewill capture display of the title (something we are solving in the related issue #2941208: Title formatting broken due to flawed EntityViewController->buildTitle). I can see two ways to workaround thatComment #120
adamps commentedI have been thinking some more on the recent comments and deprecation.
As I understand it we have proposed that in the long term:
author_name.{{ content.title }}.In that case it seems that instead of
We should say something like
Where $back_compatible_mode is a setting that currently defaults to true and can be overridden by the site builder.
We could also do the same for
$variables['page']and$variables['display_submitted'].Thoughts??
Comment #121
jonathanshawI think that's unnecessary and problematic here.
It's unnecessary in that because isDisplayConfigurable is off by default for these fields, it functions as a reasonable test in itself of whether we are in a BC mode.
It's problematic in that the setting you suggest would have no effect unless isDisplayConfigurable was also turned on for the field. So it would have no effect for most sites, which would be confusing and add unhelpful complication.
A setting like that is an excellent way of preserving BC (particularly for distinguishing new vs existing installations) and possibly we should use it if we want to turn isDisplayConfigurable on by default. But that's for a future issue.
Comment #122
adamps commented@jonathanshaw Thanks for the reply. I think we are talking at cross-purposes. Let's see if I can explain better.
I agree that we have solved BC already. My reason for proposing a new idea is something else.
No - in the new idea there is no call to isDisplayConfigurable. I plan to replace that
iftest with the new one.Recap of the problem
We have some "legacy variables" such as "author_name" and "date". These are created by some "hard-coded" formatting in template_preprocess_node. That formatting only applies for a specific theming choice and it's wrong if isDisplayConfigurable. But I think it's also wrong (or at least unnecessary) if NOT isDisplayConfigurable AND custom formatting of submitted info.
Solution
In vanilla core, the field formatter should handle all formatting for base fields. I now believe this should apply always - whether or not isDisplayConfigurable. Site builders are recommended to follow this pattern and use the field formatter but could instead write a preprocess hook.
Old idea
Wrap legacy variables inside isDisplayConfigurable. However this is actually the wrong track as sites with
isDisplayConfigurable=FALSEare still forced to use the legacy variables. I now believe that we actually want to get rid of the legacy variables for all sites.New idea
Wrap legacy variables inside a global BC setting which could be something like
theme_get_setting('old_entity_template_variables').This way sites/themes can migrate away from the legacy variables at any time that suits them. We can remove the variables in D9.
A second benefit of the new idea is that it makes it very clear which code is deprecated. This can include 'page', 'author_picture', and 'display_submitted'. I propose we can also deprecate the corresponding UI for 'display_submitted' and 'features.node_user_picture' - these would much more logically be settings on the display formatter of the uid field.
Actual usability
The manage_display module is a good benchmark for how easy it is to setDisplayConfigurable. The new idea is definitely cleaner for the module in terms of submitted info, as I can just write a field formatter for uid. It's advantageous that the UI settings for 'display_submitted' and 'features.node_user_picture' have been removed as they don't work with the module.
Comment #123
jonathanshawAre you suggesting that the rendering of a field should invoke the default formatter for that field type if isDisplayConfigurable=false? Is that not the current behaviour?
That's interesting. I thought you were proposing a per field or per bundle or per view mode setting, which I was concerned gave too much prominence to a setting that was irrelevant to most people.
There's no doubt that this is the right direction of travel. And there's bound to be existing issues for this. It all ties in with setting isDisplayConfigurable=true by default. The question is whether to o it here or in a follow-up.
Comment #124
adamps commentedI guess I had in mind something like this:
Comment #125
berdirThe downside of a single variable is that we can never add something else to the list of deprecated variables.
Example:
You also put author_picture in there, but with author_name and author_picture, we have two different variants of the same field, that's something that we currently can't really do, not without layout_builder at least, as each field can only have a single formatter/rendering with the default field formatter API.
So likely, we'd actually not be able to deprecate author_picture just yet. So lets say we deprecate the others in 8.6 and keep author_picture. Now, I'm a good developer and I update my templates to rely on the new content.X variables and set the variable accordingly. But I still use author_picture because there is no replacement for it. But then core finds a solution for author_picture in 8.7 and also moves that inside the existing check. Now my template is broken when I update from 8.6 to 8.7.
Similar to custom/contrib entity types that might want to follow the example set by core, if they'd use the same variable any time later, they might also break for sites that already had the variable set.
We're also not really deprecating those variables just yet. We can't deprecate something without having a valid replacement, and requiring a contrib module is not an option. We can only really deprecate them in follow-up/related issues, when adding a method to make them configurable directly in core.
IMHO, the configurable check is a useful first step towards fully deprecating them.
That said, the author_name/author_picture is in fact also a bit of a problem for per-field "deprecation" as it is the same field. But we can figure that out later I think.
Comment #126
adamps commentedThanks @Berdir, yes that all makes sense.
I think deprecation is at a field level and author_name/author_picture will be fine. If !isDisplayConfigurable you get the 2+ variables and of course may choose to use just one of them. If not, you get the field formatter output. I can't really imagine a valid use case in between - what would it be one variable and half the field formatter output?
So I propose that the patch should have an if test around the display_submitted code:
I have noticed that 'metadata' is another awkward variable: like 'title_prefix' it picks up attributes from modules such as rdf. It has to be present on the node, but then moved to the uid field for display. It's a bit awkward, but I think I have it working in the manage_display module.
Comment #127
jonathanshawI don't see the necessity?
The reason for our isDisplayConfigurable checks introduced here was not because these old variables were unnecessary if these fields were configurable, but because the associated unsets were removing them from the content variable and messing with ability to position them.
display_submitted may be unlikely to be used if uid is displayConfigurable, but it's also harmless and there's already a UI setting to disable it.
Comment #128
adamps commented@jonathanshaw You are right, it is a fair point. I agree there is no necessity in terms of the task allowing modules to setDisplayConfigurable.
However this issue is also part of a wider task of tidying up base field display #2353867: [META] Expose Title and other base fields in Manage Display. I thought that the extra change would create a clearer and more consistent position for others to understand - disabling all of the special processing for uid rather than just part of it. I feel that the extra change makes it clearer for writing modules like manage_display and for planing the wider changes.
I don't have an especially strong feeling about it.
Comment #129
adamps commentedOK I've written some basic tests. No changes to the patch compared with last time (can come back to #126 later).
I discovered (but did not yet solve) some more problems:
Comment #130
jonathanshawI'm wondering if we need a global solution to this along the lines of a variable passed to all field templates like "raw" or "minimal" or "entity_display" that allows the templates to discriminate whether they are being called as normal field templates or in some more barebones context where labels and other wrappers aren't needed.
Comment #131
adamps commentedNew patch that solves #129.1, similar to the idea in #130.
Possibly we could move these extra bits into #2941208: Title formatting broken due to flawed EntityViewController->buildTitle to allow the earlier patch to be committed more easily. However without the extra bits, what we have isn't really fully usable so I feel it's worth expanding to the more useful solution.
Details
TODO: Probably need some BC for themes that have their own customised field--node--***. In the long term they should rename it to inline-field.html.twig but in the short term if not isDisplayConfigurable we should probably hook it in as an extra suggestion.
Please let me know what you think of these extra changes.
Comment #133
adamps commentedThe problem with #131 shown up by StandardProfileTest test fail is that it because I switch to using a new suggestion inline_field__* instead of field__*, Drupal calls correspondingly different preprocess functions, so rdf_preprocess_field__node__uid does not get called. I could rename that to rdf_preprocess_inline_field__node__uid but it's not really an answer as the same problem would apply to any custom hooks.
New patch #133 sticks with the field template and sets a new variable inline_field. This should fix the test. Unfortunately it is more of a BC problem: every theme that has overridden field.html.twig must update their template with a test for inline_field. If they don't, then the submitted info gets split onto multiple lines - see attached image file.
I can't yet see any perfect option unfortunately. Comments/ideas please.
Comment #134
adamps commentedOops I missed out stable field.html.twig and forgot to update the comment in the other two field.html.twig.
Comment #135
adamps commentedComment #136
jonathanshawI like this approach, but the patch seems weird. There's a lot more changing than I expected. Can you check the patch and makes sure it's what you're really suggesting now?
I think this is leftover from the previous approach?
Deleted by mistake I think?
I don't understand why yet, but I won't try harder yet in case the patch is malformed.
Comment #138
adamps commentedHere is a new patch that hopefully fixes the tests and resolves muddles of last time.
Comment #140
adamps commentedComment #141
adamps commentedMinor extra change to fix RDF
Comment #142
jonathanshawIt's not obvious to me what the problem is, or why this is the best fix. We'll need to update IS to explain, can you start by explaining it to me?
I don't understand why we need this or what it does. But I'm weak on theming ...
Do we need this? I'm not sure what our best practices are for optional variables, whether to default them false or leave them unset.
Removing these seems inconsistent with leaving the templates in. Enlighten me?
I doubt this is the right CS for multi-line variable comments.
Indentation?
I worry about the disruption of dropping .field__item. Is it avoidable? At very least needs IS & CR mention.
I think you could say something like "@deprecated, remove before D9.0 as it now duplicates field.html.twig."
Comment #143
adamps commented@jonathanshaw thanks good comment, you picked up a lot of complex aspects that I need to explain better - here is a new patch.
1. Modules that use setDisplayConfigurable do not need or want $node_type->displaySubmitted() and will likely hide it in the UI. Instead the site builder can show/hide the field in manage display and choose a field formatter, which will manage its own markup. The manage_display module contains such a field formatter.
Hence node.module should only create derived submitted variables if !isDisplayConfigurable. I have now added a comment to mark that code @deprecated. If the code to set $variables['display_submitted'] is left in, code in rdf.module checks the setting and potentially leaves out the metadata. I fixed rdf.module to handle $variables['display_submitted'] being unset - I have now clarified this code and commented.
In terms of IS, this is a sub-case of item 1: it is just a bit more usurping of the processing of base fields.
2. This is necessary to allow {% include "inline-field.html.twig" %}. I have now added a comment.
3. I opted for consistency with the existing code. Without this line, template_preprocess_field has to check isset, which does not happen for any other variable.
4. In the early days of D8 there needed to be a hook_theme entry to pick up field--node--title.html.twig but that is no longer true - it gets picked up based on the theme suggestions. So that code has been unnecessary for a while. If there is a hook_theme entry, Drupal mandates that the template exist, which is not what we want (it's present only in stable and only for back-compatibility), hence I had to remove the hook_theme entry.
5. The alignment I used matches node.html.twig. Feel free to point to a CS doc that says otherwise.
6. I deliberately didn't indent to minimise disruption and preserve BC. Firstly, if many themes have to add the if test, it's faster and less VCS churn not to indent the entire template. Secondly indenting the lines does actually change the spaces in the HTML in a way that would have required changes to core tests, and could also break contrib theme tests so it seemed easiest to leave it. I guess I could try to add a comment to explain??
7. The inline-field template applies to all entity types and I propose we should keep that consistency or it's going to be really confusing and complicated. The templates I used match the historical node templates, hence avoiding any change for nodes. I think it's by far the most important case to keep nodes the same as before. Other entities are less often displayed on their own page - and to support that I claim I point out that no one seems to have noticed that Drupal currently generates illegal HTML in that case.
I guess if we want to be safer for now, I can change the patch so as not to affect the page title for non-node entities and we could handle that in the other issue.
8. Done.
Comment #144
adamps commentedFor the CR, we should mention two more template fixes. These are in the same category: recommended to fix, but optional except in case of setDisplayConfigurable as it's fully BC
Related bug fix, which possibly should move out of this issue:
Comment #145
jonathanshawThanks for explaining those things, that mostly made sense to me now you explained it.
I'm always up for splitting out issues, but not sure how we could here, without special-casing node in some awkward way.
I still don't understand the necessity.
works fine for me, even if the partial is only present in a parent theme.
(I also wonder if core theme maintainers will think it worth creating this template partial as the only repetition in core that it's saving is in the the deprecated field templates.)
Sorry to ramble ...
I worry about leaving the display_submitted setting in the UI if it no longer produces the expected results in some circumstances, it could cause some head scratching. For example, a developer might not anticipate that setting uid to be configurable would make their author_picture variable disappear. I understand that configurable uid and display_submitted are two different paradigms, but as long as we have them both it seems better to keep them working simultaneously without interfering with each other.
This makes me interested in leaving (for now) the display_submitted and author_picture variables stuff intact regardless of uid display configurability, and instead putting more checks into rdf.module to make sure the metadata behaves right.
I've tried to understand how rdf.module works, but I can't find anything that ever sets the mapping's fieldMapping property, so hit a dead end. I'm not sure what happens to $created_mapping if the uid is configurable and disabled, whether it's affected by that.
It seems like in principle we should be enabling the created data metadata at the node level only if the created date is visible to the visitor; otherwise we might be leaking information that the site wishes to keep private. Therefore we have 6 situations:
Conf = uid display configurable
Enabled = uid configurable display enabled
d_s = UI "display submitted" setting
Metadata = metadata is desired given the values of Conf, Enabled and d_s
Conf Enabled d_s Metadata
N - Y Y
N - N N
Y Y Y Y
Y Y N Y
Y N Y Y
Y N N N
So maybe we need something like this
I'm not sure that's the right way of conceiving this. It seems more about deciding what metadata is a part of the display of node itself, not just of its individual fields.
I do wonder if the simplest thing is to leave the metadata and $display_submitted as they are. If someone wants the metadata to appear on the node, they check simply check the display_submitted setting; this is true whether or not they have made uid configurable.
What's the harm in leaving things as they stand? Could we leave this to be resolved in the future when uid is made always configurable?
It may be that we decide then that the best thing to do is always default to adding the data metadata to the node, regardless of whether the date is displayed to the visitor; it keeps it clean and simple for the 80% use case, and developers can always strip it out.
Comment #146
adamps commentedThanks for the reply.
It's not too bad: in EntityViewController->buildTitle we would need to add an if:
If I comment out that line and rebuild cache then I get an error
The website encountered an unexpected error. Please try again later.</br></br><em class="placeholder">Twig_Error_Loader</em>: Template "inline-field.html.twig" is not defined (Drupal\Core\Template\Loader\ThemeRegistryLoader: Unable to find template "inline-field.html.twig" in the Drupal theme registry.) in "core/themes/stable/templates/field/field--node--title.html.twig" at line 11. in <em class="placeholder">Twig_Loader_Chain->getCacheKey()</em> (line <em class="placeholder">129</em> of <em class="placeholder">vendor/twig/twig/lib/Twig/Loader/Chain.php</em>).The benefit is mostly for themers:
Unfortunately I don't really understand your reason/purpose for objecting to the current code and wanting something else.
The title of this issue is "Field rendering should respect configurable field display". So if isDisplayConfigurable then the settings in "Manage Display" should work 100% and anything else have no effect. It is not my intention to ever have both display_submitted and setDisplayConfigurable in the UI; however this issue is not changing the UI. Personally I would recommend any module calling setDisplayConfigurable to hide display_submitted. As you say, they are two completely different paradigms and you want one or the other but not both.
It seems that you are considering control of "created metadata" separately from "created field display". That's not possible with Core now for this field or other fields and I don't see a mainstream use case for making it possible in Core. It seems like a bit of a tangent, but would of course be possible with custom module hooks or custom formatters.
Yes I could refactor the code to solve 1) and yet keep $variables['display_submitted']. I don't understand why that's a good idea though.
Yes I agree. I had assumed that $created_mapping would be empty if the display was disabled, but now I scan the code I worry that's not necessarily true - I'll check.
This seems to contradict the previous paragraph and I don't agree for the reasons you gave above:-)
Comment #147
adamps commentedNew patch. Aim is to be as safe as possible because it's already a fairly big and complicated change.
Comment #148
jonathanshawSorry not had time to review the latest yet, but I did have a thought:
I think you need this only because inline-field.html.twig is in the system module not a theme.
Given it is fundamentally a helper for themers (as you explained in #146) rather than something that core needs, I suggest it would be better to add it to classy & stable rather than the system module, in which case you don't need this hook.
This is a little less DRY in core itself, but the fact that this hook needs a long comment explaining why not to use it as normal smells to me.
Comment #149
jonathanshawI like #147. I think we're close to RTBC for real, just need the RDF etc tests. IS and CR will need a check over too.
I don't think the comment is right. @deprecated is quite technical in it's usage I think. If anything it's the variables in the template that would need to be @deprecated. What we should probably do is make sure there is an issue about removing the whole display_submitted mechanism, and a meta to keep track of those whole family. Possibly we could add an @todo here linking to that issue, but again I have the impression we only use those in quite specific circumstances
OK, this is consistent with with what we do in template_preprocess_node and node.html.twig:
we disrupt the old-style display of submitted info if the relevant fields are made configurable.
And we have to do this because otherwise the old-style disrupts the configurable display. The only way to avoid it would involve cloning fields.
How about:
If 'created' display is not configurable then it is controlled by the display_submitted setting. @see template_preprocess_node.
Comment #150
jonathanshawComment #151
adamps commentedThanks @jonathanshaw. I haven't done a new patch yet as I have a question for you first (see bold italic).
#148
For the last several of your comments a major point seems to be inline-field.html.twig. I have tried a few variations but it seems to keep coming up. The only thing I can think of is to remove the mechanism entirely. It will mean more duplication, but that's not a big deal in comparison to making it clearer. Note that every theme developer will have to add this to field.html.twig rather than just an include.
Are you in agreement that I should remove inline-field.html.twig?
#149
Comment #152
jonathanshawI'm neutral on that.
From my testing I'm certain that undeclared arbitrarily named template partials can be included in other templates, so the declaration is not absolutely necessary. I'm weak on theming so tentative, but the way the template is being declared here doesn't feel right to me, I'd expect a maintainer to reject it.
Comment #153
adamps commentedSorry but I can't get it to work without the declaration. If you can, please upload a patch with passing tests. NB I thought you were right for a while, but I think it was just caching.
If you can't get it to work either then I am willing to remove inline-field.html.twig.
Comment #154
jonathanshawSorry I'm travelling for 2 weeks. What I tried was creating a template called monkey.html.twog in my theme or parent theme and including it in field.html.twig in my theme.
Comment #155
adamps commented@jonathanshaw I'm sure you will be amused to learn how many hours of my life I have spent figuring this one out.
I deduce that you ran your test using a Bootstrap derived theme, and it worked because Bootstrap has a mechanism to automatically register hooks for any *.html.twig files that don't already have hooks.
Setting aside the exception of Bootstrap, then the normal procedure is to register new templates via hook_theme. Possibly we could avoid the need for these 3 lines if we called the template field__inline instead of inline_field, but I don't favour that as it basically disguises what we are doing and potentially creates confusion as it looks like a field name or type 'inline'.
Therefore it seems that the lines in theme.inc are necessary and correct unless we drop inline-field.html.twig entirely. As far as I can see you have not put forward any reason against the lines except that you thought they weren't necessary.
I have updated the comment in theme.inc to try and make it clearer.
In that case, please can we avoid spending any further time until we have an opinion from an expert?
Comment #156
adamps commentedEnhance tests to check quickedit and rdf attributes
Comment #157
jonathanshaw#155 you're right, it was bootstrap, sorry! Not amused!
Comment #158
jonathanshawThis seems ready. Possibly inline-field.html.twig needs mentioning in CR.
Comment #159
adamps commentedYay, thanks @jonathanshaw.
I hesitate to raise a doubt just as we reach RTBC but if we don't raise things I expect others will.
1. If isDisplayConfigurable $variables['metadata'] (meta-created tag) basically gets lost and is never printed. I have some code in the contrib module manage_display that rescues it. However this seems wrong - core should print the metadata without need for a contrib module.
In rdf.module, the other meta items get put into $variables['title_suffix']. I propose that if isDisplayConfigurable we put meta-created into title_suffix too.
2. I noticed that we could avoid the need for the second node.html.twig change
Instead node.module should only set display_submitted if both variables are available. This is something I wanted to do earlier but backed off to minimise changes. My new insight means that the balance has changed as the top priority is to minimise changes in templates. With this new approach, it significantly reduces the problems for a site that calls setDisplayConfigurable but doesn't change the node template - it avoids random printing of "Submitted by on".
Any objections if I create a new patch that includes these two extra changes?
Comment #160
jonathanshawYes, I think you're right on both.
Comment #161
adamps commentedNew patch for #159
Comment #162
jonathanshawComment #163
adamps commentedExcellent, thanks @jonathanshaw.
Comment #164
adrian83 commentedA big thank you to all of you for your tireless work on this!
Comment #166
alexpottTestbot had a hiccup re-rtbcing
Comment #168
andypostInstead of user_view() better use $node->getOwner->view('compact) also makes sense to assert() that view mode configured
Comment #169
berdirEntities do not have a view() method. If anything, it needs to use the view builder.
Comment #170
adamps commented@andypost although at first glance the lines you refer to appear to be new in this patch in fact they are existing lines that were merely indented. We definitely don't want to make any changes in this patch that are not directly required to achieve the goals.
Re-setting status to RTBC as testbot seems to be confused.
Comment #171
alexpottI'm a bit concerned about backwards compatibility and this change.
Won't removing these affect existing sites?
If a site has overridden this will this patch break it?
Comment #172
adamps commented@Alex Pott thanks very much for your time. The major part of the work here as been to do the best we possibly can for back-compatibility, but even so the result is not perfect. I don't know if you noticed, but we already have a CR that attempts to explain.
Yes I agree there is some risk in the sense that these sites may well need to make some changes to preserve existing appearance. Nevertheless I am proposing that we allow this change in a minor release for the following reasons:
I believe not.
No I believe it's fine. This patch should be fully BC for every site except for sites that have made base fields configurable.
However if a site has overridden certain templates, and also wants to take advantage of the function added by this feature, then the site will have to alter their templates to match the changes made in this patch. We have tried to explain this in detail in the CR.
Comment #174
adamps commentedNew patch fixes the coding standards error. The test failure looks like a glitch.
Comment #176
jonathanshawAgreed with #172. The CR discusses BC. There's no perfect solution, but this is likely the best we can do before D9.
Comment #178
adamps commentedAs I understand it, the only BC concern is the calls to isDisplayConfigurable because it might affect sites that are already calling setDisplayConfigurable.
@alexpott If our responses have not relieved your concern then we do possibly have another option. Instead of the calls to isDisplayConfigurable there could be a separate new switch. I raised this in #124 and Berdir pointed out some flaws in #125 - here is an attempt to solve them.
The idea is there would be a setting "Entity preprocess migration" with values:
Migration path
After this patch
After a later D8 patch that brings manage display into core
D9 removes the setting and only supports [2] (or the final newest option if more were added).
Comments anyone?
Comment #179
jonathanshawYes, a setting is the "heavy artillery" of BC: it sure works, but it makes an ugly mess.
I think we might be able to go a little further than you suggested:
create an update hook, that tests if isDisplayConfigurable is enabled for any of the problem base fields; if it is, then and only then store the setting in the entity config; in the preprocess, test for the presence of the setting.
This way existing sites that have messed with isDisplayConfigurable don't break, but everyone else gets the new goodness.
Comment #180
kingdutchThe commit
bc1b1fa8ce214478ecbf41004b545956d0101647changescore/modules/system/templates/field.html.twigwhich prevents this patch from applying.Comment #181
jofitzRe-rolled.
Comment #182
adamps commentedThanks @Jo Fitzgerald
Clarification re Back-Compatibility: I believe the community consensus is in favor of the proposed patch #181 for the reasons explained in #172.
The recent comments #178/#179 put forward two slightly different alternatives only in the case that the core committers are not convinced by #172. I don't propose to discuss the relative merits of each unless the core committers indicate that #172/#181 is not acceptable.
Comment #183
jonathanshawIn which case rtbc
Comment #184
berdirThis is still a very large patch. And in other places, we already focus on node to limit the scope.
What about doing the same here and e.g. moving the aggregator parts (which are not tested for example) to a separate issue, maybe other things too?
Similar here about the whole node field template changes and the #inline_field stuff.
Is that really needed in *this* issue? Does it really block when those other templates still exist?
BC goes in many directions, you also have to consider that people might be using themes with field templates that will not be considering that setting.
As the comment says, this is used by rdf_preprocess_node() for example to add additional information to the template. This isn't really something that can be controlled by field UI and shows the general problem with BC on this.
It's one thing for one site to make the fields configurable and configure it accordingly/update their templates. But it also needs to work in both cases with all core & contrib modules.
Not sure what the best solution is, but I'm not convinced that this is sufficiently BC.
so you are changing rdf module accordingly. But that you need to change it also shows that this is technically a non-BC change and we can not know how this will affect contrib/custom modules.
Thanks for all your work on this and I'd love to make progress on this issue, figuring out BC is really hard. You mentioned that this only affects sites that are calling setDisplayConfigurable() but I don't think that is true. Specifically the #inline_field stuff and all that refactoring does not seem necessary *and* will affect anyone.
Comment #185
adamps commented@Berdir many thanks for your time and expertise for a detailed review. I've replied below, but it might be easier to cover some details via online chat/Skype then report back a summary to this issue - I'm very happy to do that if you wish.
Yes it's a large patch, but I have been careful as I can to only change what needs to be changed to achieve the objective. I have read your arguments in detail, but nevertheless I stand by the current patch - i.e. I believe I have already considered the points you mention and it's fine, but the other possibility is that you are right and I am being dense failing to understand your point in which case please help me out. On the plus side the tests all pass and I have done extensive manual testing.
Recap on BC promise
A) Sites that don't call setDisplayConfigurable are unaffected. I will justify this claim below in specific cases you raise.
B) Sites that already call setDisplayConfigurable may well be affected, but I propose that is deemed highly experimental as it basically doesn't work for a variety of reasons as per #172 etc, and the evidence of Google searching is that everyone who wants to manage title display is currently using Display Suite. However we could add a BC flag if core committers prefer with the obvious cost of making the code more complex/less clear.
C) "Forward compatibility": sites that want to make use of this patch and start calling setDisplayConfigurable then this patch removes various obstacles in core. This patch is an important step but still just a step and other obstacles remain in core deferred to other issues, and of course in contrib. Sites must ensure the theme chosen has the template updates. As you say, there may be other contrib modules similar to RDF where hooks would need to be updated. This patch does not expose any way to enable setDisplayConfigurable, so these obstacles only affect sites that have very clearly opted in, and the sites will work much better with the patch than without. Once this patch is committed, the community can start to fix contrib modules and themes.
Response to specific points
1) I included aggregator for completeness but very happy to defer to a separate issue (but I'll wait for resolution on the other points before creating the new patch).
2 & final paragraph)
I absolutely understand where you are coming from - I implemented the #inline_field idea reluctantly after a considerable effort to find a better way and failing so I would be happy to hear of a better way. Without this part, we get invalid HTML and missing RDF metadata.
The complications start from EntityViewController::buildTitle, see comment
If the entity's label is rendered using a field formatter, set the rendered title field formatter as the page title instead of the default plain text title. This allows attributes set on the field to propagate correctly (e.g. RDFa, in-place editing).This leads to the field formatter output being emitted into the page wrapped inh1. Tags such asdivand even worseh2would not be valid in that context hence core contains templates such as field--node--title.html.twig that create non-standard inline output.I assumed that for BC I had to retain this concept, but it breaks with setDisplayConfigurable, because the title field must now be inline if used as page title but must not be if used as a normal field. The existing field-by-field approach is not so elegant because it leads to an identical inline template for each of 3 node fields, plus there ought to be at least one for other fieldable labelled entities (e.g. media is currently broken with div inside h1 but as you noticed I have deferred tackling that to a separate issue). Hence I created the generic 'inline field' concept.
Please can you describe a specific scenario that illustrates your claim it will affect anyone? I am aware that existing templates won't check inline_field but it doesn't matter so long as there is no call to setDisplayConfigurable (case A) - exactly as now the 'special fields' will all be used inline and the existing templates will emit inline markup.
Even for setDisplayConfigurable (case C) I've done my best to help: search in the patch for
This file exists to help back-compatibility in case a theme has overridden field.html.twig but not added a test for inline_field.and see code that provides the check on inline_field. That means that themes only need fixing if they override the specialist templates such as field--node--title.html.twig.3&4) I think this is covered by point C) above. This patch removes so obstacles in Core for sites that want to call setDisplayConfigurable. Yes most likely some contrib modules also need work to match what was done in RDF. However I can't see anything we can do in core to avoid that.
Comment #186
adrian83 commentedQuick Question: Is this issue affected by the new Layout Builder exposing fields as blocks on the manage display page? If title is a block already on default and full view modes but uncontrollable on other view modes, and both blocks and fields will be placeable on Manage Display, does that change anything with this issue?
Comment #187
adamps commented@Adrian83 I am not very knowledgeable on Layout Builder and I'm sure others following here know much more about it. My feeling is that Layout Builder is a separate, compatible strand which does not change the way we go about solving this issue.
1) Presumably until this issue is solved, the title field won't even be present in manage display for Layout Builder to act on.
2) A key element here is back-compatibility (BC) so we have to ensure that existing sites that don't use Layout Builder continue to work well without it.
3) You have made an assumption that I have seen many people make: "full view mode" = "node is displayed on own page, hence put title field into title block". However I can see cases where that's not true
This suggests that the title block pulling in the title field is not directly related to view modes.
Comment #188
adrian83 commented@AdamPS Thank you for the explanation. Your assumption is what I also expect, though I haven't tested. For the record, I would love to see this issue fixed, because on almost every site I need to install Display Suite primarily to control the title on any view modes that are not the full view mode. The promise of view modes is only half realized in D8 because title appears first thing on all non-full display modes, which is almost never what I want.
Comment #189
berdirYou are changing field.html.twig. You are adding a feature to it to tell it to render inline layout through a flag.
If an existing theme does not implement that new option, then it will *not* render inline layout but a regular one. That means the logic in template_preprocess_node() will now no longer render an inline field template but a regular one.
I had another look the patch and I see that there are fewer changes to the node specific templates than I thought before (it's hard to see what exactly is going on when just looking at the diff, easier when applied), so while you remove the templates from classy, you keep them in stable. So it still works for existing themes that extend from stable, even if they have a custom field template, but it does break themes that don't (you can do that by setting "base theme = false" in .info.yml) and have a field.html.twig. I tested it in our project and confirmed that this then ends up using the full field markup for the uid and created markup in the Submitted by.. text.
So the #inline_change => TRUE case can break in two cases when themes have a field.html.twig:
1. New usages of #inline_field => TRUE for other fields, which I think this issue does not yet add, but later issues will and other modules might start to use it as well
2. For those themes that opt out of stable
1. is probably OK if it's fixing bugs that can not otherwise be fixed like the entity title thing, but this doesn't actually fix those things yet, notde works because it does have its custom template now. 2. is technically also allowed I think (https://www.drupal.org/core/d8-bc-policy#themes), because we did define that themes that do not extend from stable are on their own, but the part I don't understand yet is why it is *necessary* to do it in this issue like this.
Yes, it's not elegant. But BC and elegant usually don't go hand in hand, we often can't have both.
So while this might be acceptable when strictly following our BC policy, we should try to limit even allowed BC changes to cases when it is really necessary. And yes, #2941208: Title formatting broken due to flawed EntityViewController->buildTitle I assume needs something like #inline_field, but unless I'm missing something, we can just add it there, without having to change all those node templates here. Adding it there to EntityViewController means as far as I see that the worst thing that can happen is that the bug will not be fixed in themes not respecting the new setting. So it's not getting better, but it is also not getting worse for them (At least not until modules start to rely more on that).
Am I missing something in thinking that at least as far as node is concerned, the result would be the same if we don't do the #inline_field change and don't do any of those field template changes? And for now, only node field templates use #inline_field TRUE.
Also, inline_field is currently not mentioned as something that themes should now consider in their field templates, if we decide to keep that change in here, then it should be put in either the existing CR or a separate one, or if we only introduce it in the follow-up, then one for it then.
Comment #190
adamps commented@Berdir thanks again for your time and detailed explanations. In summary you have spotted a bug that hopefully I can fix, but I still support the overall approach used in the patch.
OK, I now see your scenario. This occurs if the theme opted out of stable and it doesn't implement field--node--created.html.twig. It looks like the code worked before my patch because it picked up core\modules\node\templates\field--node--created.html.twig which my latest patch removed. I'll take a look at that and see if I can put it back. However as you say there is a possible fallback "themes that do not extend from stable are on their own".
Why we need inline_field
Core already has the concept of an inline field. The node fields title, uid and created are rendered inline, using span and other simplifications to markup. All other fields are full (i.e. not inline). We definitely must correctly handle inline/full:
Once we enable manage display then the requirements change. The node fields uid and created should be rendered full. The title should be rendered full except on the node's own page where it is rendered inline. So the existing approach of hard-coding specific field templates to be inline no longer works - we need a system that adapts dynamically based on a variable: #inline_field.
True, #inline_field will only ever be set to true for those specific 3 fields. Would it be sensible/feasible to add it to just those three templates? Not really because field--node--title.html.twig is a special case of field.twig so they share template_preprocess_field hence share the set of variables that will be available. I guess it would be possible to only comment the variable on the 3 specific templates, but that is potentially confusing. Looking forward to the future, we are likely to need #inline_field on other fields too. If we don't add it properly now, we are likely to force every theme to make some changes now and some more later.
Why it works for BC
(Aside from the bug you pointed out which hopefully I can fix.)
I do agree that existing templates will ignore #inline_field. I don't see why it creates a problem. Suppose that my patch added the #inline_field variable but made no other changes. In that case, the existing field.twig would always get passed #inline_field=FALSE, ignore it, but nevertheless correctly output full markup. Similarly field--node--title.html.twig would always get passed #inline_field=TRUE, ignore it, but nevertheless correctly output inline markup.
For any site that does not call setDisplayConfigurable, this is effectively what will happen, so it's perfectly safe for the existing templates to ignore #inline_field.
Comment #191
adamps commentedHere is a modified patch that I believe fixes the specific case that @Berdir hit in #189 by keeping a few more templates for BC.
Comment #193
adamps commentedPlease can a community member (@jonathanshaw?) review the latest patch and set RTBC?
OK so we have missed 8.6, so let's try really hard to get this in for 8.7. Setting priority to major as this issue has 40 followers, the parent issue has 111 and the D7 title module has 56,329 sites using it (of course many of these just want the translation but even so). The longer we wait, the more sites might have done workarounds and the greater the BC risk.
I believe I have answered the comments from @Berdir (it would be great to have confirmation). I didn't yet remove the aggregator to put them in a separate issue because I admit I don't quite understand what that would achieve. If we are going to commit both anyway surely it's easier/clearer to do it all together and the IS, CR and patch are all ready for that. If we are not going to do aggregator ever then fine I can remove it, although it does seem a shame to leave it as the only inconsistency.
Comment #194
berdirAdding the templates back helps, there's still at least one way where the behavior is changed. The templates now respect the #inline_field variable. That means until now, those 3 fields are *always* displayed inline if you render them, now you must provide that setting, otherwise they are no longer inline. If you wouldn't change EntityViewController in this patch then the title display would be broken. The same would happen to any call to rendering those fields themself.
If you would ignore that variable in those templates and instead always call the inline template, then that's another thing less that could possibly break. That said, I still really don't understand why that variable/concept must be introduced in this issue, it still just seems like a refactoring that isn't strictly required to achieve the goal of this issue. But I'm going to leave the decision to the maintainers whether we should include that or not.
> I believe I have answered the comments from @Berdir (it would be great to have confirmation). I didn't yet remove the aggregator to put them in a separate issue because I admit I don't quite understand what that would achieve. If we are going to commit both anyway surely it's easier/clearer to do it all together and the IS, CR and patch are all ready for that. If we are not going to do aggregator ever then fine I can remove it, although it does seem a shame to leave it as the only inconsistency.
http://www.webchick.net/please-stop-eating-baby-kittens explains that well. Every small change that doesn't absolutely belong distracts and makes it harder to review and understand a patch.
I know very well it's hard to do on your own patch. I had the same recently in #2960253: [meta] Allow Paragraphs widget/field and similar use cases to to be considered translatable where I tried to get 3 different changes (that were all necessary to achieve what I needed) and I initially argued against splitting it up, but we eventually agreed on it and we did manage to get all 3 changes committed in 8.6 because each issue on its own was easier to review and agree upon.
Comment #195
adamps commentedThanks again Berdir. OK here is a patch without aggregator.
Comment #197
adamps commentedDarn, the umami files have changed. I'll come back to that. Here is a patch that takes out inline-field. Notice that I had to compromise in NodeDisplayConfigurableTest:
rel="schema:author"I set it to test against 8.6.x else the patch would fail to apply again - that's to get a record of how the patch looks and save an interdiff before adding in the complication of refactoring for umami.
Comment #199
adamps commentedReroll, same as #197: without inline-field, without aggregator
(Sorry no interdiff - my tool fails to apply the patches)
Comment #200
adamps commentedReroll of #195: with inline-field, without aggregator
This is a more complex patch but fixes the problems listed in #197:
Comment #201
oriol_e9gIf #199 it's not including inline-field, why we need to set this vars?
I think this could be removed.
Comment #202
adamps commented@oriol_e9g Well spotted - those three lines shouldn't be there, I'll fix that.
Comment #204
jonathanshawThanks for your patience with this @AdamPS.
I think we need to move the taxonomy changes out of the patch, in the same way you have aggregator. I'm fairly sure @Berdir intended aggregator as an example of something distracting, not something that caused a particular problem.
This would benefit from a comment explaining why 'title_suffix' vs 'metadata? It's a bit of a WTF.
Do we cause these problems by our other work in this issue? Is there anyone who currently doesn't experience these problems who will immediately experience them if this patch is committed? If not we should push them into a follow-up in order to simplify this as much as possible. I see the real challenge for this issue is building consensus on how to address the BC concerns caused by what we're doing in template_preprocess_node; maybe everything work perfectly when isDisplayConfigurable is set can be follow-up stuff.
AlexPott's had a BC concern "I think there might be considerable risks to sites that have made the base fields configurable". In light of this it would be good if we could document more exactly in the IS & CR in what circumstances someone could be affected.
I believe it is if they have made a base field configurable and:
1) they made it configurable in order to use a different formatter on the title, author name or date, but still wanted them to appear only at a template-hardcoded location.
2) they made it configurable and wanted the field to appear twice, once in the configured location amidst content fields, and once in a template-hardcoded location.
3) they use twig coding in the template to add the field back into the twig content array in a specific position
4) is there a hook to alter the output of template_preprocess_node before it gets to the template? Someone using that to work round the could be affected.
5) they did any kind of conditional processing in a custom template based on values of the label, author_name and date variables
Anything else?
Comment #205
adamps commentedNo and no - so let's push it to a follow-up.
OK here is a new patch
Comment #206
adamps commentedI don't think with the list you are being more exact. I think you are being more detailed yes, but it will become less exact, because I doubt it will be possible to think of every strange piece of code that someone could have written that might be affected.
I feel that all we can safely say is that any site that already calls isDisplayConfigurable may be affected. However this is not an option that's available via the GUI or documented/recommended. See #172 and as explained in the IS, currently calling isDisplayConfigurable does not actually make the display configurable, but rather leads to a strange partly-broken result. So my question is, do we really have an obligation to keep the broken behavior working?
I see two options:
How about if we stick with option 1) for now and get a response from committers to the new much simplified patch?
Comment #207
jonathanshawAll good with me. I'm RTBCing because we need to get approval in principle from a committer.
Before actual commit we need to change IS & CR and create follow-ups.
Comment #208
adamps commentedOK, I have mostly convinced myself that we should change the patch to eliminate the BC problems here and in the follow on inline field issue.
Recap of intent of this issue
Drupal core contains some template preprocessing of base fields based on certain assumptions about the template files. In fact this processing is not always wanted and can present problems, so we need a way to disable it.
Current approach
The current patch disables processing if the field is display configurable. This makes an assumption that might be right 90% of the time, but it's possible to imagine counter examples.
authored onto let the admin configure field display options - for example to change the date format. However the template is the same as core, and preprocessing is required. The site accepts the limitation that changing the display order ofauthored onhas no effect. This would be a BC break.Proposed approach
Instead we can make it really simple - we add a new option to enable/disable the base field preprocessing. This isn't a "BC-hack" - the option would be available for the rest of D8 (with the intention that the preprocessing option be removed in D9). This patch would not expose a GUI for the option.
In #125 @Berdir said
True - but I think we now know every case of base field preprocessing and can fix them all, so it should be fine. Yes we would need to bring taxonomy and aggregator back into the same patch.
Code snippet
We need
base_field_preprocessto default to TRUE which might need an upgrade hook for existing sites.To me it seems simpler code that is guaranteed safe for BC. It also makes very clear which parts are deprecated (everything relating to base_field_preprocess). What does anyone else think?
Comment #209
jonathanshawif (theme_get_setting('base_field_preprocess')) {We'd also need an upgrade hook test, which is not a picnic. It'd be much easier to just avoid all this:
if (theme_get_setting('base_field_preprocess') !== FALSE) {You can avoid both issues if we have separate variables for each field:
What I like about your proposal @AdamPS (and even more with these modifications) is that it seems simple and unobjectionable, a much easier thing to get reviewed and agreed.
Comment #210
adamps commentedGood suggestions @jonathanshaw
I agree. However I'm not sure how much I like
node_base_field_preprocesshaving the semanticsNULL => Yes
false => No
true => Yes
It looks like a boolean, but it isn't. We could instead have
skip_node_base_field_preprocess, and then it works like a proper bool.@Berdir - can you spot any problems or shall I make a new patch along these lines?
Comment #211
jonathanshaw@AdamPs, agreed your semantics are probably better.
I'd suggest bypass_preprocess_node_fieldname or preprocess_bypass_node_fieldname or node_fieldname_bypass_preprocess (I think 'bypass' is a little more frequently used in core, skip is slightly more informal English?)
Comment #212
adamps commentedHere is a patch that implements #208-#211.
Detailed notes:
$form['display']['display_submitted']in cases when it has no effect.We can still go back to #205 if the experts prefer it. I've not yet updated the IS or CR, but I think they become simpler with the new patch.
Comment #213
adamps commentedOK, I think I have a new better approach, and finally I can see a possible whole "road map" for manage display in core.
The overall goal is to have a setting in the Drupal GUI to turn on manage display of base fields. Of course there would be an underlying config setting to record the chosen setting. So we don't really want another similar (but less easy to understand) config setting for "bypass preprocess". Why don't we instead create the proper manage display config setting now? Here is a patch that does that.
Roadmap
In this issue:
In other issues:
Comment #215
adamps commentedSorry bad patch - try again.
Also I have updated the IS.
Comment #216
jonathanshawI'm not qualified to offer an opinion
Comment #217
adamps commentedFix title
Comment #218
adamps commentedI'm feeling quite optimistic that this new approach gives a sequence of simple BC steps to the goal of manage display in Core GUI. I've created issues for all the parts that we have split out and updated the parent META issue #2353867: [META] Expose Title and other base fields in Manage Display.
@jonathanshaw Even if you feel uncertain of the wider implications, I would very much value your opinion seeing as you have been following this issue closely.
Comment #219
adamps commentedThis issue needs guidance please from a core committer/maintainer/expert to direct us to one of three open approaches. Setting to RTBC to request this. In fact 2 of the approaches are RTBC, the third is only "needs review" - if anyone can provide a community review of option 3 that would be very useful please.
Three options:
setDisplayConfigurable).theme_get_setting('bypass_base_preprocess.node');. The downside is that we would presumably eventually want to have an option in Drupal Core GUI to enable manage display and that would mean a second new setting.\Drupal::config('system.theme')->get('manage_base_field_display.node');. When we eventually have an option in Drupal Core GUI, it should be possible to use the new setting.Currently I favor option 3 as it is fully BC and seems directly aligned towards the longer term goal to have a manage display option in Drupal Core GUI.
Comment #220
adamps commentedComment #221
jonathanshawSorry for not replying Adam, I ran out of steam with it.
Comment #222
adamps commentedOK I think we are so close, I will keep working to find the patch that has no disadvantages. The only uncertain part of the patch is how we enable/disable the special preprocessing of base fields.
#215 created a new setting in the expectation it could eventually be used in the core GUI. As @Berdir says, I should keep each issue to the minimum. We should leave the eventual GUI and it's associated settings to the next issue.
#212 created a per-theme setting. That's not really right as manage display settings as shared for every theme. Plus we don't want to make a setting and force the eventual GUI to make another setting.
This new patch uses an additional property on the node entity type. There is no new setting. When we eventually make a setting/GUI in core, we can add code to automatically set the property. Any module that wants to disable the processing needs this code.
It's very similar to writing code that calls
setDisplayConfigurable().The interdiff from #212 is now very small and simple. I would be very grateful if someone can set to RTBC.
Comment #223
jonathanshawI'm not sure there is one. Dries' recent blog post points to D9 in 2020. And for D9 we will want to default setDisplayConfigurable to TRUE and remove this legacy preprocess code altogether.
I'm not sure that's necessarily a valid objection. It's only a problem if we knew we wanted to create a site wide GUI. But I'm not sure we need a GUI, and the per-theme settings GUI is a good enough place for it form my point of view. Whether you want to bypass this preprocess or not depends on what you're doing in your theme templates.
Here's my current thinking:
we should make it so that a site that (a) is a fresh 8.7+ install and (b) uses custom code to setDisplayConfigurable(TRUE) works perfectly, as if it were D9 already.
This requires that (a) whatever it is we check in the preprocess, it's something that defaults to passing on a clean install, and (b) we don't omit to also test isDisplayConfigurable().
Does this make sense as the goal?
Comment #224
adamps commentedOK I've read your arguments, but I still have the same opinion as before. Let's see if I can explain why.
OK but:
Therefore I feel that whatever work we do on D8 has substantial value. We should not just give up, but the opposite: do as much as we can as soon as we can, subject to high standards of quality. The work we do in D8 likely helps D9 anyway. It would be nice to make substantial progress in 8.7.
I think many people want a GUI and it's exactly what the parent issue calls for. Potentially people will be happy for the GUI to be in a contrib module, but core would be the ideal.
As per the previous point, the principal motivation is to allow manage display in GUI, ideally core, or at least contrib. Calling setDisplayConfigurable is not-per theme and "Manage display" settings are not per theme. Hence the underlying code to disable preprocessing of base fields needs to work whatever the theme.
If I understand correctly, you suggest a possible secondary motivation to allow one site to use multiple themes and for those themes to make different choices about preprocessing base fields. However, as you said yourself, the preprocessing will be removed in D9. All we need here is a simple mechanism to handle back-compatibility. I don't think we want to introduce new complex mixed use cases on top of something that is already deprecated.
Well it sounds nice, but that's tricky in several ways.
In summary, I think that the current patch is simple and clear. True it's one extra call, a site that calls setDisplayConfigurable also must call
set('bypass_base_preprocess', TRUE);but it's not so hard, and that would normally be done by the contrib module or even core anyway. In comparison, the goal turns out to be trickier.========
Next step: either I haven't convinced you, in which case we debate further, maybe even chat offline. Or if I have, it would be great if you could review the patch.
Comment #225
jonathanshawI was worried that might be the case. I was wondering if the theme setting approach from #212 delivers this without the update hassle; I don't understand theme settings enough to know.
Comment #226
jonathanshawI'm coming round to the idea that #222 is a good approach. It creates a crude switch for developers wanting to bypass the problematic code in the preprocess function.
And that's all we need; in D9 we remove the problem code from the preprocess altogether, but for now with this patch anyone who wants to bypass it can.
RTBCing to seek approval of the solution in principle; the tests need revision if this is the approach we settle on.
Comment #227
adamps commented@jonathanshaw Excellent, thank you.
I have updated the CR to match the latest patch - please review and improve as required.
Please can you explain what revision to tests is required? I already added
hook_entity_type_build()tonode_display_configurable_test.moduleand the tests all pass.Comment #228
jonathanshawYou're right, I only glanced before but the test itself is OK. But ....
All these comments refer to the previous approach and are misleading now.
Comment #229
adamps commentedIs it really so bad? Basically this a test to set base fields to configurable display using
setDisplayConfigurableand then check that the chosen output is respected.I agree that as an implementation detail, node_display_configurable_test also has to set
bypass_base_preprocess. However I feel that the comments regarding the primary purpose of the test are still accurate. The same module and test file will continue to be used and enhanced for the other issues that we split off.However I can flesh out some of the detailed comments, so here is a new patch that does that. Also I have fixed the comment "Tests the html head links" which presumably was a block-copy error!
Comment #230
jonathanshawFair enough.
Comment #231
adamps commentedThanks @jonathanshaw.
To the core committer - hopefully this is the patch that you can commit without reservation, thanks!
Comment #232
larowlanThis is looking good, is there a reason why we only did node though? Should we be doing comment, taxonomy term etc in the same patch?
As I see it (correct me if I'm wrong) but the main issue is with these unsets. Is there any harm in leaving the new variables (date, label etc) around even if we have the display configured fields?
That way we don't need to mark the fields as optional and themers can depend on them being present if they need them.
We would have to do something about the new label conditional in the template though.
nit: its a test module, not a dummy module
This is a good approach, but I think we need somewhere to document it, at present it lacks discoverability.
and then check that the chosen output
+ * is respected.
this violates our coding standards, should be a short summary (<80 chars) and then an additional comment if required.
Comment #233
adamps commentedThanks @larowlan.
The patch had got big and people were finding it hard to review/understand, so based on @Berdir suggestion we split it out into multiple issues. See #2993642: Mechanism to disable preprocessing of base fields in taxonomy and aggregator entity types so they can be configured via the field UI. As soon as this issue is committed, I will put a matching patch for the other issue.
1)
Yes unfortunately there is. The call to render marks the field as rendered, which means if you try to render it a second time it outputs nothing.
2) +1 I will fix
3)
Do you have any idea where/how we could document this? In the long term, the goal is to have a GUI in core; in the short term there is a GUI in contrib module manage_display.
4) +1 I will fix
Comment #234
adamps commentedNew patch fixing comments in #232.
In terms of documentation, we have the change notice. I guess we could also make a page on https://www.drupal.org/docs/8.
Comment #236
adamps commentedFix deprecated functions
Comment #237
berdir> Yes unfortunately there is. The call to render marks the field as rendered, which means if you try to render it a second time it outputs nothing.
Not 100% sure right now we even can/want to keep them, but what if we still assign it, but as a render array and stop trying to render it early? Alternatively, copy the array into a new variable before rendering it, so it is not passed in by-reference.
Comment #238
adamps commentedI propose that each field be passed in at most one place. This allows a core template to be written with both code for preprocessing and code without and only one of them will actually display.
It would be great if someone could set this back to RTBC
Comment #239
jonathanshaw#232
@larowlan's right that the main issue is with the unsets, they're what must be bypassed.
@AdamPS is right to point out that you can't print the same variable twice
@berdir's right that we could copy the array to prevent calls to {{label}} from suppressing subsequent {{content.title}}
I think the most important point here is that
1) we ultimately want to remove {{label}} and friends one day. They're legacy variables that will always have an awkward relationship with the layout UI.
2) Making these variables optionals is a problem for no one. People making contrib themes need to be aware of the emerging possibility of managing the title as a normal variable and allow for that in their theme. People doing a theme for a single site will either keep using label happily, or deliberately opt in and change their templates to not use it. It's possible we should add to the comment on label with a link to a CR explaining the circumstances is which label is present/absent.
But the bigger problem is already forseen by @larowlan:
#232
{% if label and not page %}Obviously if label is no longer optional this conditional will always pass.
One option is to add a new 'bypassed_preprocess' variable into the template.
{% if bypassed_preprocess and not page %}
The increase in complexity doesn't seem worth it to me, it feels horrid.
Another option is something like
{% if not content.title is defined and not page %}I think this might break BC for people who were using a custom preprocess to add a title variable back into the main content array, without touching their template, and wanted the title to print twice. But there's so many things these people could hypothetically be doing that there's almost no way to make any change that doesn't risk a break for someone somewhere....
Comment #240
jonathanshawComment #241
adamps commentedSorry I don't agree. After many iterations we have carefully restructured this patch in a way that is 100% BC. Nothing is going to break.
We are creating a new mechanism, and yes I agree, sites that opt in to the mechanism will have to follow the way that it works. Sites that set
bypass_base_preprocessmay have to adjust their templates, but this is impossible to avoid. With most of the core templates, the consequences of failing to adjust the template are small - an empty h2.We are following a completely natural path here: label becomes optional with this change, and then perhaps in D9 we can retire label entirely. The template adjustments are minimal and intuitive.
The alternative is to set
labeland then the template uses some other mechanism controls when to ignore the label. Then a site that fails to adjust the template would have a duplicate title, which seems worse. Furthermore there is additional complexity and increased difficulty to eventually simplify.I agree we need to document what we are doing clearly and carefully. However we have now split everything into many many issues so this issue is far from the complete solution. I think we need to see the whole picture before we can document it. I have raised #3011017: Document manage display of base fields and marked it as postponed.
Comment #242
adamps commentedAdvance warning: I will be taking a break from Drupal.org for December and January.
Please, please can we try and get this issue in before that?
There has been a huge amount of work by the community with over 50 patches and 100s of hours of unpaid work. Likely thousands of users would like to have this function, available in D7 in the hugely popular title module. Seeing as we have split everything out, there are multiple follow-on issues before we have a fully working solution that are currently blocked.
The patch is 100% BC and there is a contrib module Manage Display that proves it does achieve the desired end goal.
The latest patch changed two comments in response to #232, and I believe we have answered the other points raised there.
Next step: please can someone confirm the comments are OK then set RTBC?
Comment #243
jonathanshawI'm not sure that can be guaranteed. Core's node template relies on the variables having the meanings given to them in core's node preprocess. If someone uses their own preprocess function to mess with the meanings of the variables, without changing the template, then any change we make to the preprocess or the template cannot be guaranteed to not break. My point was that this is a hypothetical risk that has no absolute mitigation and should be ignored, we don't need to discuss it more. Core offers no BC guarantee for render arrays.
You haven't actually addressed #239: is there a reason to prefer
{{ if label and not page }}instead of something along the lines of
{% if not content.title is defined and not page %}?
The latter would allow us to not have to change #label to optional, which @larowlan was interested in.
Comment #244
adamps commentedOK fine - but just in case anyone is worrying, I will re-emphasize that we don't change the preprocess result unless a site has opted in by setting a new option
bypass_base_preprocess, so the render array is actually BC. The templates have changed, but only to suppress printing of an empty label and it's hard to see how that could be bad.I don't think it would really. The label is optional either way in the sense that it might be blank. What you are doing is to alter the way of testing whether label is blank.
This seems clearly superior because it directly tests whether the label is present in a clear and obvious way.
Now we are testing a secondary variable
content.titlethat we believe has a relationship to label. However if people write a custom preprocess function that belief might turn out to be false. This way is a potential BC break because if a site has set the content.title variable for some unrelated reason then their title will disappear.Comment #245
jonathanshawSo we've considered what @larowlan asked us to
Comment #246
adamps commentedWe seem to have consensus for the approach here, so I have created a matching patch for #2993642: Mechanism to disable preprocessing of base fields in taxonomy and aggregator entity types so they can be configured via the field UI. Please can someone review it?
Comment #247
alexpottThis needs documenting somewhere. Not sure where though. Also I think documenting it will reveal a flaw in the naming. I.e. if it did what it implies it did I would expect the code to look something like:
But the thing is it is a partial bypass. I think the name needs to reflect what it is really doing. It is extremely specific to nodes and only certain things it adds. I'm also not sure why we don't check whether the fields have a configurable display in the preprocess function. Ie. why is the bypass_base_preprocess thing necessary?
Comment #248
alexpottBack to needs review to get an answer to #247
Comment #249
jonathanshawThat was our first approach and it is more elegant. However, it is potentially disruptive for anyone who has previously made these fields configurable but still expected the current preprocess behaviour.
We changed to the bypass approach in response to your feedback [#171.1].
Comment #250
alexpott@jonathanshaw - ok that makes sense. So I still think we need a better name that reflects what this is doing and there needs to be documentation beyond a change record.
Comment #251
adamps commentedNaming
Yes it is a partial bypass - it bypasses preprocessing of base fields, but not of other fields. This distinction is made clear by the name bypass_base_preprocess. Please let me know if you have an idea for a better name.
Yes it is specific to nodes, because the option is set on the node entity. The same option is available on some other entity types as part of #2993642: Mechanism to disable preprocessing of base fields in taxonomy and aggregator entity types so they can be configured via the field UI. This allows developers to choose separately for each entity type:
Documentation
We have split the overall problem into multiple sub-issues (see #2353867: [META] Expose Title and other base fields in Manage Display) to make it easier to commit. That means there is a series of other issues blocked waiting for this one. Therefore it would be a huge help if you could commit this fix now, and we can follow up with documentation later. I give you my firm promise that I will write some documentation in time for the release of 8.7.x.
For the documentation part I have raised #3011017: Document manage display of base fields and marked it as postponed because:
Comment #252
adamps commentedHeads up on availability and timing
It would be extremely helpful if possible please to get a commit in the next few days so I can upload patches for the next issues. 1000s of users of D7 title module are anticipating the equivalent function for D8, and I get regular issues raised on manage_display module by people who didn't realise they needed a core patch for this basic function.
Comment #253
alexpott@AdamPS
baseto me meant only the preprocess from the module and not the theme. Base has way too many meanings. I would suggest that the it be called something likenode_basefield_skip_preprocess. Documentation is a core gate and should not be skipped for a speedy commit. Adding some random state to the node entity type needs to be documented somewhere.As a place to document things I suggest starting with the docblock of template_preprocess_node() as its when you override this you need to be aware that some contrib module might be setting this flag.
Comment #254
jonathanshawThat seems fine to me and is an easy fix.
You may worry that it sounds like skipping preprocess on - all- base fields. The obvious solution to that worry would be to have 3 settings for the 3 skipped fields, named for each. But as Adam has pointed out before, that leads to more awkward edge cases because the preprocess logic about authoring information works with both uid and created together.
Comment #255
alexpott@jonathanshaw I'm open to suggestions on the name - I just think that
bypass_base_preprocessis really obscure and doesn't help a developer work out what it might do.Comment #256
adamps commented@alexpott Thanks for your time and suggestions. I very much appreciate your hard work to keep Drupal stable for all of us and understand that you have to uphold the quality level.
I have applied your suggestions except that I used
basefield_skip_preprocess. The 'node' part seems unnecessary because the flag is set directly on the node entity:Rather than:
Comment #257
alexpottentity flag is new terminology. It's an
additional entity type propertysee\Drupal\Core\Entity\EntityType::$additional. Also this is why I think prefixing with node is a good idea. Because the object this is retrieved from is a ContentEntityType object.hook_entity_type_build(). Let's also add
@see hook_entity_type_build()makes the display node's base fields configurable via the field UI. Let's add an
@see \Drupal\Core\Field\BaseFieldDefinition::setDisplayConfigurableto the doc block.@see's go at the end.
Comment #258
adamps commentedMany thanks for a quick turnaround - here's a new patch.
Comment #259
alexpotthook_entity_type_build()
module enables manage displaydoes read quite right to me. That's why I re-wrote it in my last comment. At the very least I think manage needs to bemanaging theormanaging base fields' displaybut I prefer what I wrote the first time around as the important thing is that you're now using the Field UI to manage their display.I don't think we should add this. It's an implementation detail.
Needs a () at the end
Comment #260
jofitzMade changes suggested by @alexpott in #259.
EDIT: Apologies for the mis-titled patch file
Comment #261
adamps commented@alexpott thank you for your patience and many apologies I didn't get it right. Please bear with us, hopefully it's now correct.
Thanks @Jo Fitzgerald. Unfortunately one comment line is too long in #260 after adding brackets - here's a fix.
Comment #262
adamps commentedPlease follow #2993647: Correctly determine when to display fields as inline which is the next step and has a patch that needs review. This issue has 50 followers, but the other one has just one and that's me! I can't get it done all by myself.
I will be away for Dec/Jan so it would be useful to get a review from someone now if possible please.
Reminder: we split the original problem into multiple issues and this fix alone is not enough to get manage display of node title working perfectly.
PS Please can a member of the community set this to RTBC so that the core commit team know it's ready to go.
Comment #263
thejimbirch commentedComment #264
alexpottWe need to update the issue summary. It needs:
My big fear about this change is that whilst it is not disruptive to existing sites it makes any contrib modules that leverage it potentially very disruptive to existing sites that use contrib themes.
Also the change record needs updating for the latest changes.
Comment #265
adamps commentedThanks @alexpott, here is the IS. CR coming up next, but first I should save my edits here so I don't lose them by mistake.
I agree that is an important factor, and it has been very carefully considered when coding this patch. It should not be 'very disruptive', but it could be 'somewhat disruptive'.
For an existing site (that enables this feature and fails to update templates) if the template closely matches the default, then the consequence is only an unwanted empty h2 tag.
Comment #266
adamps commentedCR done.
Comment #267
dqdAwesome progress here! +1 for all the hard work on this. Would love to see this in before freeze!
Comment #268
adamps commentedI am now on a break from Drupal.org
Hopefully this will now get committed. However if any more work is needed (with luck a simple fix), it would be great if someone else could step in.
Finally, reminder please follow and help review #2993647: Correctly determine when to display fields as inline - without that fix there are other bugs and there won't be a working beta of Manage Display module for D8.7.
Comment #269
plach+1 on the idea!
Just a few nitpicks after a quick code review:
What about
node_base_field_skip_preprocess? :)These would be more readable if we were using the full method notation:
::setDisplayConfigurable()."Tests"
Also, the @see item looks extraneous.
"Sets"
::urlInfo()is deprecated, we should use::toUrl()instead.Why isn't
display_submittedenough here?Comment #270
jonathanshawFor basically the same reason that we need
{% if label and not page %}not just{% if not page %}: we can no longer rely on the field variables label, author_name and date always being present.We could in theory make sure author_name is always present (by copying the array variable to bypass passing by reference so that its rendering here does not prevent it from rendering as a normally managed field later).
While this approach of non-optional variables might seem to make sense for author_name & date (where there is a setting provided on the content type for the very purpose of controlling the display of author and date) it is more awkward for title because there the sitebuilder or even the developer are not provided with a way to turn off the printing of the label. This means that when the title is also treated as a configurable field in the way this issue enables, it would still end up being printed in front of the other fields as the label. Therefore we have to have the label variable optional, not present when managing the title as a normal field.
TLDR; it's debatable but it's for simplicity:
{% if display_submitted and author_name and date %}is used to keep the logic closely parallel to that required for the title:
{% if label and not page %}Comment #271
larowlanFor last couple of comments
Comment #272
alexpottThe interdiff is a bit odd because there was a rebase too.
Comment #273
jonathanshawComment #274
adamps commentedMany thanks @larowlan and @alexpott. The new patch looks good to me. The patch has now been reviewed in detail by many experts and also tested in the real world (contrib module manage_display has 7000 downloads).
It would be great if we can get a commit soon as 8.7.x alpha is not so far away and there are multiple follow on issues waiting.
Comment #275
panchoI agree with @jonathanshaw that we should handle this in a way consistent with
{{ label }}. This way we're documenting that the presence of these variables can't be relied on.However, why do we do this in
core/themes/bartik/templates/node.html.twigbut leave it out in all the othernode.html.twigfiles?Setting back to needs review to doublecheck if there's a deeper reason or if it was just left out.
Otherwise an excellently documented and tested patch implementing a very simple (though important) flag, so apart from this it should remain RTBC.
Comment #276
adamps commented@Pancho Thank you for a detailed review, well spotted. That change not be present on
core/themes/bartik/templates/node.html.twig.The reason why we don't need the code is because of the logic in
template_preprocess_node.author_name,dateetc. are blank only if $preprocess is FALSE, in which case display_submitted will also be blank.FYI the code was previously present in all copies of
node.html.twigand later got removed, but this once case was missed out. The current approach is much preferred because the template change is less impact.Comment #277
adamps commentedLet's get this back to RTBC - please can someone review? Just a one line change, the tests are passing. It's simple enough that you don't need to be an expert - just look at the code in node.module and check agree with my claim that
{% if display_submitted %}is a sufficient test.Comment #278
jonathanshawAs usual @AdamPS is right.
@Pancho correctly understood the thrust of @plach's #269.6 which I misunderstood in #270, and my line of reasoning in #270 was wrong anyway for the reasons @AdamPS explain in #276.
Comment #279
larowlanaround patch 200 or so we swapped from using ->isDisplayConfigurable to using this flag - can you elaborate on why that was done in the issue summary (tagging as such).
there is talk of BC but its not clear to me why
Why do we prefix this with 'node' - we know its a node because of the entity type, why not make it base_field_skip_preprocess?
Comment #280
imclean commented#279.2, see #253.
Comment #281
larowlanThanks
Comment #282
adamps commentedThanks @larowlan for continuing to give your time to this issue.
#291.1 The key comments relating to your question are #171
#172
#178
#208
#213
I have created a new section in the IS to summarise. I hope this answers your questions.
Comment #283
plachThanks a lot for the updated summary, that's very useful!
@larowlan and I have been discussing this a bit more, given that we both weren't feeling completely ok with the current approach. We both agree with the end goal of not special-casing base field display, we just had some doubts about the best way to get there.
We'd like to suggest the following way forward:
enable_base_field_custom_preprocess_skipping(or something similarly ugly we will be happy to deprecate later on ;)FieldDefinitionInterface::isDisplayConfigurable()for each entity field. When preprocessing is combining two or more rendered fields, check that none of their displays is configurable.enable_base_field_custom_preprocess_skippingflag.Comment #284
plachOf course, only bullet 1 and 2 would need to happen in this issue :)
Comment #285
adamps commentedHere is a new patch that addresses 1. and 2.
The title field can now be controlled independently whether it has special preprocessing.
Yes, the uid and created fields go together as a pair. If
enable_base_field_custom_preprocess_skippingis set and either of the two fields is display configurable, then the special preprocessing is skipped. There's no way around that as far as I can see: the method of special preprocessing anddisplay_submittedonly works if both fields are preprocessed. If we preprocess just one field then that field is not displayed at all.Comment #286
adamps commentedOops previous patch has a bug with an extra !
Comment #287
adamps commentedRegarding 4. The contrib module manage_display contains formatters that exactly replicate the current core behavior without the need for layout builder. There are new custom formatters for "title" and "submitted". I hope that these can eventually become part of core.
I am not very familiar with layout builder. I could see how to use it to replicate the existing core behavior of the submitted field where the author and date fields are combined into a single sentence "Submitted by XXX on YYY" with an optional user picture first.
Comment #289
plachThanks for the updated patches!
Through LB it should be possible to assign the node title as a standalone field block to the page title region, thus matching the current behavior. The markup might be different though, so we might still need some additional tweaks.
Not sure about the "Submitted by XXX on YYY" output TBH. The fact that it involves two fields makes me think that a custom formatter might not be the right choice, as formatters are designed to handle a single field. Since it's a whole (translatable) sentence, we cannot simply add two separate inline blocks, one for each field, so the only idea that atm comes to my mind to replicate the current behavior and keep everything configurable through the UI, could be a custom block, ideally supporting any entity implementing both
EntityOwnerInterfaceandEntityCreatedInterface(the latter does not exist).Comment #290
panchoLOL. This is funny, and I get the logic: you're avoiding a switch that is acceptable enough to stick and not get deprecated.
However, in the meantime outsiders who happen to take it serious or who don't wish us well, might use this as an example how "weird and clumsy" Drupal supposedly is. So while I don't think it is necessary at all to be extra clumsy, at least we need to add a comment that we did this on purpose.
Comment #291
plachYou're welcome to suggest something less weird and clumsy conveying the same meaning, I don't mind to be honest :)
Comment #292
pancho[minor edit: numbering was incorrect]
A.), was 1.)
Oh sorry, I didn't mean to be that honest... did I read your wrong and this wasn't on purpose? 😳
In that case sorry again! However, how about just 'skip_custom_preprocessing'? It has to be correct, sure, but does it need to have everything in it?
B.)
True, but as plach said, formatters on their own can't handle multiple fields. manage_display uses a custom preprocessor, too:
C.), was 2.)
Regarding the two proposed options 1) use Layout Builder on default, or 2) refer to Layout Builder, I'm not overly confident this is a good idea. Last time I tested it, Layout Builder was far away from being stable enough to be enabled on default or worse: (more or less) forced on site-builders. I'm quite sure we would receive tons of complaints, bug reports and support requests. This plus: I always thought Layout builder should remain an alternative rather than more or less replace our existing UI. Otherwise I would be shocked, too.
So, while it would be nice to have a custom Layout Builder block as well, I generally tend towards thinking: "If something's missing in order to convert existing Core functionality to a new Core paradigm, then seize the opportunity to make it generically possible." This might be much more work than a quickfix, but IMO worth it, because it can (and will) be reused for all kinds of totally different sitebuilding scenarios.
In this case, this would mean adding a super-super-basic "Display Suite" (also a bit like "Field Group") kind-of API and UI to Core that allows creating configurable extra fields to combine two or more real fields into one, possibly using field tokens. This would be sooo awesome, and would by the way allow for properly replacing (not just deprecating) current custom 'submitted' preprocessing without forcing Layout builder on anyone.
And as you said in #284, of course this doesn't have to happen in this issue here. We can try and implement this feature to have it in place until D8 LTS, and only if we really shouldn't get it right in time (which I'm not expecting), we'd refer to the one-off Layout Builder block.
Comment #293
adamps commented1) Regarding the name of the additional entity type property: I assure you that I take the matter of core patches seriously and do not intend to be purposely clumsy. There has been a lot of debate on this in past comments so please do read through that as it will help you avoid suggesting something that has already been rejected with good reason.
I think the consensus of earlier comments is that it is essential for 'base_field' to be in there, so it would have to be at least 'skip_base_field_custom_preprocessing'. However that's not right either, because that implies this property will always cause the preprocessing to be skipped which is not true. Instead this property allows the preprocessing to be skipped if the fields are
isDisplayConfigurable. Therefore the name 'enable_base_field_custom_preprocess_skipping' although long does seem to be what we need.To a degree it is subjective and therefore each person will have a different idea of the perfect name. I prefer to give precedence to the people who are most involved/expert and I note that plach has been credited on 51 commits to Drupal core in the past year. Every change to the name needs a change to the patch, the IS, the CR, the contrib modules that use this, so please let's not change it without a good reason. Finally, this property is intended for removal again in D9 and that's not so far away now so it's perhaps not so important to keep debating the name and instead please please can we focus on ensuring this patch gets into D8.7 before the feature freeze date next month.
2) The discussion of plach's item 4. regarding replicating core etc is out of scope of this issue. There have been some good points raised in recent comments, but I suggest that we don't discuss it further here as this issue already has 292 comments. In the end there is likely not going to be a single right answer. LB can implement something beautifully styled with a custom block however nothing here is forcing anyone to use LB; contrib modules can implement something a bit hacky (yes I will admit to that) but that works well in the short term; there might be other ideas using calculated fields or hook_entity_extra_field_info() or yes even inventing entirely new mechanisms.
Comment #294
adamps commentedNB in case of any confusion, the patch that failed testing was not the most recent one. The tests are all good.
Next step please can someone mark this as RTBC?
Comment #295
plachFirst of all, thanks @AdamPS for the continued effort here, we are very close to commit and I see no risk of this missing the alpha deadline!
I agree with some points raised in #292 (thanks for that!) and I agree this is not the issue to debate point 4, which is the trickiest of the proposed roadmap, given that step 1 and 2 are being implemented as suggested.
Sorry for not being clear here: as @AdamPS explained perfectly in #294, the name was not long and clumsy on purpose, it's just that to be sufficiently self-explanatory I couldn't suggest anything better. The sentence above was kind of a joke, although it's normally a good practice to give ugly names to stuff that is meant to be deprecated/removed.
It's perfectly clear that @Pancho meant no offense in #290, so let's keep working together towards a final RTBC. No hard feelings I hope :)
A code review will follow shortly, didn't have time to look at the updated patches yet.
Comment #296
panchoACK.
Also recategorized as a task. This patch smoothes out an inconsistency rather than really introducing a new feature.
Now this has aleady been RTBC several times, and all outstanding issues have been sufficiently resolved. We even figured out multiple options how to proceed, which I think was important not to defer to a followup. Further discussion and the actual implementation however have to be deferred to followups, so I really think this should finally go in.
Hope I didn't miss anything on this loong issue, but am rather confident that it is ready now.
Comment #297
panchoP.S. Think @Berdir and @plach should absolutely be credited as well.
Comment #298
jonathanshaw@AdamPS, perhaps it would be good to update #2353867: [META] Expose Title and other base fields in Manage Display with the follow-ups 3 and 4 requested by @plach and a link to the discussion here?
Comment #299
plachThis looks really solid, I only found minor coding standards or readability issues. We are very close!
I'd find the code more readable, especially below, if the variable name were mentioning preprocessing explicitly, e.g.
$skip_preprocessingor$skip_custom_preprocessing.This comments exceeds 80 chars.
We need to create a follow-up issue to be referenced here. That would be a good place to resume the discussion around Layout Builder and friends.
We should also add the suggested roadmap to the parent meta and create an issue to deprecate the existing cruft.
Also, nit: Missing @todo indentation.
Maybe it's just me, but I'd find this condition group more readable if it were
!$a && !$b && !$c.If we change the conditions above, we should change also these for consistency.
Nit: double space before "This".
As previously pointed out, still having this setting is tricky. I agree with:
We should have an issue in the parent meta to remove this setting from the UI entirely once fields are fully configurable through the UI. Meanwhile, modules enabling the flag should likely gray out the setting and add an explanation in the setting description.
80 chars exceeded.
Is the comment referring to the node custom preprocessing? If so "custom" instead of "special" would be more consistent. However, if this is the case, maybe the comment needs to be reworked, because the if test is about the "display_submitted" setting, not the custom preprocessing logic.
Also, 80 chars exceeded.
This can be simplified to
!empty($variables['display_submitted']).As above, should we use "custom" instead of "special" here?
Comment #300
panchoHere we go.
Fixed 1-2, 4-6, 8-11.
Still to do:
3. We need the followup issue first to add it into the comment
7. Is there something to do at this point?
11. I'm still not happy with:
Comment #301
panchoad 3.) Ah, there it is: #3015623: [PP-many] Remove outdated code relating to "Expose Title in Manage Display". Added to the @todo comments.
Still to do:
7. Is there something to do at this point?
11. I'm still not happy with:
Comment #302
plachThanks!
7: This:
:)
11: Neither do I, but it doesn't seem a blocker honestly
Shouldn't this be
!$a || !$b?Comment #303
adamps commentedOK I am working on a patch but I see there is already a patch from Pancho. So here are the comments I have written, but my patch hasn't finished testing yet. Please can any reviewers just give me a chance to compare/merge my work in before reviewing.
Thanks @plach, good nit-picking! All done, except if indicated otherwise below.
3, 7. The follow-up issue to remove outdated code already exists: #3015623: [PP-many] Remove outdated code relating to "Expose Title in Manage Display". I have added a link to it in the code. I have updated the issue summary in the META issue to make an explicit link from there.
I created a new issue to cover adding formatters, LB blocks and so on #3033301: Add formatters and other mechanisms as alternative to base fields directly in entity templates - anyone who is interested feel free to comment and improve this issue. I linked it from the META issue. It's didn't seem to make sense to link this one from the code because that's not what the @todo in the code is about.
4, 5. Well the existing code is actually
!(a && (b || c)))so the alternative is!a || (!b && !c). However I'll take the hint that's it's hard to follow, and split it out into two lines by sayingd = b || c. So now we have a choice between!(a && d)or!a || !dand I don't have a strong opinion. I had originally picked the first one because it more closely matches the sentence in the comment. However the second one has less brackets and you prefer it, so let's swap to that.Comment #304
plachCorrect!
(this was indeed hard to parse :)
Comment #305
adamps commentedNew patch similar to #301, except fix/simplify the logic of the complex if statements and improve the comments for RDF.
Tested in my local box with manage_display module - matching new release available publicly soon.
Comment #306
panchoThanks, I was just about fixing #303, but there it is. :)
Comment #307
adamps commentedI believe all the follow ups are in place now, so removing that tag.
Comment #308
plachThanks both, this looks ready to go now!
Comment #309
panchoAwesome!
Again, somebody please add Berdir and plach to the credits.
Comment #310
larowlanUpdating issue credits for those who reviewing and helped shape the patch.
I've flagged with other committers that I intend to commit this tomorrow, but have given them an opportunity for another review in the meantime.
To all involved here, especially @AdamPS @Pancho and @JonathanShaw, thanks for your patience and consideration of feedback.
Comment #312
larowlanCommitted 2541973 and pushed to 8.7.x. Thanks!
Published the change notice
Comment #313
adamps commentedExcellent many thanks @larowlan and all the other committers/experts for your time. Thanks also to everyone who helped, most especially @JonathanShaw for so many reviews.
This issue is not suitable for cherry pick into D8.6, but in case any wants to apply it locally I have uploaded a re-roll against D8.6.
Comment #314
adrian83 commented🎉 Wow, watching this favorite issue of mine play out was a huge learning experience to me! Congratulations and thank you, AdamPS, JonathanShaw, and core committers for pushing this through. The ability to manage base fields in the Manage Display UI for all view modes is a huge win for the usability of Drupal display modes.
Comment #315
adamps commentedNext steps
This issue was split into 3 parts to allow easier commit. It's now time to move our efforts to the other 2 parts, so please come and follow.
It would be easier and less confusing for the community if we could get either one or both into D8.7. I realise time is tight now, but also I hope that we have done all the hard work now, and the rest is just tidying up.
enable_base_field_custom_preprocess_skippingto ensure full BC. There are no further template changes so perhaps even if we miss the alpha deadline it could be cherry picked as a bug fix .Comment #316
skaughtcheers!
Comment #317
xjm@plach and I both looked at this issue's release note and change record, and we didn't see any disruptive changes that would need a release notes mention, since it's explicitly stated the change is backwards-compatible.
If that's incorrect and there is a disruption, let's update the CR and especially the release note to explain the specific disruption (and then re-tag the issue). Thanks!
Comment #318
adamps commented@xjm Although the fix is fully BC, the reason we might want to bring it to people's attention is so that theme developers can update their themes - ready for site owners to enable the feature using contrib and in future perhaps directly in core. Anyway fine by me whatever what you think best.