Allow field blocks to display the configuration label when set in Layout Builder

Created on 11 March 2019, over 5 years ago
Updated 25 July 2023, 11 months ago

Problem/Motivation

When you edit a field block on Layout Builder, modify the Title, check Display title, and save the block the field block does not display the specified Title (configuration label) but instead displays the label / admin label.

This is due to the block.html.twig template currently using the label variable.

Proposed resolution

Although this could be handled via a template override or a field block specific template (e.g. block--field-block.html.twig), this could be more cleanly handled by using a hook_preprocess_block that would replace the label with the configuration label, when available.

Draft release note

Layout Builder field blocks will now display the user-specified label from the block configuration. Sites should review their existing blocks as this change may impact workflows that relied on the previous behavior.

🐛 Bug report
Status

Fixed

Version

10.1

Component
Layout builder 

Last updated about 20 hours ago

Created by

🇨🇦Canada nord102

Live updates comments and jobs are added and updated live.
  • Blocks-Layouts

    Blocks and Layouts Initiative. See the #2811175 Add layouts to Drupal issue.

  • Regression

    It restores functionality that was present in earlier versions.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • 🇺🇸United States aaronpinero

    #46 is working for me on Drupal 9.5.5

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    28,519 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    29,381 pass
  • Status changed to RTBC about 1 year ago
  • 🇺🇸United States PCate

    #46 patch applied cleanly and fixed issue. Patch tests are passing on both 10.0.x and 10.1.x. I don't see any comments with outstanding issues so setting to RTBC.

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    29,197 pass, 27 fail
  • 🇺🇸United States fskreuz

    Just adding some context since it's not the first time I've bumped into this issue and tried to recall how this worked:

    2158003 added the "the exact magical spot" referred to in #33 🐛 Allow field blocks to display the configuration label when set in Layout Builder Fixed . It's a way for the rendered block content to override the configured title (e.g. views blocks). It appears that the intent is to have the implementing block place #title to override the block title (or at least it's a change to accommodate how Views did block title overrides ). Patch fixes the issue by avoiding the field's #title property from being in the magical spot by placing it in an array, nesting it a level down.

    2942623 exists, but might be closed. Although it brings up an interesting point of why the title override comes after the block's configured label. You would expect that block configuration overrides whatever the block content supplier (be it Views or Field Block) supplies.

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    29,197 pass, 27 fail
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    29,197 pass, 27 fail
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    29,197 pass, 27 fail
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    29,197 pass, 27 fail
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    29,197 pass, 27 fail
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    29,197 pass, 27 fail
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    29,197 pass, 27 fail
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    29,197 pass, 27 fail
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    29,197 pass, 27 fail
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    29,197 pass, 27 fail
  • 🇫🇮Finland lauriii Finland

    This leads into behavior change on existing sites because they might be relying on this behavior. There could be also information in the administrative labels that is not intended to be printed on the public site. Tagging for release manager review to get their feedback on how they'd prefer to handle this.

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    29,197 pass, 27 fail
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    29,197 pass, 27 fail
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    29,197 pass, 27 fail
  • 🇬🇧United Kingdom catch

    @lauriii asked me about this one in slack.

    The issue summary could use an update, the original 'proposed solution' was a bit weird, the new proposed solution just changes how the $build array is structured and seems fine.

    On the behaviour change I think this is fine in a minor release with a release note. There seem to be two possibilities where it's a surprise:

    1. Someone tried to customize the title, it didn't work, they forgot about it and just dealt with it (or changed the actual field title), suddenly it starts working. This could happen but seems like we just fixed their bug. Worst case they have to update the layout configuration.

    2. Someone's relying on having this extra text field to store 'stuff' (metadata or similar) and suddenly their stuff that wasn't intended for public consumption is shown on the site. I think this is extremely unlikely because the UI for field blocks is exactly the same as all other kinds of blocks, and it's just this one that doesn't work.

    Remaining question is whether this goes into 10.2.x or 10.1.x, I don't have a strong opinion on that.

  • 🇬🇧United Kingdom catch

    Forgot to untag.

    • lauriii committed fbec11ff on 10.1.x
      Issue #3039185 by nord102, yogeshmpawar, swentel, tim.plunkett,...
  • Status changed to Fixed about 1 year ago
  • 🇫🇮Finland lauriii Finland

    Committed 7598b15 and pushed to 11.x. Thanks!

    I don't necessarily see a lot of difference between committing this to 10.2.x and 10.1.x so I went ahead and cherry-picked this to 10.1.x.

    • lauriii committed 7598b15a on 11.x
      Issue #3039185 by nord102, yogeshmpawar, swentel, tim.plunkett,...
  • Status changed to Active about 1 year ago
  • 🇺🇸United States neclimdul Houston, TX

    This broke my site. No content on pages using field blocks.

    A developer had written this:

    ```
    {% for item in content['#items'] | keys %}
    {{ content[item] }}
    {% endfor %}
    ```
    That little changed test at the end of the patch, it was detecting this was going to break. :(

    Its getting late on my Friday so I haven't dug in too deep into why the developer did this but wanted to raise this since the scope of the break might be bigger than captured.

  • 🇬🇧United Kingdom catch

    Let's add a change record for this. It's tagged for release notes - I didn't check the release notes draft but I also can't see a snippet in the issue summary.

    The render array change is allowed in a minor so it's a case where we'd expect custom code to adapt, but this went in to 10.1.x quite late so it's not leaving that much time. Did you already fix this for your site, and if so is it compatible with both the new and old way now? i.e. I wouldn't like to break this twice.

  • 🇫🇮Finland lauriii Finland

    I added a paragraph directly to the release notes about the behavior change but that doesn't mention the render array change. Should we mention the render array change in both, CR and release notes?

  • 🇬🇧United Kingdom catch

    I normally wouldn't bother (unless it was a very commonly altered form or similar) but I think since we have an example of someone relying on it, it would be a good idea in this case. Not sure how to word it except something like 'The render array structure for field blocks now has an extra level of nesting.' - although maybe that would be enough?

  • 🇺🇸United States neclimdul Houston, TX

    Did you already fix this for your site, and if so is it compatible with both the new and old way now? i.e. I wouldn't like to break this twice.

    Yes and yes but I can watch this space and deal with the fix either way.

    Should we mention the render array change in both, CR and release notes?

    I think so. I actually went to the change records but couldn't find any recent layout builder changes which made narrowing down the problem, fix, and this issue a lot harder.

    Not sure how to word it except something like 'The render array structure for field blocks now has an extra level of nesting.' - although maybe that would be enough?

    Yeah I think so.

    The fix for me was a bit complicated because this seems to have been done to avoid the field wrapping divs. The trivial fix was just to output the individual items using the children filter but that added add the field wrappers which broke layout. To fully work around it afterwards actually required quite a bit of complexity or contrib. I went with contrib and field_value being provided by twig_field_value.

    Before:

        {% for item in content['#items'] | keys %}
          {{ content[item] }}
        {% endfor %}
    

    After:

        {% for item in content|children %}
          {{ item|field_value }}
        {% endfor %}
    
  • 🇫🇮Finland lauriii Finland

    I created a CR but I'm not sure what would be the before and after with just core because we don't have |children filter in core. Also, shouldn't it take into account that there could be something to render on the first level of the render array?

  • 🇺🇸United States neclimdul Houston, TX

    Wow... that seems like an oversight on core's fault. That's super useful with render arrays.

    I'm not sure how you'd do it either without implement Element::children inside the twig template which seems... not great.

    That said, this can probably be closed since 10.1 is out and there's a changelog?

  • Status changed to Fixed 12 months ago
  • 🇺🇸United States smustgrave

    Brought this up with @lauriii in #needs-review-queue-initative and agreed it could be closed again. Well marked fixed to be auto closed later.

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

  • Status changed to Fixed 11 months ago
  • 🇳🇿New Zealand quietone New Zealand

    This has a change record, removing tag

Production build 0.69.0 2024