You are here

public function SectionStorageTrait::insertSection in Drupal 8

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;
}