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
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mikeker created an issue. See original summary.

mikeker’s picture

Status: Active » Needs review
Issue tags: +Needs tests
FileSize
554 bytes

I'll work on tests in the morning...

joelpittet’s picture

I'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

joelpittet’s picture

Forgot about this, tests were kinda tricky to right but this should do the trick.

The last submitted patch, 4: stable_theme_does_not-2779919-4--tests-only.patch, failed testing.

lauriii’s picture

Status: Needs review » Needs work

In 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.

+++ b/core/modules/field/src/Tests/FieldDisplayTest.php
@@ -0,0 +1,121 @@
+    $renderer = \Drupal::service('renderer');
+    $content = $renderer->renderPlain($build);
+    $this->setRawContent((string) $content);

No need to do this manually since we could use $this->render()

joelpittet’s picture

Status: Needs work » Needs review

@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.

lauriii’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
FileSize
20.34 KB

Tested this manually using Stark. The visualy-hidden class is now applied to the visually-hidden field labels:

lauriii’s picture

Status: Reviewed & tested by the community » Needs work
--- /dev/null
+++ b/core/modules/field/src/Tests/FieldDisplayTest.php

@@ -0,0 +1,121 @@
+namespace Drupal\field\Tests;

I think the test should live in the Drupal\tests namespace and inside the tests/src/Kernel folder

joelpittet’s picture

Status: Needs work » Needs review
FileSize
1.68 KB
4.04 KB

Thanks @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.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

UpTil4Music’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Nashville2018
FileSize
407.04 KB
348.53 KB

Before
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

lauriii’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/field/tests/src/Kernel/FieldDisplayTest.php
    @@ -0,0 +1,118 @@
    +    $this->display = entity_get_display($this->entityType, $this->bundle, 'default');
    

    entity_get_display() is deprecated. We should seek for an alternative approach that is not deprecated.

  2. +++ b/core/modules/system/templates/field.html.twig
    @@ -53,7 +53,7 @@
    +    <div{{ title_attributes.addClass(label_display == 'visually_hidden' ? 'visually-hidden' : '') }}>{{ label }}</div>
    
    +++ b/core/themes/stable/templates/field/field.html.twig
    @@ -51,7 +51,7 @@
    +    <div{{ title_attributes.addClass(label_display == 'visually_hidden' ? 'visually-hidden' : '') }}>{{ label }}</div>
    

    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.

andrewmacpherson’s picture

Status: Needs work » Needs review
FileSize
2.02 KB
4.44 KB

addressing #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.

Status: Needs review » Needs work

The last submitted patch, 16: stable_theme_does_not-2779919-16.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

andrewmacpherson’s picture

Status: Needs work » Needs review
FileSize
695 bytes
4.55 KB

Fixing test failure in #16. It needed the second of the suggested approaches for replacing entity_get_display().

jds1’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
106.69 KB
102.9 KB

Patch 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!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 18: stable_theme_does_not-2779919-18.patch, failed testing. View results

andrewmacpherson’s picture

Status: Needs work » Needs review
FileSize
816 bytes
4.5 KB
John Cook’s picture

Status: Needs review » Reviewed & tested by the community

The 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.

andrewmacpherson’s picture

Issue tags: +Nwdug_may18
lauriii’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/field/tests/src/Kernel/FieldDisplayTest.php
@@ -0,0 +1,126 @@
+    $this->display = \Drupal::entityManager()

The \Drupal::entityManager() is deprecated as well. We should use \Drupal::entityTypeManager() instead.

andrewmacpherson’s picture

Status: Needs work » Needs review
FileSize
501 bytes
4.51 KB

Fixes #24

Kolin’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +DCScot18

Patch #25 works on 8.6.x-dev.
All tests passed.
Also manually tested.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 25: stable_theme_does_not-2779919-25.patch, failed testing. View results

idebr’s picture

Status: Needs work » Reviewed & tested by the community

  • lauriii committed bc1b1fa on 8.6.x
    Issue #2779919 by andrewmacpherson, joelpittet, mikeker, UpTil4Music, if...
lauriii’s picture

Status: Reviewed & tested by the community » Fixed

Committed bc1b1fa and pushed to 8.6.x. Thanks! 🎉

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.