You are here

protected function ScheduledTransitionsLocalTask::getEntityFromRouteMatch in Scheduled Transitions 2.x

Same name and namespace in other branches
  1. 8 src/Plugin/Menu/LocalTask/ScheduledTransitionsLocalTask.php \Drupal\scheduled_transitions\Plugin\Menu\LocalTask\ScheduledTransitionsLocalTask::getEntityFromRouteMatch()

Get entity from route match.

Return value

\Drupal\Core\Entity\ContentEntityInterface|null The entity from route match.

2 calls to ScheduledTransitionsLocalTask::getEntityFromRouteMatch()
ScheduledTransitionsLocalTask::getCacheTags in src/Plugin/Menu/LocalTask/ScheduledTransitionsLocalTask.php
The cache tags associated with this object.
ScheduledTransitionsLocalTask::getTitle in src/Plugin/Menu/LocalTask/ScheduledTransitionsLocalTask.php
Returns the localized title to be shown for this tab.

File

src/Plugin/Menu/LocalTask/ScheduledTransitionsLocalTask.php, line 146

Class

ScheduledTransitionsLocalTask
Provides a local task showing count of scheduled transitions for an entity.

Namespace

Drupal\scheduled_transitions\Plugin\Menu\LocalTask

Code

protected function getEntityFromRouteMatch() : ?ContentEntityInterface {
  [
    1 => $entityTypeId,
  ] = explode('.', $this->pluginDefinition['base_route']);

  // Get the first parameter in the route definition matching the entity type,
  // since the upcasted entity parameter could be something like {entity}.
  $parameters = $this->routeMatch
    ->getParameters()
    ->all();
  foreach ($parameters as $parameter) {
    if ($parameter instanceof ContentEntityInterface && $parameter
      ->getEntityTypeId() === $entityTypeId) {
      return $parameter;
    }
  }
  return NULL;
}