Problem/Motivation

Sections are currently given numbers by their order. Section 1, Section 2, etc.
As a more complex layout can be built by combining many simple layouts, it would be nice to be able to give meaningful names to these sections.

These would only be shown when editing the layout, never on the front end.

Proposed resolution

Add ability to give sections names.
For now, this will only be used when the numeric version of the section is display: the remove section and configure section forms, and the visually-hidden parts of the UI used by screen readers.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#29 3073872-label-29-interdiff.txt2.35 KBtim.plunkett
#29 3073872-label-29.patch36.69 KBtim.plunkett
#29 Edit layout for Article content items Drupal 2019-08-22.png57.21 KBtim.plunkett
#26 lb-configure-block.png46.73 KBwebchick
#26 lb-unpatched.png41.41 KBwebchick
#26 lb-patched.png31.43 KBwebchick
#24 wat.png72.86 KBwebchick
#24 eyeballs.png141.6 KBwebchick
#22 3073872-section-label-appears-on-delete.png561.71 KBphenaproxima
#22 3073872-label-new-section.png606.39 KBphenaproxima
#22 3073872-add-admin-label.png1.03 MBphenaproxima
#21 3073872-label-21-interdiff.txt554 bytestim.plunkett
#21 3073872-label-21.patch36.76 KBtim.plunkett
#20 3073872-label-20-interdiff.txt1.43 KBtim.plunkett
#20 3073872-label-20.patch36.22 KBtim.plunkett
#18 3073872-label-18-interdiff.txt6 KBtim.plunkett
#18 3073872-label-18.patch36.07 KBtim.plunkett
#16 3073872-label-15-interdiff.txt6.17 KBtim.plunkett
#16 3073872-label-15.patch31.76 KBtim.plunkett
#14 Edit layout for Article content items Drupal 2019-08-14.png80.48 KBtim.plunkett
#14 3073872-label-14-interdiff.txt14.45 KBtim.plunkett
#14 3073872-label-14.patch46.56 KBtim.plunkett
#11 interdiff-3073872-9-11.txt6.48 KBstarshaped
#11 3073872-11.patch36.66 KBstarshaped
#10 3073872-10-section-label.png143.95 KBstarshaped
#10 interdiff-3073872-9-10.txt6.01 KBstarshaped
#10 3073872-10.patch37.36 KBstarshaped
#9 3073872-label-9-interdiff.txt709 bytestim.plunkett
#9 3073872-label-9.patch35.56 KBtim.plunkett
#7 3073872-label-7-interdiff.txt9.3 KBtim.plunkett
#7 3073872-label-7.patch34.87 KBtim.plunkett
#5 3073872-label-5-interdiff.txt6.37 KBtim.plunkett
#5 3073872-label-5.patch25.57 KBtim.plunkett
#4 3073872-label-4-interdiff.txt9.99 KBtim.plunkett
#4 3073872-label-4.patch19.43 KBtim.plunkett
#2 3073872-label-2-w.txt8.91 KBtim.plunkett
#2 3073872-label-2.patch10.34 KBtim.plunkett
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tim.plunkett created an issue. See original summary.

tim.plunkett’s picture

Status: Active » Needs review
FileSize
10.34 KB
8.91 KB

Note that there is a good deal of indenting in the patch, so I've attached a version using -w

Status: Needs review » Needs work

The last submitted patch, 2: 3073872-label-2.patch, failed testing. View results

tim.plunkett’s picture

Status: Needs work » Needs review
FileSize
19.43 KB
9.99 KB

Fixing existing tests. Still needs dedicated tests

tim.plunkett’s picture

Added tests, and fixed it so it doesn't say "section Section 1".

Status: Needs review » Needs work

The last submitted patch, 5: 3073872-label-5.patch, failed testing. View results

tim.plunkett’s picture

Status: Needs work » Needs review
FileSize
34.87 KB
9.3 KB

Fixed the way settings are stored and retrieved.

Status: Needs review » Needs work

The last submitted patch, 7: 3073872-label-7.patch, failed testing. View results

tim.plunkett’s picture

Status: Needs work » Needs review
FileSize
35.56 KB
709 bytes

Okay should pass now.

starshaped’s picture

First pass at adding CSS to style the label.

starshaped’s picture

Removed an unrelated edit and rolled the patch again.

starshaped’s picture

Disregard #11 -- the file I removed actually is relevant! The patch in #10 is the correct one.

Status: Needs review » Needs work

The last submitted patch, 11: 3073872-11.patch, failed testing. View results

tim.plunkett’s picture

Here's an update to include the blocks part too. This will fail tests for sure. Interdiff against #10.

Status: Needs review » Needs work

The last submitted patch, 14: 3073872-label-14.patch, failed testing. View results

tim.plunkett’s picture

Status: Needs work » Needs review
FileSize
31.76 KB
6.17 KB

Okay so the scope of this issue was just about allowing administrative labels to be customized. And they are used for the aria-labels and visually-hidden text, as well as the form titles for removing and configuring a section.

Removing all of the additional UI improvements, which should be done elsewhere (likely in contrib, first).

Interdiff against #9.

