function LayoutEntityHelperTrait::getSectionStorageForEntity

Same name and namespace in other branches
  1. 9 core/modules/layout_builder/src/LayoutEntityHelperTrait.php \Drupal\layout_builder\LayoutEntityHelperTrait::getSectionStorageForEntity()
  2. 10 core/modules/layout_builder/src/LayoutEntityHelperTrait.php \Drupal\layout_builder\LayoutEntityHelperTrait::getSectionStorageForEntity()
  3. 11.x core/modules/layout_builder/src/LayoutEntityHelperTrait.php \Drupal\layout_builder\LayoutEntityHelperTrait::getSectionStorageForEntity()

Gets the section storage for an entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity.

Return value

\Drupal\layout_builder\SectionStorageInterface|null The section storage if found otherwise NULL.

3 calls to LayoutEntityHelperTrait::getSectionStorageForEntity()
LayoutEntityHelperTrait::getEntitySections in core/modules/layout_builder/src/LayoutEntityHelperTrait.php
Gets the sections for an entity if any.
LayoutEntityHelperTrait::isLayoutCompatibleEntity in core/modules/layout_builder/src/LayoutEntityHelperTrait.php
Determines if an entity can have a layout.
LayoutEntityHelperTrait::originalEntityUsesDefaultStorage in core/modules/layout_builder/src/LayoutEntityHelperTrait.php
Determines if the original entity used the default section storage.

File

core/modules/layout_builder/src/LayoutEntityHelperTrait.php, line 106

Class

LayoutEntityHelperTrait
Methods to help with entities using the layout builder.

Namespace

Drupal\layout_builder

Code

protected function getSectionStorageForEntity(EntityInterface $entity) {
    // @todo Take into account other view modes in
    //   https://www.drupal.org/node/3008924.
    $view_mode = 'full';
    if ($entity instanceof LayoutEntityDisplayInterface) {
        $contexts['display'] = EntityContext::fromEntity($entity);
        $contexts['view_mode'] = new Context(new ContextDefinition('string'), $entity->getMode());
    }
    else {
        $contexts['entity'] = EntityContext::fromEntity($entity);
        if ($entity instanceof FieldableEntityInterface) {
            $display = EntityViewDisplay::collectRenderDisplay($entity, $view_mode);
            if ($display instanceof LayoutEntityDisplayInterface) {
                $contexts['display'] = EntityContext::fromEntity($display);
            }
            $contexts['view_mode'] = new Context(new ContextDefinition('string'), $view_mode);
        }
    }
    return $this->sectionStorageManager()
        ->findByContext($contexts, new CacheableMetadata());
}

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