public function PhotosBreadcrumbBuilder::build in Album Photos 8.4
Builds the breadcrumb.
Parameters
\Drupal\Core\Routing\RouteMatchInterface $route_match: The current route match.
Return value
\Drupal\Core\Breadcrumb\Breadcrumb A breadcrumb.
Overrides BreadcrumbBuilderInterface::build
File
- src/
PhotosBreadcrumbBuilder.php, line 73
Class
- PhotosBreadcrumbBuilder
- Photos breadcrumb builder.
Namespace
Drupal\photosCode
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;
}