class LayoutSectionItemList

Same name and namespace in other branches
  1. 11.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. 8.9.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 An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function
DependencySerializationTrait::__wakeup public function #[\ReturnTypeWillChange]
FieldItemList::$langcode protected property The langcode of the field values held in the object.
FieldItemList::access public function
FieldItemList::applyDefaultValue public function
FieldItemList::createItem protected function
FieldItemList::defaultValuesForm public function 1
FieldItemList::defaultValuesForm public function 1
FieldItemList::defaultValuesFormSubmit public function
FieldItemList::defaultValuesFormValidate public function
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 1
FieldItemList::delete public function 1
FieldItemList::deleteRevision public function 1
FieldItemList::deleteRevision public function 1
FieldItemList::filterEmptyItems public function
FieldItemList::generateSampleItems public function
FieldItemList::getConstraints public function
FieldItemList::getFieldDefinition public function
FieldItemList::getLangcode public function
FieldItemList::getSetting public function
FieldItemList::getSettings public function
FieldItemList::hasAffectingChanges public function
FieldItemList::postSave public function 1
FieldItemList::postSave public function 1
FieldItemList::processDefaultValue public static function
FieldItemList::setLangcode public function
FieldItemList::setValue public function
FieldItemList::view public function
FieldItemList::__get public function
FieldItemList::__isset public function
FieldItemList::__set public function
FieldItemList::__unset public function
ItemList::appendItem public function
ItemList::filter public function
ItemList::first public function
ItemList::get public function
ItemList::getItemDefinition public function
ItemList::getIterator public function #[\ReturnTypeWillChange]
ItemList::getString public function
ItemList::getValue public function
ItemList::isEmpty public function
ItemList::offsetExists public function #[\ReturnTypeWillChange]
ItemList::offsetGet public function #[\ReturnTypeWillChange]
ItemList::offsetSet public function #[\ReturnTypeWillChange]
ItemList::offsetUnset public function #[\ReturnTypeWillChange]
ItemList::onChange public function
ItemList::rekey protected function Renumbers the items in the list.
ItemList::removeItem public function
ItemList::set public function
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 #[\ReturnTypeWillChange]
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.
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.
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
TypedData::$definition protected property The data definition.
TypedData::$name protected property The property name.
TypedData::$parent protected property The parent typed data object.
TypedData::createInstance public static function
TypedData::getDataDefinition public function
TypedData::getName public function
TypedData::getParent public function
TypedData::getPluginDefinition public function
TypedData::getPluginId public function
TypedData::getPropertyPath public function
TypedData::getRoot public function
TypedData::setContext public function
TypedData::validate public function
TypedData::__construct public function Constructs a TypedData object given its definition and context.
TypedDataTrait::$typedDataManager protected property The typed data manager used for creating the data types.
TypedDataTrait::getTypedDataManager public function Gets the typed data manager.
TypedDataTrait::setTypedDataManager public function Sets the typed data manager.

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