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.
Updated: Comment #69
Problem/Motivation
We nearly allow to configure each part of the HTML element types outputted by views, though it's not possible to configure
the HTML element for grouped views, which is H3 by default and hard-coded into the template.
Proposed resolution
Allow to configure the h3 element for view style plugins.
Remaining tasks
Patch needs review.
User interface changes
H3 element for the view style elements can be configured.
API changes
None.
Original report by dawehner
Comment | File | Size | Author |
---|---|---|---|
#86 | interdiff-1880100-85-86.txt | 1.14 KB | dman |
#86 | 1880100-86.patch | 14.8 KB | dman |
#85 | 1880100-85.patch | 13.64 KB | dman |
#81 | 1880100-81.patch | 14.08 KB | lokapujya |
Comments
Comment #1
dawehnerFirst version without some tests.
Comment #3
dawehnerRemoved the unrelated part of the patch (it was another cache related issue).
Comment #4
tim.plunkettMight as well make it public
Hmm, this means no overridden version of this will be used
Also, if you're changing every instance of the method at once, maybe it'd be good to just rename to getElements() now
Comment #5
dawehnerIn theory we could also move this method to another place like the style plugin?
Comment #6
dawehnerThank you for your feedback.
It seems to be okay to just be override-able by individual fields, because at least on the style plugin level, I don't see a reason why they want to have more then the normal ones.
Comment #8
dawehner#6: drupal-1880100-6.patch queued for re-testing.
Comment #9
dawehner#6: drupal-1880100-6.patch queued for re-testing.
Comment #10
damiankloip CreditAttribution: damiankloip commentedI think when this has test coverage this is good to go.
Do we have a follow up issue to add more (html5) tags? This could be a good novice issue, as it's just added some more tags the to array in the config file.
Comment #11
damiankloip CreditAttribution: damiankloip commentedWorking on fixes and tests for this.
Comment #12
dawehnerPlease wait if you haven't started yet, because I just saw that there is a local branch here called 1880100-tests.
Comment #13
damiankloip CreditAttribution: damiankloip commentedoops, I think we need to actually print the new variable in the templates? :)
Added some tests too.
This is what I have, so if you have tests too, we can compare.
Comment #14
dawehnerI'm not sure about this one, as caption is somehow special for a11
Comment #15
damiankloip CreditAttribution: damiankloip commentedAhh, ok. So what shall we do? Not allow this feature on tables?
Comment #16
dawehnerAdding a tag, maybe someone will see it.
Comment #17
mgiffordI need to know where to find it first. It does sound like a good idea in theory, but not sure where to find the configs. Should I be able to find them here - admin/structure/views/view/frontpage/edit?
Comment #18
damiankloip CreditAttribution: damiankloip commentedSo this will be on the style settings e.g. table when you add a grouping field to group the results by. You will then see another select field that lets you choose your tag. Hopefully this helps :)
Comment #19
mgiffordOk, so there has to be a better way to describe this, but maybe...
I think it might be useful to indicate here that if you're allowing folks to choose different headings and no headings at all -
Choose the HTML element to wrap around the grouping title of a view.
- it might be useful to encourage folks to learn how to use headings properly.I did a quick test in VoiceOver with Safari and it seems to work correctly.
It would be better if you also added the HTML5 hidden attribute as per:
http://www.paciellogroup.com/blog/2012/05/html5-accessibility-chops-hidd...
So rather than simply providing the style information via CSS:
<div class="form-item form-type-checkbox form-item-style-options-grouping-0-rendered" style="display: none;">
It would look a bit more like:
<div class="form-item form-type-checkbox form-item-style-options-grouping-0-rendered" style="display: none;" hidden>
That needs to switch along with the style information so that the semantic information is being passed along to AT.
Comment #20
dawehnerThanks for helping.
What you describe is the behavior in the admin UI using the states API, so it might make sense to open an issue for that.
What actually wanted to know the following code
As you can see, this removes caption and replaces it with a configurable event. Do you think this is correct at the end?
Is the caption tag, the only proper way to label a table?
Comment #21
mgiffordI'm not a Views guy. It's great, but my team works with it much more than I do. I was just trying to get where you were describing.
I can open a new issue and link back here for reference.
I could do that. Captions are optional. But why would you? Captions have meaning while headings have a different meaning. Surely the goal should be to properly style captions in CSS?
A caption is the only way to establish semantic relationships between a heading and a table. I think I'd like to see a good argument to allow folks to change it over. On the other hand, if the defaults are set properly it's probably not going to be a common occurrence.
Comment #22
dawehnerYeah you simply want to be able to configure that html element.
Comment #24
dawehner#22: drupal-1880100-22.patch queued for re-testing.
Comment #25
dawehner#22: drupal-1880100-22.patch queued for re-testing.
Comment #26
mgifford#22: drupal-1880100-22.patch queued for re-testing.
Comment #28
dawehnerJust a rerole.
Comment #30
dawehner$view->preview() now returns a render array.
Comment #31
tim.plunkettThis exposes a new option in the UI to change the H3 to another tag, but the default is unchanged, so I don't think this needs any accessibility review.
It now also has tests.
The code looks great, and works, so RTBC!
Comment #32
dawehner#30: drupal-1880100-30.patch queued for re-testing.
Comment #33
damiankloip CreditAttribution: damiankloip commented#30: drupal-1880100-30.patch queued for re-testing.
Should be fine but just checking.
Comment #34
tim.plunkett#30: drupal-1880100-30.patch queued for re-testing.
Comment #36
dawehnerComment #37
pwieck CreditAttribution: pwieck commentedWorking on reroll
Comment #38
pwieck CreditAttribution: pwieck commentedRerolled to current head
Removed from patch
public function getElements() (HEAD) changed to public static function getHTMLElementTypes() (PATCH)
Comment #39
dawehnerWe have to adapt all the twig files.
Comment #40
pwieck CreditAttribution: pwieck commentedAdding twig file changes to patch as per @dawehner and @Cottser
Comment #41
pwieck CreditAttribution: pwieck commentedAdded to patch per @dawehner and @Cottser on IRC:
<{{ title_element_type }}>{{ title }}</{{ title_element_type }}>
Added on my own:
To:
core/modules/views/templates/views-view-unformatted.html.twig
core/modules/views/templates/views-view-table.html.twig
core/modules/views/templates/views-view-list.html.twig
core/modules/views/templates/views-view-grid.html.twig
Comment #42
pwieck CreditAttribution: pwieck commentedchanged status
Comment #43
dawehnerGreat!
Comment #45
pwieck CreditAttribution: pwieck commentedFailing in StyleTest.php
Comment #46
dawehnerbut you just changed three twig files.
Comment #47
pwieck CreditAttribution: pwieck commentedDid manual testing and found tables not working as expected. All other styles working as expected.
The four failures in patch #41 are due to an incorrectly written test. The test in all of these patches only tests against the table style using $style['type'] = 'table'; in the foreach loop
I did a quick and dirty change to $style['type'] = $plugin; and only table fails. The test would also have to handle rows for grid and html_list styles. Test passes these with exceptions.
#46 miscounted - I did all 4 styles.
Comment #48
dawehnerI could fix some of the problems, though there is some odd error message coming from tiwg:
Comment #50
pwieck CreditAttribution: pwieck commentedDuring my manual testing of the styles one by one, I did not get these exceptions with the 'default' style. It started with 'grid'. Of coarse 'table' failed and I did not run 'html_list' through test. I was thinking it was a miss-written test.
I will run all four one by one later today.
Comment #51
dawehnerAdding back Twig.
Comment #52
dawehnerComment #53
damiankloip CreditAttribution: damiankloip commentedShould we use Html instead of HTML? I can't remember the 'proper' rules on camel casing.
Do you think we should move this static method somewhere else? not FieldPluginBase. Just a thought, otherwise this patch is looking good.
Comment #54
dawehnerThere we go.
Comment #56
dawehnerMissed one place.
Comment #58
dawehnerFixed the last bit.
Comment #59
damiankloip CreditAttribution: damiankloip commentedI think it living of StylePluginBase is better, using FieldPluginBase::stuff around town looks a bit weird. The rest of the changes look good.
Comment #60
tim.plunkett#58: vdc-1880100-58.patch queued for re-testing.
Comment #62
dawehnerComment #64
dawehnerThere we go.
Comment #65
dawehner64: vdc-1880100-64.patch queued for re-testing.
Comment #67
dawehnerJust a rerole.
Comment #68
olli CreditAttribution: olli commentedNice work! I think this is almost a bug =)
Why static? Could we call $this->view->style_plugin->getHtmlElementTypes()? Or make $this->getElements() a wrapper around it? Or...
Why not move this method to pluginbase? This docs needs tuning.
Comment #69
PavanL CreditAttribution: PavanL commentedComment #70
dawehnerThank you for the good review!
It used to be on the field, so the style plugin could not easily access it, but know I think it is fine to just have it as method on the style plugin base. Both field and style can acess it there.
I have the feeling that moving it to the plugin base just makes this already gigant file even bigger.
Additional I took the change and started with a unit test.
Comment #72
dawehnerThe problem with this is now basically that creating an instance of a field requires the style plugin to be already instanciated. While this is not a real problem in reality is still couples the system more as well as makes it harder to test things.
Yes caling $this->initStyle in initHandlers() is actually quite easy, though we have to do the same on the display side. Also quite a lot of the tests actually are in a reduced enviroment in which we don't have actual row/style plugins available. Don't we also create some kind of recursion here?
Field -> Style -> Row (for example fields row style) -> Fields
Comment #73
olli CreditAttribution: olli commentedThe method is only called by buildOptionsForm() and we could get those tests green by calling $this->view->getStyle()->getHtmlElementTypes() but this also means that the style plugin defines what which html elements the field plugin may use. I'm not sure we want that.
How about simply leaving FieldPluginBase::getElements() as is (yes, duplicate the code in style plugin base)? This way there is no coupling, only an api addition and it can still be overridden.
Comment #74
dawehnerI don't get why we also can't just use a static method.
Comment #75
olli CreditAttribution: olli commentedSo #67 with that comment fix?
Comment #76
olli CreditAttribution: olli commentedStylePluginBase::getHtmlElementTypes()
Comment #77
dawehnerWent back to the static method approach and fied the part of the previous review.
Comment #78
dawehner77: vdc-1880100.patch queued for re-testing.
Comment #79
olli CreditAttribution: olli commentedTested manually with a table. Options none and default does not seem to work: those are rendered as "<0>" and "<>" inside the
<caption>
element.Comment #80
mgiffordComment #81
lokapujyaJust the reroll here.
Comment #82
lokapujyaSee #79
Comment #85
dman CreditAttribution: dman as a volunteer and at Sparks Interactive commentedI found this was needed on a project today, so am trying to pick this up and give it a shake.
First patch is an attempt at a reroll of #81 from May, all the way up through some significant versions.
Many of the files have been moved around to different places, but that was the least of it.
Issues still exist, but this is a faithful re-roll of #81 - with many lines re-applied manually due to nearby changes.
With the following two significant changes just to make it work:
I have not replaced the usages of it in the forms #options lines yet - as this is currently a no-fix reroll for changes. But I think that those lines should also go back to how they were - as it seems that getElements() is the way things have gone.
This test is found in core/modules/views/tests/src/Kernel/Plugin/DisplayKernelTest.php
After inserting the schema, that test cleared.
I tried making an interdiff (failed), it was messier than the patch itself due (in large part at least) to all the file renaming.
Experimental manual testing has been promising but glitchy, and I'll review the actual issues next. I'm just pushing this up as a place to roll the next issues from.
This is 'needs work' still, but I'd like to bump it up to see if the testbot can assimilate it OK. (I've been getting an unrelated false positive in local tests today - so I'm half expecting to see a fail from Drupal\Tests\views\Kernel\Handler\FieldDateTest::testFieldDate - but let's see.)
Comment #86
dman CreditAttribution: dman as a volunteer and at Sparks Interactive commentedUpdated the test (that applies solely to this patch) to use current test methods, removed deprecated calls that meant that test could not even run.
Tests now run, but fail, as the patch functionality isn't working. Starting with failing tests is at least a solid start :-}
The test in question:
php ./core/scripts/run-tests.sh --verbose --class "Drupal\views\Tests\Plugin\StyleTest::testCustomElementTitle"
Comment #96
theMusician CreditAttribution: theMusician at Western Washington University commentedThis issue appears to be a duplicate of https://www.drupal.org/project/drupal/issues/1383696, or the other way around. https://www.drupal.org/project/drupal/issues/1383696 has updated code that appears to work with 9.5.x.