class TitleResolver in Easy Breadcrumb 8
Same name and namespace in other branches
- 2.x src/TitleResolver.php \Drupal\easy_breadcrumb\TitleResolver
Class TitleResolver.
Hierarchy
- class \Drupal\Core\Controller\TitleResolver implements TitleResolverInterface uses StringTranslationTrait
- class \Drupal\easy_breadcrumb\TitleResolver
Expanded class hierarchy of TitleResolver
1 string reference to 'TitleResolver'
1 service uses TitleResolver
File
- src/
TitleResolver.php, line 17
Namespace
Drupal\easy_breadcrumbView source
class TitleResolver extends ControllerTitleResolver {
/**
* The field storage config storage.
*
* @var \Drupal\Core\Entity\EntityTypeManager
*/
protected $entityTypeManager;
/**
* Breadcrumb config object.
*
* @var \Drupal\Core\Config\Config
*/
protected $config;
/**
* Constructs a new EntityDisplayRebuilder.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity manager.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory service.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory) {
$this->entityTypeManager = $entity_type_manager;
$this->config = $config_factory
->get(EasyBreadcrumbConstants::MODULE_SETTINGS);
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_type.manager'), $container
->get('config.factory'));
}
/**
* {@inheritdoc}
*/
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);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
TitleResolver:: |
protected | property | The argument resolver. | |
TitleResolver:: |
protected | property | Breadcrumb config object. | |
TitleResolver:: |
protected | property | The controller resolver. | |
TitleResolver:: |
protected | property | The field storage config storage. | |
TitleResolver:: |
public static | function | ||
TitleResolver:: |
public | function |
Returns a static or dynamic title for the route. Overrides TitleResolver:: |
|
TitleResolver:: |
public | function |
Constructs a new EntityDisplayRebuilder. Overrides TitleResolver:: |