function SectionStorageTrait::insertSection

File

core/modules/layout_builder/src/SectionStorage/SectionStorageTrait.php, line 77

Class

SectionStorageTrait
Provides a trait for storing sections on an object.

Namespace

Drupal\layout_builder\SectionStorage

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.