You are here

protected function ContentAwareGenerator::getBestLocaleRoute in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony-cmf/routing/ContentAwareGenerator.php \Symfony\Cmf\Component\Routing\ContentAwareGenerator::getBestLocaleRoute()

Determine if there is a route with matching locale associated with the given route via associated content.

Parameters

SymfonyRoute $route:

array $parameters:

Return value

SymfonyRoute either the passed route or an alternative with better locale

2 calls to ContentAwareGenerator::getBestLocaleRoute()
ContentAwareGenerator::generate in vendor/symfony-cmf/routing/ContentAwareGenerator.php
ContentAwareGenerator::getRouteByName in vendor/symfony-cmf/routing/ContentAwareGenerator.php
Get the route by a string name

File

vendor/symfony-cmf/routing/ContentAwareGenerator.php, line 117

Class

ContentAwareGenerator
A generator that tries to generate routes from object, route names or content objects or names.

Namespace

Symfony\Cmf\Component\Routing

Code

protected function getBestLocaleRoute(SymfonyRoute $route, $parameters) {
  if (!$route instanceof RouteObjectInterface) {

    // this route has no content, we can't get the alternatives
    return $route;
  }
  $locale = $this
    ->getLocale($parameters);
  if (!$this
    ->checkLocaleRequirement($route, $locale)) {
    $content = $route
      ->getContent();
    if ($content instanceof RouteReferrersReadInterface) {
      $routes = $content
        ->getRoutes();
      $contentRoute = $this
        ->getRouteByLocale($routes, $locale);
      if ($contentRoute) {
        return $contentRoute;
      }
    }
  }
  return $route;
}