Status: Needs review » Needs work

The last submitted patch, 16: 3073872-label-15.patch, failed testing. View results

tim.plunkett’s picture

Status: Needs work » Needs review
FileSize
36.07 KB
6 KB

Fixed some tests

phenaproxima’s picture

  1. +++ b/core/config/schema/core.data_types.schema.yml
    @@ -358,6 +358,10 @@ display_variant.plugin:
    +  mapping:
    +    label:
    +      type: label
    +      label: 'Label'
    

    I was thinking this might get easily confused with the label of the layout plugin itself, but on second thought, this is very clearly part of the plugin settings, so it makes sense where and how it is. 👍

  2. +++ b/core/modules/layout_builder/src/Field/LayoutSectionItemList.php
    @@ -22,12 +22,18 @@ class LayoutSectionItemList extends FieldItemList implements SectionListInterfac
    +  /**
    +   * Numerically indexed array of field items.
    +   *
    +   * @var \Drupal\layout_builder\Plugin\Field\FieldType\LayoutSectionItem[]
    +   */
    +  protected $list = [];
    +
    

    I was going to ask why this was needed, since we get it from FieldItemList, but I see it's because of the type hint. So, 👍

  3. +++ b/core/modules/layout_builder/src/Field/LayoutSectionItemList.php
    @@ -60,6 +66,17 @@ public function getEntity() {
    +    // Loop through each section and make sure it is up-to-date.
    +    foreach ($this->list as $delta => $item) {
    +      $item->section = Section::fromArray($item->section->toArray());
    +    }
    

    I think this comment needs to be expanded a bit. Why would the sections be out of date?

  4. +++ b/core/modules/layout_builder/src/Plugin/Layout/MultiWidthLayoutBase.php
    @@ -35,19 +36,14 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
    -    return $form;
    -  }
    -
    -  /**
    -   * {@inheritdoc}
    -   */
    -  public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
    

    Not exactly sure what's going on here, but I assume it's just diff weirdness. 🤷‍♂️

  5. +++ b/core/modules/layout_builder/src/Section.php
    @@ -98,7 +98,7 @@ public function toRenderArray(array $contexts = [], $in_preview = FALSE) {
    -    return $this->layoutPluginManager()->createInstance($this->getLayoutId(), $this->getLayoutSettings());
    +    return $this->layoutPluginManager()->createInstance($this->getLayoutId(), $this->layoutSettings);
    

    This could use a comment. Why can't we call $this->getLayoutSettings() anymore? Will it not return the same data it previously did? If not, isn't that a backwards compatibility issue?

  6. +++ b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php
    @@ -1219,10 +1257,10 @@ protected function assertCorrectLayouts() {
    -      'layout_builder/add/section/overrides/node.1/0/layout_onecol',
    +      'layout_builder/configure/section/overrides/node.1/0/layout_onecol',
           'layout_builder/configure/section/overrides/node.1/0/layout_twocol_section',
           'layout_builder/configure/section/overrides/node.1/0/layout_threecol_section',
    -      'layout_builder/add/section/overrides/node.1/0/layout_fourcol_section',
    +      'layout_builder/configure/section/overrides/node.1/0/layout_fourcol_section',
    

    Why did these change?

  7. +++ b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php
    @@ -1236,6 +1274,7 @@ protected function assertCorrectLayouts() {
    +      $assert_session->linkByHrefNotExists("layout_builder/configure/section/overrides/node.1/0/$unexpected_layout");
    

    And here? I must be missing something.

  8. +++ b/core/modules/layout_builder/tests/src/Kernel/OverridesSectionStorageTest.php
    @@ -120,7 +120,7 @@ public function testAccess($expected, $is_enabled, array $section_data, array $p
    +      new Section('layout_onecol', [], [
    

    How about this? It's not clear why this changed...

  9. +++ b/core/modules/layout_builder/tests/src/Kernel/SectionListTraitTest.php
    @@ -47,7 +48,9 @@ class TestSectionList implements SectionListInterface {
    +    foreach ($sections as $section) {
    +      $this->sections[] = Section::fromArray($section->toArray());
    +    }
    

    This could also use a comment, maybe.

tim.plunkett’s picture

3)
Rewrote the comment. The loop is needed to add in default values for the layout settings.

4)
MultiWidthLayoutBase was providing an empty validateConfigurationForm method, but now that is provided by its new parent class.

5)
From the diff it looks like it needs a comment, but if you read the code as-is, not as much. Also if someone tried to switch it, they will find out quickly why it needed direct access: getLayoutSettings() now calls to getLayout(), this method :)

6)
In HEAD the onecol and fourcol layouts had no settings, so they bypassed the configuration route. Now they have the label to configure, hence the change to the expected route.

7)
Same as above, we need to assert for the absence of the correct link. To be safe, I just asserted that neither /add/ nor /configure/ are used.

8)
There's no such plugin as layout_default, and now it is instantiated. Same for the other places this switches to layout_onecol.

9)
Copied the relevant comment from feedback point 3

tim.plunkett’s picture

Included post_update hook for the schema change

phenaproxima’s picture

