class LayoutSectionItemList
Same name in other branches
- 8.9.x core/modules/layout_builder/src/Field/LayoutSectionItemList.php \Drupal\layout_builder\Field\LayoutSectionItemList
- 10 core/modules/layout_builder/src/Field/LayoutSectionItemList.php \Drupal\layout_builder\Field\LayoutSectionItemList
- 11.x core/modules/layout_builder/src/Field/LayoutSectionItemList.php \Drupal\layout_builder\Field\LayoutSectionItemList
Defines an item list class for layout section fields.
@internal Plugin classes are internal.
Hierarchy
- class \Drupal\Core\TypedData\TypedData implements \Drupal\Core\TypedData\TypedDataInterface, \Drupal\Component\Plugin\PluginInspectionInterface uses \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\TypedData\TypedDataTrait
- class \Drupal\Core\TypedData\Plugin\DataType\ItemList extends \Drupal\Core\TypedData\TypedData implements \Drupal\Core\TypedData\Plugin\DataType\IteratorAggregate, \Drupal\Core\TypedData\ListInterface
- class \Drupal\Core\Field\FieldItemList extends \Drupal\Core\TypedData\Plugin\DataType\ItemList implements \Drupal\Core\Field\FieldItemListInterface
- class \Drupal\layout_builder\Field\LayoutSectionItemList extends \Drupal\Core\Field\FieldItemList implements \Drupal\layout_builder\SectionListInterface uses \Drupal\layout_builder\SectionListTrait
- class \Drupal\Core\Field\FieldItemList extends \Drupal\Core\TypedData\Plugin\DataType\ItemList implements \Drupal\Core\Field\FieldItemListInterface
- class \Drupal\Core\TypedData\Plugin\DataType\ItemList extends \Drupal\Core\TypedData\TypedData implements \Drupal\Core\TypedData\Plugin\DataType\IteratorAggregate, \Drupal\Core\TypedData\ListInterface
Expanded class hierarchy of LayoutSectionItemList
See also
\Drupal\layout_builder\Plugin\Field\FieldType\LayoutSectionItem
File
-
core/
modules/ layout_builder/ src/ Field/ LayoutSectionItemList.php, line 21
Namespace
Drupal\layout_builder\FieldView source
class LayoutSectionItemList extends FieldItemList implements SectionListInterface {
use SectionListTrait;
/**
* Numerically indexed array of field items.
*
* @var \Drupal\layout_builder\Plugin\Field\FieldType\LayoutSectionItem[]
*/
protected $list = [];
/**
* {@inheritdoc}
*/
public function getSections() {
$sections = [];
foreach ($this->list as $delta => $item) {
$sections[$delta] = $item->section;
}
return $sections;
}
/**
* {@inheritdoc}
*/
protected function setSections(array $sections) {
$this->list = [];
$sections = array_values($sections);
/** @var \Drupal\layout_builder\Plugin\Field\FieldType\LayoutSectionItem $item */
foreach ($sections as $section) {
$item = $this->appendItem();
$item->section = $section;
}
return $this;
}
/**
* {@inheritdoc}
*/
public function getEntity() {
$entity = parent::getEntity();
// Ensure the entity is updated with the latest value.
$entity->set($this->getName(), $this->getValue());
return $entity;
}
/**
* {@inheritdoc}
*/
public function preSave() {
parent::preSave();
// Loop through each section and reconstruct it to ensure that all default
// values are present.
foreach ($this->list as $item) {
$item->section = Section::fromArray($item->section
->toArray());
}
}
/**
* {@inheritdoc}
*/
public function equals(FieldItemListInterface $list_to_compare) {
if (!$list_to_compare instanceof LayoutSectionItemList) {
return FALSE;
}
// Convert arrays of section objects to array values for comparison.
$convert = function (LayoutSectionItemList $list) {
return array_map(function (Section $section) {
return $section->toArray();
}, $list->getSections());
};
return $convert($this) === $convert($list_to_compare);
}
/**
* Overrides \Drupal\Core\Field\FieldItemListInterface::defaultAccess().
*
* @ingroup layout_builder_access
*/
public function defaultAccess($operation = 'view', AccountInterface $account = NULL) {
// @todo Allow access in https://www.drupal.org/node/2942975.
return AccessResult::forbidden();
}
}
Members
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.