Same filename and directory in other branches
- 8.9.x core/modules/layout_builder/src/Field/LayoutSectionItemList.php
- 9 core/modules/layout_builder/src/Field/LayoutSectionItemList.php
Namespace
Drupal\layout_builder\Field
File
core/modules/layout_builder/src/Field/LayoutSectionItemList.php
View source
<?php
namespace Drupal\layout_builder\Field;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Field\FieldItemList;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\layout_builder\Section;
use Drupal\layout_builder\SectionListInterface;
use Drupal\layout_builder\SectionListTrait;
class LayoutSectionItemList extends FieldItemList implements SectionListInterface {
use SectionListTrait;
protected $list = [];
public function getSections() {
$sections = [];
foreach ($this->list as $delta => $item) {
$sections[$delta] = $item->section;
}
return $sections;
}
protected function setSections(array $sections) {
$this->list = [];
$sections = array_values($sections);
foreach ($sections as $section) {
$item = $this
->appendItem();
$item->section = $section;
}
return $this;
}
public function getEntity() {
$entity = parent::getEntity();
$entity
->set($this
->getName(), $this
->getValue());
return $entity;
}
public function preSave() {
parent::preSave();
foreach ($this->list as $item) {
$item->section = Section::fromArray($item->section
->toArray());
}
}
public function equals(FieldItemListInterface $list_to_compare) {
if (!$list_to_compare instanceof LayoutSectionItemList) {
return FALSE;
}
$convert = function (LayoutSectionItemList $list) {
return array_map(function (Section $section) {
return $section
->toArray();
}, $list
->getSections());
};
return $convert($this) === $convert($list_to_compare);
}
public function defaultAccess($operation = 'view', AccountInterface $account = NULL) {
return AccessResult::forbidden();
}
}
Classes