Problem/Motivation
With core upgrade to 11.3.0/11.3.1, a custom twig overriding field--comment.html.twig, using one of the file name suggestions, has null as the value of both variables 'comments' and 'comment_form' and renders nothing.
When this twig is renamed 'field--comment.html.twig' (the default), these twig variables have their respective content and the twig renders the comments correctly.
I am now using core 11.3.1, with the Bootstrap Barrio theme 5.5.2, and a subtheme from that. Running php 8.3.
Steps to reproduce
Add a second comment field to the article content type
Machine name field_second_comment
Create a template in olivero called field--second-comment.html.twig from field--comment.html.twig
Add an article node
Note that the second comment field does not render
Proposed resolution
Render hook name
Remaining tasks
Confirm this is eligible for no tests.
This would be very difficult to test requiring a custom theme and extra comment field, a custom template and more setup.
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
Issue fork drupal-3566261
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:
- 3566261-with-d11.3.0-upgrade
changes, plain diff MR !14294
- 3566261-106-starter
compare
Comments
Comment #2
quietone commentedHi, in Drupal core changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to the Core change policies. Thanks.
Comment #3
ghost of drupal pastThanks for the report. Nic and I both are aware and I will have time over the weekend to look into this if he doesn't get to it sooner. My first guess was it is not comment specific alas rather it's the subtheme and an initial quick investigation seems to corroborate this:
SystemThemeHooks::themeSuggestionsFieldFormatterBasewhich has been unchanged since 2012.Something likely broke either with OOP-ifying the suggestion hooks or the theme engine conversion. More later.
Comment #4
nicxvan commented#1685492: Convert theme engines into services
Is the theme engine conversion for reference.
Comment #5
nicxvan commentedA couple other thoughts.
We should git bisect to determine when this broke.
Possible culprits:
Subtheme - unlikely since most themes are a subtheme
Sub subtheme - unlikely since barrio sets base theme to false
Theme engine conversion
Oop themes
A change in comment module
Something with theme suggestions in general
I have a question too. You said a second comment type are you doing the suggestion on the comment bundle?
Comment #6
nicxvan commentedPlease provide some more details on how to reproduce. I tried to reproduce by doing the following.
I see these suggestions:
For completeness I created a new comment field and added a comment there I see these suggestions on that field? Is this what you meant?
Assuming the second is what you mean I then created :
and I see this on 10.6
Updating this afterwards to 11.3 and running updates I do see something weird.
The thing is I have both field--comment.html.twig and field--field-comment-two.html.twig but the second comment field doesn't render at all.
Removing field--field-comment-two.html.twig brings it back. So yes something very weird is going on, let me try a git bisect.
Comment #7
nicxvan commentedBisect reveals this as the culprit: e6abe62c098dd6ee04e7165678564164330aac6a
#3536196: Investigate preprocess_field in the comment module
Comment #8
nicxvan commentedNo wonder it tickled the back of my mind...
Comment #9
nicxvan commentedI confirmed locally that changing
back to
Fixes the issue.
Comment #11
nicxvan commentedComment #12
nicxvan commentedNeed to update the IS for some clarity, the field doesn't print if the suggestion exists, the suggestion is right, but the preprocess doesn't populate the variables so the comment field does not print.
Comment #13
nicxvan commentedOne final note is that we changed this because the comment said to change it when https://www.drupal.org/node/939462 was resolved and that was fixed.
This proves that both the comment was wrong and test coverage was not sufficient for this.
I'd recommend a quick fix revert the preprocess, then we can decide if it's worth digging in why there is still and issue with 939462.
Comment #14
ghost of drupal pastAh. Thanks for sleuthing, great work. So the problem is not at all new, indeed this comment describes it as a D6-D7 regression: field--comment--foo will call preprocess methods of the base hook (field) it will not call the preprocess functions of field--comment.
Fixing this with a loop that peels off -- sections and calls preprocess on each would mean preprocess functions which didn't fire before would fire now which is probably a BC break so it can only be done in D12. Maybe allowing an explicit list of preprocess hooks to fire on hook_theme would help and for D11.* the current and base hook preprocess could be added automatically to achieve BC and then in D12 the loop described above would run instead.
For now revert of this specific method seems to be the right way forward.
Comment #15
fl-49 commented@nicxvan - Just letting you know that your #6 after creating a new comment field is exactly what I was writing about. A late response to your request for more info, sorry about that. But you all seem to have it well in hand! Thank you!
Comment #16
fl-49 commentedJust curious... will there be a patch file soon I could test out? Thanks again!
Comment #17
nicxvan commentedIf you want to create the MR changing the hook I can create the follow up for the root cause!
If you need help with how to do that don't hesitate to ask!
I've been thinking about the best way to test it in the meantime.
Edited to add: this is a great starting point for some documentation https://www.drupal.org/docs/develop/git/using-gitlab-to-contribute-to-dr...
Let me know if you have any questions.
Comment #18
will_frank commented@nicxvan
I work on the same site as @fl-49 who reported this issue. We can now report that manually reverting the change in this diff that you identified as the culprit indeed fixed the issue reported here. This is the diff file we looked at and manually reverted on our test site. https://git.drupalcode.org/project/drupal/-/merge_requests/12793.diff.
This test was done while running Drupal core 11.3.2. Hope this helps.
Comment #19
nicxvan commentedI thank you for confirming!
I will offer you the same assistance if you want to open a merge request to fix this, the link with the process is on my previous comment. Feel free to reach out here or in slack if you have any questions!
Comment #20
fl-49 commented@nicxvan Thanks for the help offer. I've been a Drupal developer for some time on individual projects but I've never forked contributed code and created merge requests. I'm eager to learn, so I'd like to take you up on that offer. I read the documentation you sent. But I have a very beginner question: Would an MR basically be the full, changed, hook CommentThemeHooks.php? And I create a new branch from your fork? If this tutor conversation should happen somewhere else please let me know. I appreciate your patience!
Comment #21
nicxvan commentedHappy to help, the actual fix would be just changing the hook attribute from
preprocess_field__commenttopreprocess_fieldWe can figure out tests later.
To do this you want to clone drupal from the project page here: https://www.drupal.org/project/drupal/git-instructions
Make sure you have added your ssh keys to your user account.
Then at the top of this issue press the green button that says
get push access.After that click the link that says
show commands.You'll then want to run the first command under
Then run the command under
Check out this branch for the first timeThe other command is when switching between issues after you already have it locally. You won't need this today.
Then you can make the change in the code, commit it and push.
Once you have that I can help further, feel free to ping me on the contribute channel in drupal slack others might help too in that case.
Comment #22
fl-49 commentedThank you! I'll do this and write any more on the slack channel.
Comment #23
fl-49 commentedI've pushed up the change. Again, thanks for the lesson!
Comment #25
fl-49 commentedComment #26
nicxvan commentedComment #27
nicxvan commentedSetting to needs work while I work on a test.
Comment #28
nicxvan commentedI came up with a test setup that I think adds a second comment field to a test entity, we now need to assert that the form is on a display of that entity.
I tried rendering it with viewbuilder and renderRoot was getting this error:
I also tried the kernel->render method, it worked once, but I am not sure that will actually test since we need the actual theme to load the template.
Maybe this doesn't belong in a kernel test.
Needs work still to finish or remove the tests.
Comment #30
godotislateRefactored the test.
Looking back at it, perhaps part of what was missing from the original test was setting the active theme.
Failing test only job: https://git.drupalcode.org/issue/drupal-3566261/-/jobs/7947163
Applied comment suggestion, so build is going again, but previous builds passed. If any tests fail, they'll just need re-running.
I haven't looked at the IS for what updates are outstanding per the tag.
Comment #31
nicxvan commentedThank you so much!
I already updated the issue summary, just forgot to remove the tag.
Comment #32
nicxvan commentedI think this is good to go now, we have a follow up.
I wrote the first pass at the test but it was so significantly refactored I think I can rtbc.
I took a first pass at credit too.
Test only fails as expected and it's essentially a revert of a minor change we just made with better test coverage.
Comment #33
fl-49 commentedUm... I think you can ignore this comment, actually. Sorry... What I describe below, after making the change in this MR, did happen, I had cleared cache and everything. But now it has cleared up and all seems to be working as it should. This MR does look good to me.
I don't know yet if this is an issue with the change in this merge or something else particular to my site's code, but thought I should write before the merge is approved.I added a third comment type (long story but the site uses three -- two are related to proofing unpublished content). The second and third are used on unpublished nodes. When the node is not yet published and the revision is the default, the comments with this fix now work as they should. When the latest revision is not the default revision, one of the comments works fine but the other has null value for comments in the twig.This was not the case with Drupal before 11.3. These comments were working as they should.This has happened when I used custom field twigs (field--field-comment-1.html.twig and field--field-comment-2.html.twig). It also happened when I used field--comment.html.twig with conditional logic for what is different (the comments variable is there for all).The comment-form displays correctly all the time now.I'm trying to track down a cause...Comment #34
quietone commentedTrying to improve the title which is the commit message
Comment #35
nicxvan commentedI iterated on the title a bit.
Did you find the cause of 33? I think it's unrelated.
Comment #36
fl-49 commentedIt seems #33 was a bit of a fluke. It happened on a local and on a multidev. The next day it was fine without us having done anything. I don't know the cause, but we'll watch and see if it comes up again. I agree it seems unrelated.
Maybe the cache didn't fully clear/rebuild? Or maybe it was the cat. She does things...
Comment #40
catchAdding a couple of related issues.
Committed/pushed to 11.x and cherry-picked to 11.3.x, thanks!