function SectionListTrait::insertSection

Same name in other branches
  1. 9 core/modules/layout_builder/src/SectionListTrait.php \Drupal\layout_builder\SectionListTrait::insertSection()
  2. 11.x core/modules/layout_builder/src/SectionListTrait.php \Drupal\layout_builder\SectionListTrait::insertSection()

File

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

Class

SectionListTrait
Provides a trait for maintaining a list of sections.

Namespace

Drupal\layout_builder

Code

public function insertSection($delta, Section $section) {
    // Clear the section list if there is currently a blank section.
    if ($this->hasBlankSection()) {
        $this->removeAllSections();
    }
    if ($this->hasSection($delta)) {
        // @todo Use https://www.drupal.org/node/66183 once resolved.
        $start = array_slice($this->getSections(), 0, $delta);
        $end = array_slice($this->getSections(), $delta);
        $this->setSections(array_merge($start, [
            $section,
        ], $end));
    }
    else {
        $this->appendSection($section);
    }
    return $this;
}

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