Skip to content
Snippets Groups Projects

Issue #3336041: Add check if current page is a node page

1 file
+ 9
1
Compare changes
  • Side-by-side
  • Inline
@@ -8,6 +8,7 @@ use Drupal\Core\Link;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Url;
use Drupal\node\NodeInterface;
/**
* Pretty Paths breadcrumb builder.
@@ -40,7 +41,14 @@ class PrettyPathBreadcrumb implements BreadcrumbBuilderInterface {
$title = \Drupal::service('title_resolver')
->getTitle($request, $route_object);
$url = Url::fromUserInput($route_without_facets_query);
// We check if the current page is a node page.
$node = $route_match->getParameter('node');
if ($node instanceof NodeInterface) {
$url = $node->toUrl();
}
else {
$url = Url::fromUserInput($route_without_facets_query);
}
$links[] = Link::createFromRoute($this->t('Home'), '<front>');
$links[] = Link::fromTextAndUrl($title, $url);
return $breadcrumb->setLinks($links);
Loading