Enable Add Section for Existing (Overridden) Layouts

Created on 10 July 2023, over 1 year ago
Updated 22 July 2023, over 1 year ago

Problem/Motivation

Up until now, we've only had one layout allowed - a single column layout. On that layout, we've set the layout builder lock to not allow sections to be added above and below the main content section. Now, we've introduced a two column layout. We've added it into the system and it works great for admins and non-admins adding new pages. But for non-admins and existing pages, the "Add section" button does not show up. In investigating, it looks like the layout builder lock settings are still present in the database (serialized data). We can get around this, of course, by editing the node as an admin and adding the two column layout, but this is not ideal.

Steps to reproduce

1. Set up layout builder lock on a content type to not allow sections to be added above and below a specified section.
2. Override the layout on an actual node and add some layout builder blocks, etc.
3. Turn off layout builder lock on the content type - i.e. allow sections to be added below/above the specified section.
4. As a non-admin, edit the node that was created and notice that there is no "Add section" button present.

Proposed resolution

I don't know if this is a bug on the module or not - if it is intended to work this way, is there a way to bulk update nodes that have their layouts overridden to essentially replace the layout builder lock info with the one from the master display?

Remaining tasks

Unknown.

User interface changes

Unknown.

API changes

Unknown.

Data model changes

Unknown.

πŸ’¬ Support request
Status

Active

Version

1.2

Component

User interface

Created by

πŸ‡ΊπŸ‡ΈUnited States codechefmarc

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @codechefmarc
  • πŸ‡ΊπŸ‡¦Ukraine Panchuk Volyn, Lutsk

    Sounds like a bug..
    Thanks for the issue report, I'll take a look

  • πŸ‡ΊπŸ‡ΈUnited States codechefmarc

    An update for you and my solution. I don't think this is a bug - I think the module is working as intended, it was just a bit tricky to figure out how to update existing, overridden, layouts. We can close this if you wish.

    So, here is my solution I did in an deploy hook and it worked beautifully:

    $nids = \Drupal::entityQuery('node')->condition('type', 'page')->execute();
    
        foreach ($nids as $nid) {
          $node = Node::load($nid);
          $layout = $node->get('layout_builder__layout');
    
          /** @var \Drupal\layout_builder\Field\LayoutSectionItemList $layout */
          $sections = $layout->getSections();
          foreach ($sections as $section) {
            if ($section->getLayoutSettings()['label'] == 'Content Section') {
              $section->unsetThirdPartySetting('layout_builder_lock', 'lock');
              $section_storage = $this->getSectionStorageForEntity($node);
              $tempStore = \Drupal::service('layout_builder.tempstore_repository');
              $tempStore->set($section_storage);
              $node->save();
            }
          }
        }

    We needed to remove all layout builders lock settings, so this worked. But if anyone else needs something similar, another method would allow you to programmatically set any third party settings. See here: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Config%21...

Production build 0.71.5 2024