3 namespace Drupal\layout_builder\Field;
5 use Drupal\Core\Field\FieldItemList;
6 use Drupal\layout_builder\SectionListInterface;
7 use Drupal\layout_builder\SectionStorage\SectionStorageTrait;
10 * Defines a item list class for layout section fields.
14 * @see \Drupal\layout_builder\Plugin\Field\FieldType\LayoutSectionItem
16 class LayoutSectionItemList extends FieldItemList implements SectionListInterface {
18 use SectionStorageTrait;
23 public function getSections() {
25 /** @var \Drupal\layout_builder\Plugin\Field\FieldType\LayoutSectionItem $item */
26 foreach ($this->list as $delta => $item) {
27 $sections[$delta] = $item->section;
35 protected function setSections(array $sections) {
37 $sections = array_values($sections);
38 /** @var \Drupal\layout_builder\Plugin\Field\FieldType\LayoutSectionItem $item */
39 foreach ($sections as $section) {
40 $item = $this->appendItem();
41 $item->section = $section;
50 public function getEntity() {
51 $entity = parent::getEntity();
53 // Ensure the entity is updated with the latest value.
54 $entity->set($this->getName(), $this->getValue());