function SectionListTrait::removeSection

Same name in other branches
  1. 9 core/modules/layout_builder/src/SectionListTrait.php \Drupal\layout_builder\SectionListTrait::removeSection()
  2. 10 core/modules/layout_builder/src/SectionListTrait.php \Drupal\layout_builder\SectionListTrait::removeSection()
1 call to SectionListTrait::removeSection()
LayoutBuilderEntityViewDisplay::onDependencyRemoval in core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php
Informs the entity that entities it depends on will be deleted.

File

core/modules/layout_builder/src/SectionListTrait.php, line 132

Class

SectionListTrait
Provides a trait for maintaining a list of sections.

Namespace

Drupal\layout_builder

Code

public function removeSection($delta) {
    // Clear the section list if there is currently a blank section.
    if ($this->hasBlankSection()) {
        $this->removeAllSections();
    }
    $sections = $this->getSections();
    unset($sections[$delta]);
    $this->setSections($sections);
    // Add a blank section when the last section is removed.
    if (empty($sections)) {
        $this->addBlankSection();
    }
    return $this;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.