getSections()); } /** * {@inheritdoc} */ public function getSection($delta) { if (!$this->hasSection($delta)) { throw new \OutOfBoundsException(sprintf('Invalid delta "%s"', $delta)); } return $this->getSections()[$delta]; } /** * Sets the section for the given delta on the display. * * @param int $delta * The delta of the section. * @param \Drupal\layout_builder\Section $section * The layout section. * * @return $this */ protected function setSection($delta, Section $section) { $sections = $this->getSections(); $sections[$delta] = $section; $this->setSections($sections); return $this; } /** * {@inheritdoc} */ public function appendSection(Section $section) { $delta = $this->count(); $this->setSection($delta, $section); return $this; } /** * {@inheritdoc} */ public function insertSection($delta, Section $section) { 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; } /** * {@inheritdoc} */ public function removeSection($delta) { $sections = $this->getSections(); unset($sections[$delta]); $this->setSections($sections); return $this; } /** * Indicates if there is a section at the specified delta. * * @param int $delta * The delta of the section. * * @return bool * TRUE if there is a section for this delta, FALSE otherwise. */ protected function hasSection($delta) { return isset($this->getSections()[$delta]); } /** * Magic method: Implements a deep clone. */ public function __clone() { $sections = $this->getSections(); foreach ($sections as $delta => $item) { $sections[$delta] = clone $item; } $this->setSections($sections); } }