Commit 2816f045 authored by Adam G-H's avatar Adam G-H
Browse files

Refactored EntityRouteProvider::getEntityFromRoute() to rely on _entity_view...

Refactored EntityRouteProvider::getEntityFromRoute() to rely on _entity_view default, rather than route name.
parent d7143ff4
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -93,10 +93,11 @@ final class EntityRouteProvider implements ContextProviderInterface {
   *   The entity being viewed, or NULL if we're not viewing an entity.
   */
  private function getEntityFromRoute() {
    $match = [];
    $route = $this->routeMatch->getRouteObject();

    if (preg_match('/^entity\.([a-z0-9_]+)\.canonical$/', $this->routeMatch->getRouteName(), $match)) {
      return $this->routeMatch->getParameter($match[1]);
    if ($route && $route->hasDefault('_entity_view')) {
      list ($entity_type_id) = explode('.', $route->getDefault('_entity_view'));
      return $this->routeMatch->getParameter($entity_type_id);
    }
    return NULL;
  }