class LayoutSectionItemList

Same name in other branches
  1. 8.9.x core/modules/layout_builder/src/Field/LayoutSectionItemList.php \Drupal\layout_builder\Field\LayoutSectionItemList
  2. 10 core/modules/layout_builder/src/Field/LayoutSectionItemList.php \Drupal\layout_builder\Field\LayoutSectionItemList
  3. 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

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\Field
View 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

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FieldItemList::$langcode protected property The langcode of the field values held in the object.
FieldItemList::access public function Overrides AccessibleInterface::access 1
FieldItemList::applyDefaultValue public function Overrides TypedData::applyDefaultValue
FieldItemList::createItem protected function Overrides ItemList::createItem
FieldItemList::defaultValuesForm public function Overrides FieldItemListInterface::defaultValuesForm 2
FieldItemList::defaultValuesFormSubmit public function Overrides FieldItemListInterface::defaultValuesFormSubmit 2
FieldItemList::defaultValuesFormValidate public function Overrides FieldItemListInterface::defaultValuesFormValidate 1
FieldItemList::defaultValueWidget protected function Returns the widget object used in default value form.
FieldItemList::delegateMethod protected function Calls a method on each FieldItem.
FieldItemList::delete public function Overrides FieldItemListInterface::delete 2
FieldItemList::deleteRevision public function Overrides FieldItemListInterface::deleteRevision 1
FieldItemList::filterEmptyItems public function Overrides FieldItemListInterface::filterEmptyItems
FieldItemList::generateSampleItems public function Overrides FieldItemListInterface::generateSampleItems 1
FieldItemList::getConstraints public function Overrides TypedData::getConstraints 1
FieldItemList::getFieldDefinition public function Overrides FieldItemListInterface::getFieldDefinition
FieldItemList::getLangcode public function Overrides FieldItemListInterface::getLangcode
FieldItemList::getSetting public function Overrides FieldItemListInterface::getSetting
FieldItemList::getSettings public function Overrides FieldItemListInterface::getSettings
FieldItemList::hasAffectingChanges public function Overrides FieldItemListInterface::hasAffectingChanges 1
FieldItemList::postSave public function Overrides FieldItemListInterface::postSave 1
FieldItemList::processDefaultValue public static function Overrides FieldItemListInterface::processDefaultValue 2
FieldItemList::setLangcode public function Overrides FieldItemListInterface::setLangcode
FieldItemList::setValue public function Overrides ItemList::setValue
FieldItemList::view public function Overrides FieldItemListInterface::view
FieldItemList::__get public function Overrides FieldItemListInterface::__get
FieldItemList::__isset public function Overrides FieldItemListInterface::__isset
FieldItemList::__set public function Overrides FieldItemListInterface::__set
FieldItemList::__unset public function Overrides FieldItemListInterface::__unset
ItemList::appendItem public function Overrides ListInterface::appendItem
ItemList::filter public function Overrides ListInterface::filter
ItemList::first public function Overrides ListInterface::first
ItemList::get public function Overrides ListInterface::get 2
ItemList::getItemDefinition public function Overrides ListInterface::getItemDefinition
ItemList::getIterator public function
ItemList::getString public function Overrides TypedData::getString
ItemList::getValue public function Overrides TypedData::getValue
ItemList::isEmpty public function Overrides ListInterface::isEmpty
ItemList::offsetExists public function 1
ItemList::offsetGet public function
ItemList::offsetSet public function
ItemList::offsetUnset public function
ItemList::onChange public function Overrides TraversableTypedDataInterface::onChange 1
ItemList::rekey protected function Renumbers the items in the list.
ItemList::removeItem public function Overrides ListInterface::removeItem
ItemList::set public function Overrides ListInterface::set
LayoutSectionItemList::$list protected property Numerically indexed array of field items. Overrides FieldItemList::$list
LayoutSectionItemList::defaultAccess public function Overrides \Drupal\Core\Field\FieldItemListInterface::defaultAccess(). Overrides FieldItemList::defaultAccess
LayoutSectionItemList::equals public function Determines equality to another object implementing FieldItemListInterface. Overrides FieldItemList::equals
LayoutSectionItemList::getEntity public function Gets the entity that field belongs to. Overrides FieldItemList::getEntity
LayoutSectionItemList::getSections public function Gets the layout sections. Overrides SectionListInterface::getSections
LayoutSectionItemList::preSave public function Defines custom presave behavior for field values. Overrides FieldItemList::preSave
LayoutSectionItemList::setSections protected function Stores the information for all sections. Overrides SectionListTrait::setSections
SectionListTrait::addBlankSection protected function Adds a blank section to the list.
SectionListTrait::appendSection public function
SectionListTrait::count public function
SectionListTrait::getSection public function
SectionListTrait::hasBlankSection protected function Indicates if this section list contains a blank section.
SectionListTrait::hasSection protected function Indicates if there is a section at the specified delta.
SectionListTrait::insertSection public function
SectionListTrait::removeAllSections public function
SectionListTrait::removeSection public function
SectionListTrait::setSection protected function Sets the section for the given delta on the display.
SectionListTrait::__clone public function Magic method: Implements a deep clone.
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
TypedData::$definition protected property The data definition. 1
TypedData::$name protected property The property name.
TypedData::$parent protected property The parent typed data object.
TypedData::createInstance public static function Overrides TypedDataInterface::createInstance
TypedData::getDataDefinition public function Overrides TypedDataInterface::getDataDefinition
TypedData::getName public function Overrides TypedDataInterface::getName
TypedData::getParent public function Overrides TypedDataInterface::getParent
TypedData::getPluginDefinition public function Overrides PluginInspectionInterface::getPluginDefinition
TypedData::getPluginId public function Overrides PluginInspectionInterface::getPluginId
TypedData::getPropertyPath public function Overrides TypedDataInterface::getPropertyPath
TypedData::getRoot public function Overrides TypedDataInterface::getRoot
TypedData::setContext public function Overrides TypedDataInterface::setContext
TypedData::validate public function Overrides TypedDataInterface::validate
TypedData::__construct public function Constructs a TypedData object given its definition and context. 3
TypedDataTrait::$typedDataManager protected property The typed data manager used for creating the data types.
TypedDataTrait::getTypedDataManager public function Gets the typed data manager. 2
TypedDataTrait::setTypedDataManager public function Sets the typed data manager. 2

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.