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.
I have tested the functionality of table grouping and found this bug (or missing feature ?)
Create a view
Format: table
Add some fields
Check "Exclude from Display" for one field (i.e. Field1)
View Format / Table Settings: Group by => Field1
In D7/Views 7.3.x the hidden field is used as table caption (unfortunately with no css class)
In D8/Views there is no table caption !!
Beta phase evaluation
Issue category | Bug because the missing caption is a regression |
---|---|
Prioritized changes | The main goal of this issue is fixing a normal bug. |
Disruption | None |
Comment | File | Size | Author |
---|---|---|---|
#62 | After patch.png | 31.61 KB | greggmarshall |
#62 | Before patch.png | 20.83 KB | greggmarshall |
#60 | missing_caption_if-2302319-60.patch | 3.64 KB | Lendude |
#57 | missing_caption_if-2302319-57.patch | 3.64 KB | Lendude |
| |||
#57 | interdiff-2302319-54-57.txt | 756 bytes | Lendude |
Comments
Comment #1
Micha1111 CreditAttribution: Micha1111 commentedSame problem with D8-beta
Comment #2
Anonymous (not verified) CreditAttribution: Anonymous commentedI can reproduce this on 8.0.x and I also verified on a D7 install that this is a regression.
Comment #3
dawehner.
Comment #4
geertvd CreditAttribution: geertvd commentedSomething like this adds the caption.
Comment #5
geertvd CreditAttribution: geertvd commentedStill needs test coverage though.
Comment #6
Anonymous (not verified) CreditAttribution: Anonymous commentedRe #4: I tried the grouping in D7 with the created field iso the title field, which resulted in:
It seems to me your patch doesn't handle that use case?
Comment #7
Anonymous (not verified) CreditAttribution: Anonymous commentedCorrection to #6 after manually retesting this issue. The use case is handled by the patch:
Comment #8
geertvd CreditAttribution: geertvd commentedAdded test.
Comment #10
LendudeFix and test looks go to me. Bit of nitpicking:
'will be used as a' (missing as)
tht => that
Also needs a beta evaluation added.
Comment #11
geertvd CreditAttribution: geertvd commentedFixed nitpicks
Comment #13
Anonymous (not verified) CreditAttribution: Anonymous at XIO commentedAdded a beta eval.
Tested manually and looks good to me.
Comment #14
Micha1111 CreditAttribution: Micha1111 commentedNew test with D8-beta10 after clean installation:
My view has two grouped fields, both are entity_reference fields. They are excluded from display.
First grouped field "Veranstaltung" is now used for table caption, but not right displayed as link to its content.
Second grouped field "Turnier" is not used for table caption (second level)
Have a look at attached screenshot.
Comment #15
alexpottHow does the views ui let you know that you're still going to get a caption?
Assigning to @dawehner to get an opinion.
Comment #16
dawehnerFirst I tried to understand how this actually works in Drupal 7:
This is the table template code we talk about.
So even if $caption is empty, it $title is set, we use it. This is set, when we group by a specific field, see http://cgit.drupalcode.org/views/tree/plugins/views_plugin_style.inc#n344
Alright, let's have a look at the situation in Drupal 8.
The grouping code itself looks still pretty much the same, see http://cgit.drupalcode.org/drupal/tree/core/modules/views/src/Plugin/vie...
I'm curious as it seems to be that the fix is not the right thing to do. The template still prints out the
{{ title }}
in case{{ caption_needed }}
,but we simply set it up wrong. This is some code from HEAD:
so all we need is
$variables['caption_needed'] = !empty($variables['summary']) || !empty($variables['description']) || !empty($variables['title']);
.So let's clarify things a bit. The option in the UI is for manual hand-crafted captions, which might be useful for additional accessibility on the site. In case you
group the view, the title is coming directly from the grouping. As additional accessibility features we support to add a summary and a description, but we don't take
into account
{{ caption }}
or{{ title }}
so I guess #843708: Add option to set caption & remove summary in the html table (Accessibility) was simply not entirely correct.Do we really need the escaping here? Don't we autoescape now? In case we have to, why can't we do that in the template itself? Is there something like
Xss::filterAdmin()
in twig?So yeah as written above I think we better encapsulate this into the line coming below.
Comment #17
geertvd CreditAttribution: geertvd commentedComment #18
geertvd CreditAttribution: geertvd at XIO commentedWe could also use the
raw
filter in the template, not sure what's best.Comment #24
geertvd CreditAttribution: geertvd at XIO commentedNo clue why the testbot keeps failing on this one. Seems unrelated to the patch.
Comment #26
pjbaertIt seems like all feedback from #16 is processed.
It looks like this is RTBC.
Comment #27
alexpottWe shouldn't be using SafeMarkup::set(). Why are we?
Comment #28
Anonymous (not verified) CreditAttribution: Anonymous at XIO commentedIf you choose to group by title, then the title is by default a link which is html. Without marking it safe, it is not rendered properly. Judging from the CR on SafeMarkup::set() here, I'd say we can use SafeMarkup::format() instead. I tested this manually, and it works. We will need to update the test coverage to cover such a use case.
Comment #29
geertvd CreditAttribution: geertvd at XIO commentedChanged SafeMarkup::set() to SafeMarkup::format() and added some extra test coverage.
Comment #31
Anonymous (not verified) CreditAttribution: Anonymous at XIO commentedI tested this manually and it looks good overall. One remark though:
This filters away the script tags. I think we should explicitly check for them.
Comment #32
geertvd CreditAttribution: geertvd at XIO commentedYup, missed that.
I changed
Xss::filterAdmin()
forSafeMarkup::escape()
I also changed the xpath select for a
assertRaw
because I had trouble finding the escaped markup with the xpath selector.Comment #34
Anonymous (not verified) CreditAttribution: Anonymous at XIO commentedLooks good to me. I think it's ready now.
Comment #35
alexpottThis is wrong what is this trying to do?
$this->assertEscaped() instead I think.
Comment #36
geertvd CreditAttribution: geertvd at XIO commented$this->assertEscaped()
fixes that nicely indeedComment #38
geertvd CreditAttribution: geertvd at XIO commentedbump
Comment #39
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedOverall looks good, but there's this in the test.
The test goes on to modify display and use the passage by reference to modify the view object without using the normal setters. This is unusual, and I'd discourage such in production code but sometimes tests have to do things in an unorthodox manner. Some commentary as to why a pass by reference here is being used instead of using the setters would be good I think.
Note: If $display is an ArrayObject then the pass by reference is redundant - objects are always passed by reference in PHP.
Comment #40
geertvd CreditAttribution: geertvd at XIO commentedHad to reroll this.
This was also not working anymore due to the recent SafeMarkup changes I guess. I changed it to use
ViewsRenderPipelineSafeString
.getDisplay()
doesn't return an object there, it returns an array reference to the display configuration (so I need the&
).Including
/** @var \Drupal\views\ViewEntityInterface $view */
already explains this better I think but I also added an extra comment to be clear on this matter.Comment #42
koence CreditAttribution: koence at XIO commentedDid some manual and automated tests.
Looks good to me.
Comment #43
alexpottThis does look right - how is $variables['title'] being set? This looks like it is user input and therefore this would be very unsafe.
Comment #44
geertvd CreditAttribution: geertvd at XIO commentedAfter looking into this again I noticed
$variables['title']
actually turned out to be aSafeString
object soViewsRenderPipelineSafeString::create()
was not necessary there anymore.While I was testing this I did bump into another issue in
StylePluginBase::renderGrouping()
which was using that same SafeString object as an array key which caused a fatal error.I'm not completely sure why this wasn't picked up by our tests though.
For now, this patch fixes that but maybe we need to expand our test coverage there.
Comment #46
geertvd CreditAttribution: geertvd at XIO commentedThe fatal error was not appearing because the grouping field in our has a label.
StylePluginBase::renderGrouping()
is doing this:So the string cast is happening there.
The reason that the test is failing is because the grouping string is not marked as safe in combination with the label.
Comment #47
geertvd CreditAttribution: geertvd at XIO commentedSetting this to Major since this is a Fatal Error that I can reproduce on HEAD
Comment #48
geertvd CreditAttribution: geertvd at XIO commentedThis should demonstrate the problem.
The complete patch should fail on the unsafe markup with a label.
Comment #51
geertvd CreditAttribution: geertvd at XIO commentedComment #52
geertvd CreditAttribution: geertvd at XIO commentedError from #46 is actually fixed in #2546924: Views fatal error when grouping on a field without a label set
Comment #53
geertvd CreditAttribution: geertvd at XIO commentedLooked into this issue a bit more.
The reason the group label is being double escaped is because of the string casting happening in
StylePluginBase::renderGrouping()
:I would have thought the label would have been added in
theme_views_view_field()
but it's actually being added intheme_views_view_fields()
.So either we need to move the caption label logic to a preprocess function or template, which I don't want to do since then we're just copying logic from
theme_views_view_fields()
or just mark the string safe somehow.Comment #54
LendudeManually tested this, and this is still an issue.
Since the fix for the fatal error was fixed in #2546924: Views fatal error when grouping on a field without a label set, we can take that bit out.
Also a lot of other safe markup stuff and theming has changed since this was last rolled. Setting the caption to markup with the escaped title in it does the trick to pass the tests.
Comment #55
LendudeSince the fatal error has been fixed elsewhere, I think we can move this back to normal.
Comment #56
dawehnerlet's use the entity type manager directly
Comment #57
Lendude@dawehner Like this?
Comment #58
dawehnerYeah, thanks for that!
Comment #60
Lendudereroll, didn't apply anymore.
Comment #61
LendudeComment #62
greggmarshallConfirmed the re-rolled patch applied correctly against 8.0.x-DEV and correctly displays the caption after being applied.
Before and after screen shots attached.
Comment #65
catchCommitted/pushed to 8.1.x and cherry-picked to 8.0.x. Thanks!