This issue has been split off from #2353867: [META] Expose Title and other base fields in Manage Display as one of the steps in the overall process. Specifically this issue covers enabling the fields in Manage Display settings, following on from the work of #3033301: Add formatters and other mechanisms as alternative to base fields directly in entity templates which created the necessary formatters.
This applies to base fields that are displayed with setDisplayOptions() but are not configurable with setDisplayConfigurable - instead they are hard-coded into the field template with custom preprocessing. The full list of fields can be found by searching the code for the flag enable_base_field_custom_preprocess_skipping.
Proposed resolution
Update the base field definitions. We can use the node title field as an example, see Node::baseFieldDefinitions().
The current base field definitions are:
- type = string
- display configurable = FALSE
- extra preprocessing in
template_preprocess_node()= TRUE - special inline display in
node_preprocess_field__node()= TRUE
The new base field definitions are:
- type = title (new formatter created as part of #3033301)
- display configurable = TRUE
- extra preprocessing in
template_preprocess_node()= FALSE - special inline display in
node_preprocess_field__node()= FALSE
In addition to the base field definitions, the GUI setting would also trigger the following changes:
- The node content type setting "Display author and date information" no longer exists
- The theme settings for user picture are removed
- The user name field becomes a label
Transition/migration/deprecation
Proposal is a GUI setting that enables this feature, switching from the old base field definitions to the new ones. As part of #3015623: [PP-many] Remove outdated code relating to "Expose Title in Manage Display" we propose to deprecate, and eventually delete the extra preprocessing. At this point, the GUI option would be removed, and the new base field definitions would always be used.
Other options are likely not acceptable for BC:
1. If we enable isDisplayConfigurable() but do nothing else then the result is basically worse than useless because we expose the problems in #2923701: Mechanism to disable preprocessing of node base fields so they can be configured via the field UI - trying to use the Manage Display GUI has no effect except perhaps to generate broken markup. It would not help at all to change the theme or the templates. The only fix is to disable the extra pre-processing which requires custom code.
2. If we in addition disable the extra pre-processing then it's even worse. The Manage Display GUI will now work. However the display settings for each field will be very wrong, and it will be complex and time-consuming to resolve.
3. If we write the entirety of the code in the IS, but without any GUI setting then it's getting better. The display settings for each field will now be set to sensible defaults. However if a site has customised their node template then the results of that will be lost. Some node.html.twig template variables will not be set: label, date, author_name, display_submitted, author_picture, author_attributes. This is the closest I can see without a GUI setting, but I am doubtful the BC rules allow deleting of template variables.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | Manage-display-node.png | 152.43 KB | vacho |
Issue fork drupal-3036862
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
dwwThis is very related to (if not duplicate with) #1399990: Remove "Display author and date information" in Display Settings in favor of listing Author and Date in Manage Displays.
Comment #6
adamps commentedComment #8
andypostLooks it depends on related
Comment #10
vacho commentedThis patch is a starter point to start a code patch that fix this requiremient. The patch let to the user get title field for display configuration:
Still needs works on:
1. Apply patches for this related-blocked issues to test with it:
- https://www.drupal.org/project/drupal/issues/2993647
2. Review this knowed problems/cases:
- Whats happen if the user hide/disable the title? => validate
- Review core/lib/Drupal/Core/Entity/Controller/EntityViewController::buildTitle() compatibility
3. Review node.html.twig to make title field dinamic. Review also the code field--node--title.html.twig
4. Review that no break funcionality for layout_builder module.
5. Review if fix the problems and share knows with another solutions like contrib modules manage_display, title, ...
more issues can appear and needs to fix.
Comment #11
vacho commented...
Comment #13
jonathanshaw#10 is out of scope for this issue in the context of the roadmap #2353867: [META] Expose Title and other base fields in Manage Display.
Regarding the intended purpose of this issue in the context of the roadmap:
I do not believe we should do this anymore. Let's go direct to always setting
setDisplayConfigurable(TRUE). We don't need an intermediate GUI option that we will to deprecate/remove shortly anyway. The proposed solution here would make sense only if core development had a much faster velocity than earlier experience in this family of issues shows that it does.Let's close this issue.
Comment #14
adamps commented@jonathanshaw Let's discuss this idea before changing the status and summaries of all the related issues.
Perhaps I didn't grasp your proposal, however at first glance it seems to break the rules for Core BC
Comment #15
adamps commentedSee comment for explanation.
Comment #16
adamps commentedComment #17
catchAs long as the new fields are only available in display mode configuration, and somehow aren't forced to show on nodes by default, then I don't see how this would break bc or require additional configuration options other than display mode - it'd just be an additional option in manage display.
Comment #18
adamps commentedThanks @catch. However I've thought so more and I'm pretty sure that it's impossible for this to be automatically enabled and still BC.
Imagine that a site edited node.html.twig as follows.
<h3>not<h2>.How could we possibly even imagine an automatic migration process that would parse every single instance of node.html.twig on the site and create the exact same output using field formatters? So if we automatically enable manage display on this site, then there are two possibilities:
Therefore if we are going to remove the extra preprocessing and move to field formatters (which is obviously desirable), there will be a cost:
Would be useful to have thoughts on the acceptability of this cost.
Comment #19
catchRight but there are lots of things you can do in manage display that don't actually look very good. It's not really different to adding a new field formatter that's incompatible with a custom or theme preprocess (which happened to me today).
In that case, the site owner would have to install a different theme, or if it's a custom theme, handle the fields differently in the template, and then update the configuration and theme at the same time.
Yes exactly, but the advantage is that they won't have to handle these fields in node.html.twig ever again, and can do everything in formatters/field templates/manage display from then on.
Comment #20
xmacinfoI don’t expect a theme working fine in Drupal 10 to work without any change in Drupal 11.
Contributed themes will most probably update their Drupal 10 themes to support the new markup for Drupal 11. Although we want the core changes to be minimal.
Custom Drupal 10 themes will definitely need to be fixed to work in Drupal 11, but usually, we would permit the Drupal 10 theme to be loaded in Drupal 11, at the cost of some variables not loading. So it would be easier to change some twig code and debug the Drupal 10 theme directly in Drupal 11. And at that point, the theme does not have any version constraint, Drupal 11 just needs to highlight an error in Watchdog when something is not updated yet to support Drupal 11.
In change records, we could document the old vs the new way to represent a value, use the Title field, etc.
Same thing for field formatters. It is perfectly fine when updating to a major version, to review field formatters and reapply those. Although here, we try to be BC as much as possible.
Comment #21
xmacinfoI think we should switch the version of this ticket to 10.0.x-dev, though.
Comment #22
adamps commentedThanks @catch and @xmacinfo for continuing the discussion.
OK, good so it seems that we are in agreement on that.
In summary, this issue causes a modest migration step, but it seems fine with the normal deprecation mechanism so sites have a whole major release to do it.
On the other hand if we force people to do the migration step in a minor release (and possibly they don't realise the non-BC problem until they can no longer roll back) I feel it would not be welcomed.
The GUI option is not so difficult to write.
As far as I can see it's unfortunately much more disruptive than that. I updated the IS with a list of options that I can imagine without a GUI setting. Number 3 is the best one, but even that I doubt is allowed in a minor release because it deletes template variables and loses customisations. Can anyone confirm/clarify on this?
Good idea, done.
Comment #23
catchFor this I think we're going to need multiple approaches:
1. An 'extra field' which reproduces the current format (By [username] on [date]) so that it's easy for sites to recreate the current look with the new API (also convenient for new sites too in some cases).
2. Also the ability to show the individual fields with standard formatter settings.
I'm looking at the logic we added around custom preprocessing:
And I'm wondering if we could dynamically set is_line based on the display configuration i.e. if the display configuration contains the uid field, then set is_line to false, or alternatively base it on the 'display submitted' configuration option (which we'd then start triggering a deprecation message when that is set in preparation to remove the setting).
That would mean it wouldn't be possible to use both the submitted variable and also have the fields via manage display in a way that would work, but don't think we need to support that and we could even add validation for that case.
Comment #24
adamps commentedThat makes sense, I agree.
The SubmittedFormatter in Manage Display module replicates the current format exactly. If we want to discuss the benefits of that compared with extra fields, we should likely do it in #3033301: Add formatters and other mechanisms as alternative to base fields directly in entity templates.
In
node_preprocess_field__node()we already set 'is_inline' dynamically based onenable_base_field_custom_preprocess_skippingandisDisplayConfigurable. This code already works in 3 cases:My expectation is that the is_inline variable and these special base field templates like
field--node--uid.html.twigcan be deprecated and eventually deleted. They are another part of the 'magic hackery'. We should have a mechanism to display "Submitted by" that works for any entity type including comment and media in core. It's not attractive to add the same magic hackery (quite complex!) to every similar entity type.Absolutely, I agree, the two possibilities are fundamentally incompatible. Manage Display GUI of the base fields only works if
enable_base_field_custom_preprocess_skippingis set, in which case the submitted variable is not set.Comment #25
jonathanshawThanks for your detailed replies @AdamPS, and thanks for staying with us @catch. These are really hard things to figure out, so your persistence is invaluable.
I'm going to take up Adam's invitation to follow up the discussion from #2353867: [META] Expose Title and other base fields in Manage Display here.
The complexities are indeed intricate, and you've led the way in figuring them out. I've reviewed manage_display.module, and spent several hours carefully considering BC strategies here. I'm not sure I'm right, but I am sure these things are complex enough to require
careful discussion.
Strategy B
In #118 Strategy B (safer) I proposed this:
In #121 @adamps responded:
I believe this is all untrue, because of the implications of points B1 and B2.b. Let me explain (which is also repeating @catch's points from #17/#19 above):
I'm not sure what problems you have in mind, but my purpose in suggesting doing B1 first in 9.4 is to make sure that everyone who has enabled isDisplayConfigurable() has also updated their templates. (unless they are ignoring our runtime deprecation errors, in which case they are on their own; this is how core handles BC).
By implementing B1 and B2b, this does not happen. Now that B1 ensures enable_base_field_custom_preprocess_skipping is set on sites where isDisplayConfigurable(TRUE) has been previously set, there are 3 scenarios we find existings sites in:
i. (isDisplayConfigurable was & is true AND field configured to be visible) => preprocessing was & is skipped, field was & is shown normally
ii. isDisplayConfigurable was & is true AND field is configured to be hidden) => preprocessing was & is skipped, field not shown normally or from preprocess
iii. (isDisplayConfigurable was false now true, AND field was not configured is now configured hidden) => preprocessing was not & is not
skipped, field not shown normally but shown via template hardcoding; preprocessing will be skipped and field shown normally not via template hardcoding when the field is configured to not be hidden.
There is one disadvantage to this approach: the manage display UI will not allow sitebuilders to hide a base field if they are using the core templates. If they move a base field into the 'hidden' region (or leave it in there when it's first made configurable), it will still show up in the rendered output because of the preprocess & template hardcoding. This could be a little head-scratching, though may be not more of a WTF than having non-configurable base fields in the first place. The only way to really hide the title would be to set enable_base_field_custom_preprocess_skipping in custom code or customise the template.
Configuration setting
You've proposed a "Gui setting". I'm assuming this is configuration with a UI. The UI is not strictly relevant to BC, we could maybe have configuration without it.
If we go this way, I think we should default the setting to FALSE, both for existing sites and new installs. The reason fot this is as in #118 with regard to strategy B:
it avoids us having us to wait on developing a 100% perfect drop-in reimplementation of the existing experience in #3033301: Add formatters and other mechanisms as alternative to base fields directly in entity templates. This will be hard to, and would force us to perpetuate legacy aspects of the current base field display.
For example, it configurable base fields are purely opt-in, keeping the existing template behavior as the fallback if people don't opt-in, then we don't need to provide a replacement for "Display author and date information" if we don't believe it should be part of Drupal core. People who really want that exact display of authoring info can get it from contrib or custom. And best of all, this whole debate can be allowed to take as long as it likes. We push on with making it easier to customise core (the framework), without having to decide first exactly which options core (the product) should provide.
I think this issue should not be blocked by #3033301: Add formatters and other mechanisms as alternative to base fields directly in entity templates.
Strategy B vs a configuration setting defaulted to false
Both these solutions are undisruptive to existing sites, they're a 100% BC within the scope if this issue.
The hard question is about how they set things up for the final removal of the preprocess variables in future issues for anyone using custom templates.
We can definitely throw a deprecation error in core twig template if a preprocess variable is used, so that gives us a solid coverage for anyone using core templates. It's custom templates that are tricky.
There's various ways of thinking about this.
1. Hardline. @catch said in the meta in #122:
And I seem to remember @lauriii saying something to the effect of "if a template depends on a variable, you should implement a preprocess to ensure the presence of that variable, we can't guarantee it"
2. Major. @catch again in #122 implies that we can do things in a major that we can't in a minor; given they are not covered by BC policy dropping templates variables in a major is OK in theory. But inn practice all these questions are addressed pragmatically based on likely disruption.
3. @catch suggested phpstan. phpstan-deprecation-rules allows emits deprecation warnings on code, which uses properties/functions/methods/classes which are annotated as @deprecated. I don't see how this helps us.
4. The usual core approach is @trigger_error(..., E_USER_DEPRECATED). It's tricky here because the logic path to set the variables in preprocess is harmless, it's using them in a template that we want to deprecate. If we @trigger_error in the preprocess, we cause a deprecation error for sites that that may not need to do anything. We can tell them to either ignore the deprecation error (if not using custom templates or if they want the basefield hidden) or set enable_base_field_custom_preprocess_skipping to silence it.
5. The configuration and UI option proposed in the IS would allow us to trigger a deprecation error on any site that has not opted in to the configuration, telling them they now have to do so (or ignore the error if not using custom templates or if they want the basefield hidden).
So in BC terms the configuration setting turns out to be identical to my strategy B, just more complex to implement and later remove.
Am I seeing this right?
Comment #26
catchIt'd have to be a custom rule looking for particular variable usage in templates.
Comment #27
adamps commentedMany thanks @jonathanshaw for putting in so much time and energy even after my reply in the other issue was a bit negative. I haven't fully grasped all that you say. However I believe I have understood it enough to make some initial comments.
It might be the case that we each of us need to write some patches. I believe I can entirely imagine that patch I would write - indeed it is quite simply a case of transferring some code from Manage Display into Core. Perhaps I should write it first without the config setting. This would stand as a candidate solution for where we IMO are ultimately aiming for.
I don't yet understand how you would achieve some parts of the IS proposed resolution in your solution B.
1. The IS describes 'current' and 'new' base field definitions. How would you achieve the updating of the default type in
Node::baseFieldDefinitions()? The current definitions seem highly unsuitable for use when base fields are present in Manage Display, so we need a strategy to change them. Arguably this is the key part of the whole BC debate, because there is no halfway option - somehow we need to make a change that's inherently not easily BC.2. The IS says: "the GUI setting would also trigger the following changes:...". If there's no config option we would also need another way to achieve these parts.
I believe we are too late for that. It seems that anything deprecated in D9.4 would not get removed until D11. I haven't seen this written down but that was what @larowlan said related to a different issue.
NB the title, UID and created fields are currently visible by default so I don't see how to write code for your concept "explicitly configured to be visible". As soon as someone saves their display settings, config will be saved for the newly visible base field. If the admin didn't explicitly change them, then the defaults will be saved. So I am speculating that the admin makes a minor adjustment to any field display and suddenly their title and submitted display switches to all the "disastrous" scenarios I described earlier.
I agree.
I agree it doesn't have to be a 100% identical replacement, however I feel it does have to be something 100% suitable and at least as good.
One of the key objectives is to deprecate and eventually remove the extra preprocessing. Before we do that, we would need something to replace it. I feel at minimum we need a title formatter, and some sort of solution for submitted information - these seem absolutely fundamental aspects of a CMS that should be in Core not Contrib.
I think the issue as currently described is inevitably blocked because it proposes to update the type of a base field definition to something that doesn't yet exist. Possibly we could unblock it by reducing the scope here. However we should still make sure we know how to solve the entire problem eventually.
Comment #28
adamps commentedIn summary, I agree it would be clearly advantageous to avoid a config setting, so it's a really good idea to explore that. On the other hand, a config setting is not really such a big problem. I am concerned that the alternative might actually create more problems - in the worst case could be fragile, confusing, and prolong the 'agony' of the current confusion multiple stages as we incrementally solve the problem.
Is there really any urgency to press us to make partial solutions? We've made really good progress so far and sites that want manage display can now get it - with some simple hooks, or using the contrib module "Manage Display".
Before insisting that the whole Drupal community adopt our initiative I feel we should ensure that we are offering something they will welcome, rather than dislike.
Comment #29
adamps commentedOK here's another way to look at it.
I have a proposal the create a new setting for Manage Display of base fields. This makes is very clear to people that they have a choice to make and what the implications are.
You are proposing to guess or deduce people's preference based on other settings. This could work, however I am rather doubtful. For example suppose someone hides the title field because they don't want it displayed. This would apparently alter your algorithm and re-enable extra preprocessing meaning the title field actually is displayed based on node.html.twig.
I have probably spent over 100 hours working on this area. I've tried lots of different things in code and my proposal is based on the best option I've found. I think you to explore your ideas further would be greatly assisted by showing a working patch. So many ideas that seem good in theory don't work out as expected when you try to implement them😃. I would very much welcome another developer to share the work and bring new ideas.
Comment #30
adamps commentedOK here's a new brain-storming idea
We create a new setting in manage display for the base fields: "Use node template", which means enable special preprocessing. This is used as the default for the base fields at least for all existing sites. However it is deprecated and later will be deleted.
Comment #32
jonathanshawYou're right, code speaks 1000 words. Some of your concerns above are clearly sensible, some might be misunderstandings of what I did not express well.
So here's what I mean in code, as it applies to the node title, in 4 steps (6 commits of which 2 could have been combined with predecessor).
Can you say in a nutshell what your outstanding concerns are now you see this?
Comment #33
adamps commentedBefore we dive into more detail, I'd like to take a step back.
I have proposed a strategy:
You have proposed a strategy:
First of all please can you explain your concerns with the established proposal😃.
Comment #34
jonathanshawI've created #3270148: Provide a mechanism for deprecation of variables used in twig templates with a working patch that allows us to trigger deprecation errors when deprecated render array keys are used in twig templates. It doesn't help with the rarer cases where they might be used in downstream callbacks or preprocess hooks, but it should substantially reduce the disruption of removing render array keys.
1. The config setting is an extra complication that might become controversial. This is a pretty minor consideration.
2. Whether we use the config or not, I don't see we have to wait on #3033301: Add formatters and other mechanisms as alternative to base fields directly in entity templates before we set isDispayConfigurable(TRUE).
The MR has the wrong target, but the individual commits are fine and should clarify why I think this.
I'm happy to bow out of the discussion at this point, as you say I'm taking up more of your time than I'm saving.
Comment #35
adamps commentedNo I'm not trying to shut you out, rather I'm saying please let's be focused. I'm out of time for speculative discussion. There are two approaches that seem productive:
I'm afraid that they don't for me😃. If you can provide a valid patch for D9.4 that covers all 3 node fields then I am happy to test and discuss. The strategy and patches I am proposing are not perfect but are the best I've managed to get to work. It's easy to bring another solution and say that in a certain aspect it is better. However the alternative solution isn't much use if it fundamentally breaks another aspect. I don't currently see the seed of a working solution in the MR. However I would encourage you to continue to work on it and see if you can bring one out.
I.e. you propose some intermediate state - we would set
isDispayConfigurable(TRUE)first and then the other changes from the IS in a separate issue. Your MR even suggests a series of 4 separate commits/issues. In response I would askComment #36
adamps commentedPlease see the end of the issue summary where I already presented a list of three possible ways to set
isDispayConfigurable(TRUE)and their respective problems.Many apologies Jonathan if I have caused offence. I'm really not wanting to shut down all debate, so I truly hope others will continue to contribute. I have found out the hard way that lots of ideas that seem promising turn out to be very difficult when you start to code them. If this issue becomes a dialogue of others saying "what about this or this or this" and I try to explain for each of them in turn where I think it will go wrong then it takes up more time that I currently have. Please do try to write some code and discover for yourself the answer to whether it works or not. Of course watch out for BC, especially if changing base field definitions or preprocessing. If anyone can produce a simpler solution that what I'm currently suggesting then I will be delighted.
Comment #37
adamps commentedAlready in #27 and #29 I describe several problems that are apparently still present in the MR.
Comment #38
jonathanshawNo worries Adam. I'm going to focus anyway on #3270148: Provide a mechanism for deprecation of variables used in twig templates and more generic approaches to these deprecation challenges.
I thought we could get around that by setting the base field displayOption 'region' => 'hidden'. That's been what I've been trying to get across. But now I'm realising that's simply impossible, we depend on that to have the title at all!
It should have been obvious to me that my code:
is obviously nonsense. I'm check I use
$variables['elements']['title']after it fails an isset!So we need your proposed configuration setting, sorry it took me a long time to get there.
However, I still don't see why this issue has to be postponed on #3033301: Add formatters and other mechanisms as alternative to base fields directly in entity templates. We can allow people to opt-in to configurable display long before we have developed a perfect replacement for the current non-configured approach. If they do opt-in, they might end up with odd feeble displays if they don't make use of custom or contrib formatters. But that's ok, it's just an option, we're not forcing anyone to use it, and surfacing it will probably help us get more contributors, make manual testing of new formatters easier, and lead to more contrib innovation around this.
Comment #39
adamps commentedPlease see end of issue summary. The text has been there for some while, and I've been trying to persuade you to read it😃.
The whole essence of the #2353867: [META] Expose Title and other base fields in Manage Display initiative is that Manage Display of base fields is broken. If we enable it without fixing the problem then we give everyone a broken UI. Any attempt to move the author field around in the display order has no effect. If you set a different formatter then it can cause invalid HTML inside a span tag.
Comment #40
jonathanshawI've read the IS. I'm saying exactly what @catch said to you in #19 above. It doesn't matter if enabling the opt-in makes stuff behave weirdly, it's simply an advanced option that it only makes sense to enable (at this point) if you have additional modules/themes that fix the problem.
Comment #41
adamps commentedHere is what @catch said
Then in #23 I said this
And in the IS is says this
Only isDisplayConfigurable()
Here is my analysis on a possible patch that sets
isDisplayConfigurable()but nothing else:Sites that want the advanced behaviour can already have it right now, without any patch. They can enable Manage Display module, or some other custom module. It's simply a matter of calling
isDisplayConfigurable()and$entity_type->->set('enable_base_field_custom_preprocess_skipping').A patch that sets
isDisplayConfigurable()leads to a broken user experience in Manage Display. How can you fix it? Well you can install Manage Display module. In which case the patch was unnecessary.So I don't understand in what situation it is possible to benefit from this patch.
Changing base field definitions
In #27 item 1 I said this
In my view, this is a strong argument for creating a setting. How else can we change the base field definitions? In the MR there is a commit that nonchalantly changes the formatter type of title, but as far as I can see that would be a significant BC break. If we have a setting, then it's very natural that it would also enable
isDisplayConfigurable()etc. Hence the strategy proposed in the IS.===
Anyway I'm exhausted from this debate. I have unsubscribed from this issue, and please feel free to create whatever patches you wish. I feel I have achieved something by completing stage A of the meta issue, and creating Manage Display module that works without patches to core. I'm quite ready for someone else to take over for the next stage.
Comment #43
ressaThanks for the herculean efforts here, getting "Title", "Authored on", and other relevant fields included in the Display manager, I very much appreciate it!
I'll just leave a comment here, that the overall task is not dead, even though the last comment here could give that impression, and dissuade interested developers ... because it looks like the idea reached a dead end.
But it is still being worked on, see the "META" issue #2353867: [META] Expose Title and other base fields in Manage Display :)