Summary:

The below error occurs after a user removes all sections from a layout and saves while the Quickedit module is enabled.

The website encountered an unexpected error. Please try again later.
Error: Call to a member function getRegionNames() on null in Drupal\layout_builder\QuickEditIntegration->entityViewAlter() (line 134 of core/modules/layout_builder/src/QuickEditIntegration.php).

Additionally, this error will appear in the log:
Notice: Undefined index: #layout in Drupal\layout_builder\QuickEditIntegration->entityViewAlter() (line 133 of core/modules/layout_builder/src/QuickEditIntegration.php).

Steps to reproduce:

  • Install Drupal 8.7.3
  • Enable Layout Builder
  • Under Manage Display of any content type, enable both "Use Layout Builder" and "Allow each content item to have its layout customized."
  • Create a Layout enabled node
  • Click the "Layout" tab of this new node and remove all sections
  • Click "Save layout"

Proposed fix:

In QuickEditIntegration.php wrap lines 132 to 144 in an if statement so that it looks like this:

if (!empty($section)) {
  /** @var \Drupal\Core\Layout\LayoutDefinition $layout */
  $layout = $section['#layout'];
  $regions = $layout->getRegionNames();

  foreach ($regions as $region) {
    if (isset($section[$region])) {
      foreach ($section[$region] as $uuid => $component) {
        if (isset($component['#plugin_id']) && $this->supportQuickEditOnComponent($component, $entity)) {
          $plugin_ids_to_update[$component['#plugin_id']][$delta][$region][$uuid] = $uuid;
        }
      }
    }
  }
}

Comments

jeremyr created an issue. See original summary.

jeremyr’s picture

StatusFileSize
new1.62 KB
tim.plunkett’s picture

Version: 8.7.x-dev » 8.8.x-dev
Status: Active » Needs review
Issue tags: +Blocks-Layouts
StatusFileSize
new859 bytes
new2.47 KB
new1.57 KB

Nice find. We have test coverage for removing all sections, but quickedit wasn't installed.

Also, the render system provides a bespoke isEmpty method that handles #cache info, switching to that.

The last submitted patch, 3: 3065474-emptysection-3-FAIL.patch, failed testing. View results

omkar06’s picture

Assigned: Unassigned » omkar06
omkar06’s picture

Status: Needs review » Reviewed & tested by the community

Tested Patch provided in #3. After applying a patch, I am able to view the page even I remove all sections from the layout of the page. Before applying a patch, I was able to reproduce an issue.

omkar06’s picture

Assigned: omkar06 » Unassigned
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed a2d8c0a and pushed to 8.8.x. Thanks!

  • catch committed a2d8c0a on 8.8.x
    Issue #3065474 by tim.plunkett, jeremyr, omkar06: An error occurs when...

Status: Fixed » Closed (fixed)

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

paulkerrigan’s picture

Notice: Undefined index: #layout in Drupal\layout_builder\QuickEditIntegration->entityViewAlter() (line 133 of core/modules/layout_builder/src/QuickEditIntegration.php).

The notice above can be avoided by adding a further check inside the if-statement, to make sure $section['#layout'] is not empty.

As the code relies on the availability of the LayoutDefinition object, it appears that there is no need to run the loop if it's unset. Please correct me if I'm wrong. Thanks.

      $section = $build['_layout_builder'][$delta];
      if (!Element::isEmpty($section) && !empty($section['#layout'])) {
        /** @var \Drupal\Core\Layout\LayoutDefinition $layout */
        $layout = $section['#layout'];
        $regions = $layout->getRegionNames();

        foreach ($regions as $region) {
          if (isset($section[$region])) {
            foreach ($section[$region] as $uuid => $component) {
              if (isset($component['#plugin_id']) && $this->supportQuickEditOnComponent($component, $entity)) {
                $plugin_ids_to_update[$component['#plugin_id']][$delta][$region][$uuid] = $uuid;
              }
            }
          }
        }
      }