Change record status: 
Project: 
Introduced in branch: 
8.7.x
Description: 

When interacting with the Layout Builder API, the main data objects are Sections. They are contained by an implementation of SectionListInterface.

A section list will have no sections in it at two different times:

  1. When it is first created
  2. When it has had all existing sections removed from it

There are different workflows that may result from the differences between these two cases.

For example, when a new override is created, the sections from the underlying default are copied over.
But these default sections should not be copied over if a user has purposefully removed them all.

Two new methods have been added:

  1. \Drupal\layout_builder\SectionListInterface::removeAllSections():
    This removes all sections. Previously, code had to rely on removeSection(), which took a delta.
    Before:
    while (count($section_list)) {
      $section_list->removeSection(0);
    }
    

    After:

    $section_list->removeAllSections();
    

    removeAllSections() has an optional parameter: $set_blank. Passing TRUE will cause the layout to be marked as blank, and therefore overridden.

  2. \Drupal\layout_builder\OverridesSectionStorageInterface::isOverridden()
    Allows the override section storage to indicate if it has an override in place. Checking the count() of the sections is not the same as there being an override, since an empty override is possible.
Impacts: 
Module developers