3 namespace Drupal\layout_builder\Plugin\SectionStorage;
5 use Drupal\Core\Plugin\PluginBase;
6 use Drupal\layout_builder\Routing\LayoutBuilderRoutesTrait;
7 use Drupal\layout_builder\Section;
8 use Drupal\layout_builder\SectionListInterface;
9 use Drupal\layout_builder\SectionStorageInterface;
12 * Provides a base class for Section Storage types.
15 * Layout Builder is currently experimental and should only be leveraged by
16 * experimental modules and development releases of contributed modules.
17 * See https://www.drupal.org/core/experimental for more information.
19 abstract class SectionStorageBase extends PluginBase implements SectionStorageInterface {
21 use LayoutBuilderRoutesTrait;
24 * The section storage instance.
26 * @var \Drupal\layout_builder\SectionListInterface|null
28 protected $sectionList;
33 public function setSectionList(SectionListInterface $section_list) {
34 $this->sectionList = $section_list;
39 * Gets the section list.
41 * @return \Drupal\layout_builder\SectionListInterface
44 * @throws \RuntimeException
45 * Thrown if ::setSectionList() is not called first.
47 protected function getSectionList() {
48 if (!$this->sectionList) {
49 throw new \RuntimeException(sprintf('%s::setSectionList() must be called first', static::class));
51 return $this->sectionList;
57 public function getStorageType() {
58 return $this->getPluginId();
64 public function count() {
65 return $this->getSectionList()->count();
71 public function getSections() {
72 return $this->getSectionList()->getSections();
78 public function getSection($delta) {
79 return $this->getSectionList()->getSection($delta);
85 public function appendSection(Section $section) {
86 $this->getSectionList()->appendSection($section);
93 public function insertSection($delta, Section $section) {
94 $this->getSectionList()->insertSection($delta, $section);
101 public function removeSection($delta) {
102 $this->getSectionList()->removeSection($delta);