I gave this a quick manual test. It worked beautifully; the sections can indeed be assigned administrative labels, which are exposed as the title of the off-canvas area when configuring or deleting the sections. Well done! Code is clean and well-tested (par for the course with a @tim.plunkett patch), and we are accounting for the update path. I don't think this needs anything else.

Screenshots attached from my testing (on a clean new install).

phenaproxima’s picture

Status: Needs review » Reviewed & tested by the community

Forgot to move to RTBC.

webchick’s picture

Status: Reviewed & tested by the community » Needs work
FileSize
141.6 KB
72.86 KB

Ok, running this through WebchickTestCase™!

First question: Can we smoosh the layout selection + the admin label into the same form so it's one step instead of two? We ideally want adding a section to be as quick and painless as possible; this new second step adds friction. (Oh, I see... this happens only for one-col; the other ones already have an extra configuration step. Well then.)

Second question: Why do I not see the section label I just created on the page anywhere? This left me fairly disoriented, especially with a one-column section where it's lots of equally-sized boxes stacked on top of each other. Would expect to see the "Configure" link say "Configure Top Header Thingy" or whatever. This would also help with targeting drag-and-drop.

Configure links with no description as to what they configure.

(Oh wait. After dragging a block in, the labels suddenly appeared? Some caching issue? It's visible in @phenaproxima's screenshot at https://www.drupal.org/files/issues/2019-08-16/3073872-label-new-section... nevertheless, so don't think it's just me.)

At least in Firefox, there is also some weird styling on optgroups on the move drop-down. Probably a pre-existing condition, tho:

White text on light grey background.

Elsewise the patch itself looks very straight-forward, has ample test coverage, and so on. A nice accessibility and usability improvement both, so \o/ Feels like we need to address that weird label disappearing issue, however.

webchick’s picture

Ok, spun off #3076153: Off-canvas dialog <optgroup> styling in Firefox is illegible for the third point.

On the second point, which is the only thing we need to fix here, I figured out through talking with @tim.plunkett that this is not a caching issue; rather, those labels are only visible when in keyboard navigation mode (which I also was testing).

We discussed and agreed that showing them is better though, because otherwise it gets confusing, esp. if you are creating multiple similar-looking sections at a time, as to which is which.

Since this is a new feature that not all sites will be using right away, what we discussed was conditional logic like (blatantly stolen from @tim.plunkett :D):

$text = "Configure";
if (there is an admin label) {
 $text .= " $label";
}
else {
  $text .= " <span class="visually-hidden">section $delta</span>"; 
}

This way the labels are exposed to screen readers/keyboard users no matter what, but folks who don't need/want to use section labels aren't inundated with a bunch of "Section 1, 2, 3 [...]" in the UI.

webchick’s picture

FileSize
31.43 KB
41.41 KB
46.73 KB

Moar feedback from the UX meeting today. :)

HEAD:

Link says 'Configure section'

This patch:

Link says 'Configure'

This won't fly, because without the extra input as to what you're configuring, it's not clear what that configure link actually refers to. Additionally, the "X" icon seems to be associated with Configure, vs. its own operation. :O

This is particularly apparent when a section has blocks in it:

Link positioned directly above block

Absent of the word "section," a sensible person would think that these were links to configure / delete the content within the section, since that's what's actually visible.

All of that makes sense, but then seems to make the proposed resolution not quite right... instead we probably ought to instead just always display the section name even if it's an auto-generated delta (which has the side benefit of making the UX consistent between screen reader users and visual users).

In other words:

$text = "Configure section $label";

...across the board.

(Obviously with translation and escaping and such :P)

tim.plunkett’s picture

First off, definitely agree with showing more text, not less. Will fix.

One clarifying question.
Let's say you have three sections.

You configure the label of the top section to be "Header section".
You do not configure the middle section label.
You configure the label of the bottom section to be "Footer".

By the current logic, it will say

"Configure Header section"
"Configure section 2"
"Configure Footer"

Note the mismatch between the first and third.

Or, we could have it say

"Configure section Header section"
"Configure section 2"
"Configure section Footer"

I'm partial to the first option, but just wanted to call it out.

webchick’s picture

Yeah, I think the first one is sufficient. As @yoroy always used to say, use fewer words. :) The previous concern was the standalone "Configure" getting confused with blocks, but I don't see that happening with the labels exposed.

tim.plunkett’s picture

phenaproxima’s picture

Status: Needs review » Reviewed & tested by the community

Seems legit.

webchick credited ckrina.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Great stuff! Thanks a lot for the extra tweaking!

Committed and pushed to 8.8.x, woohoo! Also crediting folks on the UX call, who contributed to the solution outlined here.

  • webchick committed 3003cc6 on 8.8.x
    Issue #3073872 by tim.plunkett, starshaped, webchick, phenaproxima,...
webchick’s picture

Issue tags: +8.8.0 highlights

Also, probably something to mention in the release highlights reel. This is a nice feature for accessibility and usability both.

Status: Fixed » Closed (fixed)

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

brooke_heaton’s picture

Now that we've added the ability to add Administrative labels - how do I get rid of them :/ I find them super belittling to the end user.