You are here

protected function EntityController::doGetEntity in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Entity/Controller/EntityController.php \Drupal\Core\Entity\Controller\EntityController::doGetEntity()

Determines the entity.

Parameters

\Drupal\Core\Routing\RouteMatchInterface $route_match: The route match.

\Drupal\Core\Entity\EntityInterface $_entity: (optional) The entity, set in \Drupal\Core\Entity\Enhancer\EntityRouteEnhancer.

Return value

\Drupal\Core\Entity\EntityInterface|null The entity, if it is passed in directly or if the first parameter of the active route is an entity; otherwise, NULL.

3 calls to EntityController::doGetEntity()
EntityController::deleteTitle in core/lib/Drupal/Core/Entity/Controller/EntityController.php
Provides a generic delete title callback.
EntityController::editTitle in core/lib/Drupal/Core/Entity/Controller/EntityController.php
Provides a generic edit title callback.
EntityController::title in core/lib/Drupal/Core/Entity/Controller/EntityController.php
Provides a generic title callback for a single entity.

File

core/lib/Drupal/Core/Entity/Controller/EntityController.php, line 302

Class

EntityController
Provides the add-page and title callbacks for entities.

Namespace

Drupal\Core\Entity\Controller

Code

protected function doGetEntity(RouteMatchInterface $route_match, EntityInterface $_entity = NULL) {
  if ($_entity) {
    $entity = $_entity;
  }
  else {

    // Let's look up in the route object for the name of upcasted values.
    foreach ($route_match
      ->getParameters() as $parameter) {
      if ($parameter instanceof EntityInterface) {
        $entity = $parameter;
        break;
      }
    }
  }
  if (isset($entity)) {
    return $this->entityRepository
      ->getTranslationFromContext($entity);
  }
}