TitleResolver::getTitle

public TitleResolver::getTitle(Request $request, Route $route)

Returns a static or dynamic title for the route.

If the returned title can contain HTML that should not be escaped it should return a render array, for example:

['#markup' => 'title', '#allowed_tags' => ['em']]

If the method returns a string and it is not marked safe then it will be auto-escaped.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request object passed to the title callback.

\Symfony\Component\Routing\Route $route: The route information of the route to fetch the title.

Return value

array|string|null The title for the route.

Overrides TitleResolverInterface::getTitle

File

core/lib/Drupal/Core/Controller/TitleResolver.php, line 39

Class

TitleResolver
Provides the default implementation of the title resolver interface.

Namespace

Drupal\Core\Controller

Code

public function getTitle(Request $request, Route $route) {
  $route_title = NULL;
  // A dynamic title takes priority. Route::getDefault() returns NULL if the
  // named default is not set.  By testing the value directly, we also avoid
  // trying to use empty values.
  if ($callback = $route->getDefault('_title_callback')) {
    $callable = $this->controllerResolver->getControllerFromDefinition($callback);
    $arguments = $this->controllerResolver->getArguments($request, $callable);
    $route_title = call_user_func_array($callable, $arguments);
  }
  elseif ($title = $route->getDefault('_title')) {
    $options = array();
    if ($context = $route->getDefault('_title_context')) {
      $options['context'] = $context;
    }
    $args = array();
    if (($raw_parameters = $request->attributes->get('_raw_variables'))) {
      foreach ($raw_parameters->all() as $key => $value) {
        $args['@' . $key] = $value;
        $args['%' . $key] = $value;
      }
    }
    if ($title_arguments = $route->getDefault('_title_arguments')) {
      $args = array_merge($args, (array) $title_arguments);
    }

    // Fall back to a static string from the route.
    $route_title = $this->t($title, $args, $options);
  }
  return $route_title;
}
doc_Drupal
2016-10-29 09:48:30
Comments
Leave a Comment

Please login to continue.