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.
Site builders can set field labels to be hidden (not output at all) or visually hidden (text is available to screen readers) via admin/structure/types/manage/<content_type>/display
. The Stable theme does not add the proper class to the field label to achieve the "visually hidden" effect.
Steps to repro:
- Standard install profile with some devel generated content
- Navigate to
admin/structure/types/manage/article/display
- For the "Image" field, change the "Label" setting to "Visually hidden"
- Create a dummy theme with the following in
dummy.info.yml
name: Dummy Testing Theme type: theme core: 8.x base theme: stable
- Enable and set as default the new Dummy theme
- Navigate to an article node
Comment | File | Size | Author |
---|---|---|---|
#25 | stable_theme_does_not-2779919-25.patch | 4.51 KB | andrewmacpherson |
#25 | interdiff-2779919-20-25.txt | 501 bytes | andrewmacpherson |
#21 | stable_theme_does_not-2779919-20.patch | 4.5 KB | andrewmacpherson |
#21 | interdiff-2779919-18-20.txt | 816 bytes | andrewmacpherson |
#19 | after-patch-18-applied.png | 102.9 KB | jds1 |
Comments
Comment #2
mikeker CreditAttribution: mikeker as a volunteer commentedI'll work on tests in the morning...
Comment #3
joelpittetI'm +1 for this, ping me if you'd like a hand with a test. This utility class is added all over the place throughout core and though I'd prefer if we had it configurable, especially in stable. It is what it is and should be working in all cases it's used by site builders. Themers can rewrite the CSS if new techniques arise, but the class name is pretty much stuck for 8.x
Comment #4
joelpittetForgot about this, tests were kinda tricky to right but this should do the trick.
Comment #6
lauriiiIn overall this looks good even though there's a markup change inside Stable theme. This is a missing functionality inside Stable theme and should be fixed there, even though there is a small risk that we might break some themes.
No need to do this manually since we could use $this->render()
Comment #7
joelpittet@lauriii actually
$this->render()
renders the whole page, and gives some false positives because the .visually-hidden class is added in the page template for the "skip content" link. Also, it's slower because this only renders the thing in question and not the rest of the page.Thanks for the review.
Comment #8
lauriiiTested this manually using Stark. The visualy-hidden class is now applied to the visually-hidden field labels:
Comment #9
lauriiiI think the test should live in the Drupal\tests namespace and inside the tests/src/Kernel folder
Comment #10
joelpittetThanks @lauriii again that makes sense, here's my attempt at that move and removed a couple of modules that weren't needed for the test and array syntax update to short.
Comment #14
UpTil4Music CreditAttribution: UpTil4Music as a volunteer commentedBefore
Performed all Steps to reproduce
Screenshot showing expected results - Title displays, visually-hidden class not applied
Patch #10 applied to 8.6.x-dev
After
Screenshot showing expected results - Title no longer display, visually-hidden class applied
Comment #15
lauriiientity_get_display() is deprecated. We should seek for an alternative approach that is not deprecated.
We should split this to multiple lines since this line is quite line after these changes. We can change to
{{- label -}}
which will remove any of the whitespaces from the end result.Comment #16
andrewmacpherson CreditAttribution: andrewmacpherson as a volunteer commentedaddressing #15
For #15.1 I just looked up the API docs, saw there were two examples for what to replace it with, and cribbed the first one.
For #15.2, splitting out
{{- label -}}
still left the opening DIV as the longest line in the file, at over 100 chars. So I copied the way Classy's field template sets the title classes.Comment #18
andrewmacpherson CreditAttribution: andrewmacpherson as a volunteer commentedFixing test failure in #16. It needed the second of the suggested approaches for replacing entity_get_display().
Comment #19
jds1Patch applies for me and works on latest pull of 8.6.x dev branch. Attaching two screenshots of before and after. Followed steps above and "Image" label disappears after patch is applied. Marking as Reviewed!
Comment #21
andrewmacpherson CreditAttribution: andrewmacpherson as a volunteer commentedThis fixes another deprecation, since #2849669: Fix \Drupal\Component\Utility\Unicode() because of the Symfony mbstring polyfill went in this week.
Comment #22
John Cook CreditAttribution: John Cook at Creode commentedThe patch from #21 addresses the test failure. It only replaces the deprecated method with the recommended function call.
As this has been manually tested by @if-jd, the latest patch only changes a test, and all the tests are now passing, I'm setting this back to RTBC.
Comment #23
andrewmacpherson CreditAttribution: andrewmacpherson as a volunteer commentedComment #24
lauriiiThe
\Drupal::entityManager()
is deprecated as well. We should use\Drupal::entityTypeManager()
instead.Comment #25
andrewmacpherson CreditAttribution: andrewmacpherson as a volunteer commentedFixes #24
Comment #26
Kolin CreditAttribution: Kolin as a volunteer and at Inviqa commentedPatch #25 works on 8.6.x-dev.
All tests passed.
Also manually tested.
Comment #28
idebr CreditAttribution: idebr at ezCompany commentedRestoring status to RTBC after #2973992: Permission issue in Nightwatch step marks all full testruns as unstable
Comment #30
lauriiiCommitted bc1b1fa and pushed to 8.6.x. Thanks! 🎉