You are here

private function OverridesSectionStorage::extractEntityFromRoute in Drupal 9

Same name and namespace in other branches
  1. 8 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\SectionStorage

Code

private function extractEntityFromRoute($value, array $defaults) {
  if (strpos($value, '.') !== FALSE) {
    list($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;
  }
}