public function TitleResolver::getTitle in Easy Breadcrumb 8
Same name and namespace in other branches
- 2.x src/TitleResolver.php \Drupal\easy_breadcrumb\TitleResolver::getTitle()
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 TitleResolver::getTitle
File
- src/
TitleResolver.php, line 59
Class
- TitleResolver
- Class TitleResolver.
Namespace
Drupal\easy_breadcrumbCode
public function getTitle(Request $request, Route $route) {
$url = Url::fromUri("internal:" . $request
->getRequestUri());
$route_parts = explode(".", $url
->getRouteName());
$entity = NULL;
$params = $url
->getRouteParameters();
if ($route_parts[0] === 'entity' && $route_parts[2] === 'canonical') {
$entity_type = $route_parts[1];
$entity = $this->entityTypeManager
->getStorage($entity_type)
->load($params[$entity_type]);
}
if ($entity !== NULL) {
$alternative_title_field = $this->config
->get(EasyBreadcrumbConstants::ALTERNATIVE_TITLE_FIELD);
if ($entity
->hasField($alternative_title_field) && !$entity
->get($alternative_title_field)
->isEmpty()) {
return Xss::filter($entity
->get($alternative_title_field)->value);
}
}
return parent::getTitle($request, $route);
}