TitleResolver.php in Drupal 10
File
core/lib/Drupal/Core/Controller/TitleResolver.php
View source
<?php
namespace Drupal\Core\Controller;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface;
use Symfony\Component\Routing\Route;
class TitleResolver implements TitleResolverInterface {
use StringTranslationTrait;
protected $controllerResolver;
protected $argumentResolver;
public function __construct(ControllerResolverInterface $controller_resolver, TranslationInterface $string_translation, ArgumentResolverInterface $argument_resolver) {
$this->controllerResolver = $controller_resolver;
$this->stringTranslation = $string_translation;
$this->argumentResolver = $argument_resolver;
}
public function getTitle(Request $request, Route $route) {
$route_title = NULL;
if ($callback = $route
->getDefault('_title_callback')) {
$callable = $this->controllerResolver
->getControllerFromDefinition($callback);
$arguments = $this->argumentResolver
->getArguments($request, $callable);
$route_title = call_user_func_array($callable, $arguments);
}
elseif ($title = $route
->getDefault('_title')) {
$options = [];
if ($context = $route
->getDefault('_title_context')) {
$options['context'] = $context;
}
$args = [];
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);
}
$route_title = $this
->t($title, $args, $options);
}
return $route_title;
}
}
Classes
Name |
Description |
TitleResolver |
Provides the default implementation of the title resolver interface. |