function OverridesSectionStorage::extractEntityFromRoute
Same name in other branches
- 8.9.x core/modules/layout_builder/src/Plugin/SectionStorage/OverridesSectionStorage.php \Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage::extractEntityFromRoute()
- 10 core/modules/layout_builder/src/Plugin/SectionStorage/OverridesSectionStorage.php \Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage::extractEntityFromRoute()
- 11.x core/modules/layout_builder/src/Plugin/SectionStorage/OverridesSectionStorage.php \Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage::extractEntityFromRoute()
Extracts an entity from the route values.
Parameters
mixed $value: The raw value from the route.
array $defaults: The route defaults array.
Return value
\Drupal\Core\Entity\EntityInterface|null The entity for the route, or NULL if none exist.
See also
\Drupal\layout_builder\SectionStorageInterface::deriveContextsFromRoute()
\Drupal\Core\ParamConverter\ParamConverterInterface::convert()
1 call to OverridesSectionStorage::extractEntityFromRoute()
- OverridesSectionStorage::deriveContextsFromRoute in core/
modules/ layout_builder/ src/ Plugin/ SectionStorage/ OverridesSectionStorage.php - Derives the available plugin contexts from route values.
File
-
core/
modules/ layout_builder/ src/ Plugin/ SectionStorage/ OverridesSectionStorage.php, line 196
Class
- OverridesSectionStorage
- Defines the 'overrides' section storage type.
Namespace
Drupal\layout_builder\Plugin\SectionStorageCode
private function extractEntityFromRoute($value, array $defaults) {
if (strpos($value, '.') !== FALSE) {
[
$entity_type_id,
$entity_id,
] = explode('.', $value, 2);
}
elseif (isset($defaults['entity_type_id']) && !empty($defaults[$defaults['entity_type_id']])) {
$entity_type_id = $defaults['entity_type_id'];
$entity_id = $defaults[$entity_type_id];
}
else {
return NULL;
}
$entity = $this->entityRepository
->getActive($entity_type_id, $entity_id);
if ($entity instanceof FieldableEntityInterface && $entity->hasField(static::FIELD_NAME)) {
return $entity;
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.