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