Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
In Drupal 8.0.x the UI allows us to create a new view mode for a comment type, but there is no way to use that view mode without writing a custom formatter. Ideally, there should be a setting on the built-in comments formatter that allows us to specify a particular view mode should be used for the comments on a particular content type.
Proposed resolution
- Add a new Comment field formatter setting
view_mode
, defaulting todefault
. - Add an update path to set this setting on existing formatters.
- Test the update path test.
- Allow the new setting to be configured from the view display form.
- Calculate dependencies for the new setting and add appropriate reactions on dependency removal or disable.
Remaining tasks
None.
User interface changes
None.
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#42 | interdiff.txt | 2.07 KB | claudiu.cristea |
#42 | 2627678-42.patch | 22.93 KB | claudiu.cristea |
Comments
Comment #2
jonathanshawComment #3
larowlanThanks, definitely an omission
Comment #4
claudiu.cristeaPatch.
Comment #6
claudiu.cristeaSmall fix.
Comment #8
claudiu.cristeaComment #9
claudiu.cristeaComment #10
claudiu.cristeaOk, it's not straight.
Comment #12
larowlanThis is looking great
nit ===
Trailing space
nice
nice
Awesome
was this duplicated?
Comment #13
claudiu.cristea#12.1, 2: Fixed.
#12.6: Yes, it was duplicated.
Now I added one more KernelTest because I had to fix the case when a commend display, used as setting in field formatter, gets disabled. That case is not covered by calculateDependencies(). We need to act in the same way as we do when we delete de dependent entity — disable the formatter and log a message.
Comment #14
claudiu.cristeaComment #15
jonathanshawPatch works great on simplytest.me. 1 minor issue:
If I add a new comment display mode called "Newmode" then I have 3 display modes: Default, Full comment and Newmode. At admin/structure/comment/manage/comment/display I can assign different display properties for Default, Full comment and Newmode. When got to admin/structure/types/manage/article/display and set the new comment formatter setting in this patch to "Newmode", it works and I get the Newmode comment display mode shown on Articles. But whether I select "Default" or "Full comment" in the formatter setting, I get the "Full comment" display mode either way. Perhaps something is weird about "Default" and it should be excluded from the options presented by this formatter setting?
Comment #16
claudiu.cristea@jonathanjfshaw, thank you for review. Can you try this new patch?
Comment #18
claudiu.cristeaOK. Fixed the crash (hopefully).
@jonathanjfshaw, if this is green, it would be nice to have another review.
Comment #20
ashhishhh CreditAttribution: ashhishhh at Valuebound commentedCan you try pulling code once and create patch again.
Comment #21
ashhishhh CreditAttribution: ashhishhh at Valuebound commentedComment #22
ashhishhh CreditAttribution: ashhishhh at Valuebound commentedComment #23
claudiu.cristeaThe patch is OK. See that it applies in test. You should use the 8.1.x branch and apply the patch on that. But wait till we'll have a green patch, I still need to fix the code.
Comment #24
claudiu.cristeaLet's see.
Comment #26
claudiu.cristeaIgnore patch from #24. The patch was malformed. Interdiff is against #18.
Comment #27
jonathanshawGreat! Sorry for delay in replying. Latest version of the patch fixes #15. I'm not qualified to review the revised code, so leaving status at Needs review.
Comment #28
claudiu.cristeaPassing to @larowlan for a review.
Comment #29
claudiu.cristeaThis can be rewritten in a more nicer way if #2647576: onDependencyUpdating() - React on dependency updating would be committed.
Comment #30
larowlanThis looks really good, a couple of nits and one minor cleanup as well as some random musings that you can ignore unless you feel strongly about it.
Should we have an
@addtogroup updates-8.1-0
or similar here?Should we collate the updated displays and show a message to the user with regards to the changes made?
Random observation: we could refactor this to a domain object that could be unit tested?
nit: === and !==
nit: 'is is using' instead of 'is using'
this hunk could be simplified to
Sometimes I see code that calls ::addDependency and then return the parent result for ::calculateDependencies? Is there a standard for that?
nit: I think new code is supposed to use [] instead of array()
Great work
Comment #31
claudiu.cristeaThank you for review, @larowlan.
#30.1: That's not very clear, I guess. I asked a question here #2624318-5: [meta] 8.1.x upgrade path. For now I wrapped the function in
addtogroup updates-8.1.0
and we'll see what the core committer will say after RTBC.#30.2: OK.
#30.3: We are fully testing
comment_entity_view_display_presave()
in the new Kernel test \Drupal\Tests\comment\Kernel\CommentIntegrationTest. Also, as I mention in #29, I think it's better to convert it into anonDependencyUpdating()
, when (and if) #2647576: onDependencyUpdating() - React on dependency updating lands. BTW, that needs a good review too but I feel that it's must in order to drop a lot of procedural code.#30.4, 5: Done.
#30.6: Nice! Done.
#30.7:
Yes, there's a difference between how calculateDependencies() works on config entities vs. plugins that are items in plugin collections attached to config entities. In this case this is a formatter plugin that is member of a collection part of the entity display (a formatter in entity display components plugin collection). There's no addDependency() method in plugins and the plugin calculateDependencies() (unlike the same method of config entities) should return the dependencies. Then the enclosing config entity will collect those dependencies from all plugin collections and add them to its own dependency list.
#30.8: Yes, but the enclosing statement entity_get_display(...)->setComponent($field_name, array(...)) still uses the old syntax and our code standards documents states (https://www.drupal.org/coding-standards#array) about the short syntax:
So I didn't wanted to increase the footstep of the patch by converting the whole method.
#30.9: Thank you!
Comment #33
claudiu.cristeaOuch!
Comment #34
larowlanAssuming bot agrees
Thanks - great work
Comment #35
alexpottSo this gets displayed to the user. It must be a single line and should start with "Add" to "Adds" (ie. imperative not indicative).
Should be a single line.
Need a comma after
'default'
$logged is not used - I guess we just need an assert.
Can we use the full update db so we can test updating multiple config entities... forum should be enabled there.
Comment #36
claudiu.cristea@alexpott, Implemented all from #35. @larowlan you can RTBC if you feel that it's OK.
Comment #37
larowlanGreat review @alexpott, thanks again @claudiu.cristea
Comment #38
catchIf we do this, can we later do #1938096: Convert the node comments list to a view, or does this mean we're not planning on doing that?
Comment #39
andypostI think comments render is complex enough to live in formatter, so there's no need to do that with views.
I closed #1938096: Convert the node comments list to a view
Comment #40
catchShould be 8.1.x
Not sure it matters but while 8000 was reserved for detecting 7.x databases, we don't need to do that with 8100.
Why disable and not switch back to default?
Or should we validate disabling the view displays instead when they're in use? This is the only bit of the patch that didn't sit right with me, might just need some more comments on why we're doing it this way, but feels a bit fragile. I realise #2647576: onDependencyUpdating() - React on dependency updating would make this visually a bit nicer.
Are we using view mode or display in UI text?
Comment #42
claudiu.cristeaRerolled for 8.2.x
@catch,
#4.1: Fixed.
#40.2: OK. Starting from 8200.
#40.3: This was a long discussion on removing image styles. Should the image formatter use the original image or the entire field should be disabled. This is somehow the same. My point: we cannot assume that the site builder wants to use that view display. When he's doing such operations (deleting/disabling a display) he must assume what he's doing. We cannot substitute him. The only thing we can make is to disable and notify him. So, I'm for disabling.
#40.4: 'Mode", no? I cannot decide that but mode sounds OK for me.
Comment #43
claudiu.cristeaComment #44
jonathanshawRegarding #40.4, entity reference uses "view mode" in the settings ui of its rendered entity formatter.
Comment #45
larowlanthanks @claudiu.cristea
Comment #46
alexpottRead through the entire patch again and tested it out - this looks like a really nice feature addition for 8.2.x that makes the system work the way you think it should.
Given this is a change in behaviour we need a change record - once we have that we're good for a commit. There are both developer changes and site builder changes. Also this is not an API change because a sensible default is used which results in the existing behaviour.
Comment #47
claudiu.cristea@alexpott, Added the draft CR at https://www.drupal.org/node/2769201. Back to RTBC as per #45.
Comment #48
alexpottCommitted 7f8e1c9 and pushed to 8.2.x. Thanks!
Comment #49
claudiu.cristea@alexpott, Seems it wasn't committed. At least I cannot see it in Git log
Comment #51
andypostGreat and useful improvement, thanx!