protected function LayoutEntityHelperTrait::getSectionStorageForEntity in Drupal 8
Same name and namespace in other branches
- 9 core/modules/layout_builder/src/LayoutEntityHelperTrait.php \Drupal\layout_builder\LayoutEntityHelperTrait::getSectionStorageForEntity()
- 10 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_builderCode
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());
}