Cannot add new section to default node layout

Created on 25 November 2024, 23 days ago

Problem/motivation

When attempting to add a new section that was previously restricted to the default layout for a content type I find that the site is stuck in an endless loop of (see steps below). Of note, this happens when using Drupal core 11.0.5 and layout_builder_restrictions 3.0.0.

Steps to reproduce

  1. Go to the content type configuration > manage display page > layouts available for sections, attempt to enable a previously disabled layout
  2. Click on the "Manage Layout" button for the same display
  3. Observe that you cannot see the section that you just enabled in the allowed sections list (the bug)
  4. Also observe that the layout says it has unsaved changed, do not save the save changes yet
  5. Observe that if you export configuration, the section you attempted to enable is properly exported and appears that it should be enabled
  6. Observe that if you click save layout or save on the default layout showing unsaved changes and then export again, the configuration is lost

Proposed resolution

Somewhere in the layout_builder_restrictions/src/Plugin/LayoutBuilderRestriction/EntityViewModeRestriction.php file there is an issue. When I comment out the changes to the $definitions variable I am able to see all of the sections add the section I need and then save the configuration but the new section that should be enabled is still lost after saving the section.

  /**
   * {@inheritdoc}
   */
  public function alterSectionDefinitions(array $definitions, array $context) {
    // Respect restrictions on allowed layouts specified by section storage.
    if (isset($context['section_storage'])) {
      $default = $context['section_storage'] instanceof OverridesSectionStorageInterface ? $context['section_storage']->getDefaultSectionStorage() : $context['section_storage'];
      if ($default instanceof ThirdPartySettingsInterface) {
        $third_party_settings = $default->getThirdPartySetting('layout_builder_restrictions', 'entity_view_mode_restriction', []);
        $allowed_layouts = (isset($third_party_settings['allowed_layouts'])) ? $third_party_settings['allowed_layouts'] : [];
        // Filter blocks from entity-specific SectionStorage (i.e., UI).
        if (!empty($allowed_layouts)) {
          $definitions = array_intersect_key($definitions, array_flip($allowed_layouts));
        }
      }
    }
    return $definitions;
  }
πŸ› Bug report
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States ccjjmartin Austin, TX

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

Comments & Activities

Production build 0.71.5 2024