class PhotosBreadcrumbBuilder in Album Photos 8.4
Photos breadcrumb builder.
Hierarchy
- class \Drupal\photos\PhotosBreadcrumbBuilder implements BreadcrumbBuilderInterface uses StringTranslationTrait
Expanded class hierarchy of PhotosBreadcrumbBuilder
1 string reference to 'PhotosBreadcrumbBuilder'
1 service uses PhotosBreadcrumbBuilder
File
- src/
PhotosBreadcrumbBuilder.php, line 17
Namespace
Drupal\photosView source
class PhotosBreadcrumbBuilder implements BreadcrumbBuilderInterface {
use StringTranslationTrait;
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $connection;
/**
* The router request context.
*
* @var \Drupal\Core\Routing\RequestContext
*/
protected $context;
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs the PathBasedBreadcrumbBuilder.
*
* @param \Drupal\Core\Database\Connection $connection
* The database connection.
* @param \Drupal\Core\Routing\RequestContext $context
* The router request context.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager
* The entity manager service.
*/
public function __construct(Connection $connection, RequestContext $context, EntityTypeManagerInterface $entity_manager) {
$this->connection = $connection;
$this->context = $context;
$this->entityTypeManager = $entity_manager;
}
/**
* {@inheritdoc}
*/
public function applies(RouteMatchInterface $route_match) {
// Check if image page.
$fid = $route_match
->getParameter('file');
if ($fid) {
$path = trim($this->context
->getPathInfo(), '/');
$path_elements = explode('/', $path);
return $path_elements[0] == 'photos' && $path_elements[1] == 'image';
}
}
/**
* {@inheritdoc}
*/
public function build(RouteMatchInterface $route_match) {
$breadcrumb = new Breadcrumb();
$breadcrumb
->addCacheContexts([
'route',
]);
// Home.
$breadcrumb
->addLink(Link::createFromRoute($this
->t('Home'), '<front>'));
$fid = $route_match
->getParameter('file');
if ($fid) {
// Recent images.
$breadcrumb
->addLink(Link::createFromRoute($this
->t('Images'), 'photos.image.recent'));
// Images by User.
$uid = $this->connection
->query("SELECT uid FROM {file_managed} WHERE fid = :fid", [
':fid' => $fid,
])
->fetchField();
$account = $this->entityTypeManager
->getStorage('user')
->load($uid);
$username = $account
->getDisplayName();
$breadcrumb
->addLink(Link::createFromRoute($this
->t('Images by :name', [
':name' => $username,
]), 'photos.user.images', [
'user' => $uid,
]));
// Album.
$pid = $this->connection
->query("SELECT pid FROM {photos_image} WHERE fid = :fid", [
':fid' => $fid,
])
->fetchField();
$node = $this->entityTypeManager
->getStorage('node')
->load($pid);
$breadcrumb
->addLink(Link::createFromRoute($node
->getTitle(), 'photos.album', [
'node' => $pid,
]));
}
return $breadcrumb;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhotosBreadcrumbBuilder:: |
protected | property | The database connection. | |
PhotosBreadcrumbBuilder:: |
protected | property | The router request context. | |
PhotosBreadcrumbBuilder:: |
protected | property | The entity manager. | |
PhotosBreadcrumbBuilder:: |
public | function |
Whether this breadcrumb builder should be used to build the breadcrumb. Overrides BreadcrumbBuilderInterface:: |
|
PhotosBreadcrumbBuilder:: |
public | function |
Builds the breadcrumb. Overrides BreadcrumbBuilderInterface:: |
|
PhotosBreadcrumbBuilder:: |
public | function | Constructs the PathBasedBreadcrumbBuilder. | |
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. |