/**
  * {@inheritdoc}
  */
 public function build(RouteMatchInterface $route_match)
 {
     $b = new Breadcrumb();
     /* If registration page use these links */
     $b->setLinks($this->buildBreadcrumb());
     return $b;
 }
 /**
  * {@inheritdoc}
  */
 public function build(RouteMatchInterface $route_match)
 {
     $book_nids = array();
     $breadcrumb = new Breadcrumb();
     $links = array(Link::createFromRoute($this->t('Home'), '<front>'));
     $book = $route_match->getParameter('node')->book;
     $depth = 1;
     // We skip the current node.
     while (!empty($book['p' . ($depth + 1)])) {
         $book_nids[] = $book['p' . $depth];
         $depth++;
     }
     $parent_books = $this->nodeStorage->loadMultiple($book_nids);
     if (count($parent_books) > 0) {
         $depth = 1;
         while (!empty($book['p' . ($depth + 1)])) {
             if (!empty($parent_books[$book['p' . $depth]]) && ($parent_book = $parent_books[$book['p' . $depth]])) {
                 $access = $parent_book->access('view', $this->account, TRUE);
                 $breadcrumb->addCacheableDependency($access);
                 if ($access->isAllowed()) {
                     $breadcrumb->addCacheableDependency($parent_book);
                     $links[] = Link::createFromRoute($parent_book->label(), 'entity.node.canonical', array('node' => $parent_book->id()));
                 }
             }
             $depth++;
         }
     }
     $breadcrumb->setLinks($links);
     $breadcrumb->addCacheContexts(['route.book_navigation']);
     return $breadcrumb;
 }
 /**
  * @inheritdoc
  */
 public function build(RouteMatchInterface $route_match)
 {
     $breadcrumb = new Breadcrumb();
     $geocoder = $route_match->getParameter('service');
     $current_route = $route_match->getRouteName();
     $links = [Link::createFromRoute($this->t('Home'), '<front>'), Link::createFromRoute($this->t('Administration'), 'system.admin'), Link::createFromRoute($this->t('Configuration'), 'system.admin_config'), Link::createFromRoute($this->t('Dmaps'), 'dmaps.settings'), Link::createFromRoute($this->t('Geocoding'), 'dmaps.locations.geocoding_options'), Link::createFromRoute($this->t('Geocoding %service', ['%service' => $geocoder]), $current_route, ['iso' => $route_match->getParameter('iso'), 'service' => $geocoder])];
     $breadcrumb->setLinks($links);
     return $breadcrumb;
 }
 /**
  * {@inheritdoc}
  */
 public function build(RouteMatchInterface $route_match)
 {
     $config = \Drupal::config('uc_cart.settings');
     $text = $config->get('breadcrumb_text');
     $links[] = Link::createFromRoute($this->t('Home'), '<front>');
     $links[] = new Link($text, Url::fromUri('internal:/' . $config->get('breadcrumb_url'), ['absolute' => TRUE]));
     $breadcrumb = new Breadcrumb();
     $breadcrumb->setLinks($links);
     return $breadcrumb;
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function build(RouteMatchInterface $route_match)
 {
     $breadcrumb = new Breadcrumb();
     $breadcrumb->addCacheContexts(['route']);
     $links[] = Link::createFromRoute($this->t('Home'), '<front>');
     $vocabulary = $this->entityManager->getStorage('taxonomy_vocabulary')->load($this->config->get('vocabulary'));
     $breadcrumb->addCacheableDependency($vocabulary);
     $links[] = Link::createFromRoute($vocabulary->label(), 'forum.index');
     return $breadcrumb->setLinks($links);
 }
 /**
  * {@inheritdoc}
  */
 public function build(RouteMatchInterface $route_match)
 {
     $breadcrumb = new Breadcrumb();
     $links[] = Link::createFromRoute(t('Home'), '<front>');
     // Articles page is a view.
     $links[] = Link::createFromRoute(t('Articles'), 'view.articles.page_1');
     $links[] = Link::createFromRoute($this->node->label(), '<none>');
     $breadcrumb->setLinks($links);
     return $breadcrumb;
 }
 /**
  * {@inheritdoc}
  */
 public function build(RouteMatchInterface $route_match)
 {
     $links = array(Link::createFromRoute($this->t('Home'), '<front>'));
     /** @var \Drupal\rng\GroupInterface $group */
     $group = $route_match->getParameter('registration_group');
     if ($event = $group->getEvent()) {
         $links[] = new Link($event->label(), $event->urlInfo());
     }
     $breadcrumb = new Breadcrumb();
     return $breadcrumb->setLinks($links)->addCacheContexts(['route.name']);
 }
 /**
  * {@inheritdoc}
  */
 public function build(RouteMatchInterface $route_match)
 {
     $links = array(Link::createFromRoute($this->t('Home'), '<front>'));
     $registration = $route_match->getParameter('registration');
     if ($event = $registration->getEvent()) {
         $links[] = new Link($event->label(), $event->urlInfo());
     }
     if ('entity.registration.canonical' != $route_match->getRouteName()) {
         $links[] = new Link($registration->label(), $registration->urlInfo());
     }
     $breadcrumb = new Breadcrumb();
     return $breadcrumb->setLinks($links)->addCacheContexts(['route.name']);
 }
 /**
  * {@inheritdoc}
  */
 public function build(RouteMatchInterface $route_match)
 {
     $links = array(Link::createFromRoute($this->t('Home'), '<front>'));
     /** @var \Drupal\rng\RuleComponentInterface $component */
     $component = $route_match->getParameter('rng_rule_component');
     if ($rule = $component->getRule()) {
         if ($event = $rule->getEvent()) {
             $links[] = new Link($event->label(), $event->urlInfo());
         }
     }
     $breadcrumb = new Breadcrumb();
     return $breadcrumb->setLinks($links)->addCacheContexts(['route.name']);
 }
 /**
  * Builds the breadcrumb for a catalog page.
  */
 protected function catalogBreadcrumb($node)
 {
     $links[] = Link::createFromRoute($this->t('Home'), '<front>');
     $links[] = new Link($this->t('Catalog'), Url::fromRoute('view.uc_catalog.page_1'));
     if ($parents = \Drupal::entityManager()->getStorage('taxonomy_term')->loadAllParents($node->taxonomy_catalog->target_id)) {
         $parents = array_reverse($parents);
         foreach ($parents as $parent) {
             $links[] = new Link($parent->label(), Url::fromRoute('view.uc_catalog.page_1', ['term_node_tid_depth' => $parent->id()]));
         }
     }
     $breadcrumb = new Breadcrumb();
     $breadcrumb->setLinks($links);
     return $breadcrumb;
 }
Exemplo n.º 11
0
 /**
  * {@inheritdoc}
  */
 public function build()
 {
     $items = [];
     $current_id = $this->active->getActiveLink('main')->getPluginId();
     while (!empty($current_id)) {
         $current_link = $this->linkManager->createInstance($current_id);
         /** @var MenuLinkContent $current_link */
         $link = new Link($current_link->getTitle(), $current_link->getUrlObject());
         $items[] = $link;
         $current_id = $current_link->getParent();
     }
     $breadcrumbs = new Breadcrumb();
     $breadcrumbs->setLinks(array_reverse($items));
     return $breadcrumbs->toRenderable();
 }
Exemplo n.º 12
0
  /**
   * Tests multiple breadcrumb builders of which one returns NULL.
   */
  public function testBuildWithOneNotApplyingBuilders() {
    $builder1 = $this->getMock('Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface');
    $builder1->expects($this->once())
      ->method('applies')
      ->will($this->returnValue(FALSE));
    $builder1->expects($this->never())
      ->method('build');

    $builder2 = $this->getMock('Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface');
    $links2 = ['<a href="/example2">Test2</a>'];
    $this->breadcrumb->setLinks($links2);
    $this->breadcrumb->addCacheContexts(['baz'])->addCacheTags(['qux']);
    $builder2->expects($this->once())
      ->method('applies')
      ->will($this->returnValue(TRUE));
    $builder2->expects($this->once())
      ->method('build')
      ->willReturn($this->breadcrumb);

    $route_match = $this->getMock('Drupal\Core\Routing\RouteMatchInterface');

    $this->moduleHandler->expects($this->once())
      ->method('alter')
      ->with('system_breadcrumb', $this->breadcrumb, $route_match, array('builder' => $builder2));

    $this->breadcrumbManager->addBuilder($builder1, 10);
    $this->breadcrumbManager->addBuilder($builder2, 0);

    $breadcrumb = $this->breadcrumbManager->build($route_match);
    $this->assertEquals($links2, $breadcrumb->getLinks());
    $this->assertEquals(['baz'], $breadcrumb->getCacheContexts());
    $this->assertEquals(['qux'], $breadcrumb->getCacheTags());
    $this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge());
  }
 /**
  * {@inheritdoc}
  */
 public function build(RouteMatchInterface $route_match)
 {
     $breadcrumb = new Breadcrumb();
     $node = $route_match->getParameter('node');
     // Homepage link.
     $links[] = Link::createFromRoute($this->t('Home'), '<front>');
     // First assigned tag.
     if (!empty($node->field_tags[0]->target_id)) {
         $tid = $node->field_tags[0]->target_id;
         $term_name = Term::load($tid)->get('name')->value;
         $links[] = Link::createFromRoute($term_name, 'entity.taxonomy_term.canonical', ['taxonomy_term' => $tid]);
     }
     // The node itself.
     $links[] = Link::fromTextAndUrl($node->getTitle(), Url::fromRoute('<current>'));
     $breadcrumb->addCacheContexts(['route']);
     return $breadcrumb->setLinks($links);
 }
Exemplo n.º 14
0
 /**
  * {@inheritdoc}
  */
 public function build(RouteMatchInterface $route_match)
 {
     $breadcrumb = new Breadcrumb();
     $breadcrumb->addLink(Link::createFromRoute($this->t('Home'), '<front>'));
     $term = $route_match->getParameter('taxonomy_term');
     // Breadcrumb needs to have terms cacheable metadata as a cacheable
     // dependency even though it is not shown in the breadcrumb because e.g. its
     // parent might have changed.
     $breadcrumb->addCacheableDependency($term);
     // @todo This overrides any other possible breadcrumb and is a pure
     //   hard-coded presumption. Make this behavior configurable per
     //   vocabulary or term.
     $parents = $this->termStorage->loadAllParents($term->id());
     // Remove current term being accessed.
     array_shift($parents);
     foreach (array_reverse($parents) as $term) {
         $term = $this->entityManager->getTranslationFromContext($term);
         $breadcrumb->addCacheableDependency($term);
         $breadcrumb->addLink(Link::createFromRoute($term->getName(), 'entity.taxonomy_term.canonical', array('taxonomy_term' => $term->id())));
     }
     // This breadcrumb builder is based on a route parameter, and hence it
     // depends on the 'route' cache context.
     $breadcrumb->addCacheContexts(['route']);
     return $breadcrumb;
 }
Exemplo n.º 15
0
 /**
  * {@inheritdoc}
  */
 public function build(RouteMatchInterface $route_match)
 {
     $breadcrumb = new Breadcrumb();
     $breadcrumb->addLink(Link::createFromRoute($this->t('Home'), '<front>'));
     $breadcrumb->addCacheContexts(['route']);
     /** @var JobItemInterface $job_item */
     $job_item = $route_match->getParameter('tmgmt_job_item');
     $breadcrumb->addCacheableDependency($job_item);
     // Add links to administration, translation, job overview and job to the
     // breadcrumb.
     $breadcrumb->addLink(Link::createFromRoute($this->t('Administration'), 'system.admin'));
     $breadcrumb->addLink(Link::createFromRoute($this->t('Translation'), 'tmgmt.admin_tmgmt'));
     $breadcrumb->addLink(Link::createFromRoute($this->t('Job overview'), 'view.tmgmt_job_overview.page_1'));
     $breadcrumb->addLink(Link::createFromRoute($job_item->getJob()->label(), 'entity.tmgmt_job.canonical', array('tmgmt_job' => $job_item->getJobId())));
     return $breadcrumb;
 }
Exemplo n.º 16
0
 /**
  * {@inheritdoc}
  */
 public function build(RouteMatchInterface $route_match)
 {
     $breadcrumb = new Breadcrumb();
     $links = array();
     $contact_form = $route_match->getParameter('contact_form');
     $label = $contact_form->label();
     $id = $contact_form->id();
     $links[] = Link::createFromRoute($this->t('Home'), '<front>');
     if (in_array($id, ['volunteer_application', 'mentor_application'])) {
         $links[] = Link::createFromRoute($this->t('Community'), 'entity.node.canonical', array('node' => 15));
     }
     if (in_array($id, ['sponsorship_request'])) {
         $links[] = Link::createFromRoute($this->t('Sponsors'), 'entity.node.canonical', array('node' => 19));
     }
     if (in_array($id, ['contact_us'])) {
         $links[] = Link::createFromRoute($this->t('About'), 'entity.node.canonical', array('node' => 1));
     }
     $links[] = Link::createFromRoute($label, 'entity.contact_form.canonical', array('contact_form' => $id));
     $breadcrumb->setLinks($links);
     $breadcrumb->addCacheContexts(['url']);
     return $breadcrumb;
 }
 /**
  * {@inheritdoc}
  */
 public function build(RouteMatchInterface $route_match)
 {
     $breadcrumb = new Breadcrumb();
     $breadcrumb->setCacheContexts(['route']);
     $breadcrumb->addLink(Link::createFromRoute($this->t('Home'), '<front>'));
     $entity = $route_match->getParameter('entity');
     $breadcrumb->addLink(new Link($entity->label(), $entity->urlInfo()));
     $breadcrumb->addCacheableDependency($entity);
     if (($pid = $route_match->getParameter('pid')) && ($comment = $this->storage->load($pid))) {
         /** @var \Drupal\comment\CommentInterface $comment */
         $breadcrumb->addCacheableDependency($comment);
         // Display link to parent comment.
         // @todo Clean-up permalink in https://www.drupal.org/node/2198041
         $breadcrumb->addLink(new Link($comment->getSubject(), $comment->urlInfo()));
     }
     return $breadcrumb;
 }
 /**
  * {@inheritdoc}
  */
 public function build(RouteMatchInterface $route_match)
 {
     $breadcrumb = new Breadcrumb();
     $breadcrumb->addLink(Link::createFromRoute($this->t('Home'), '<front>'));
     $breadcrumb->addCacheContexts(['route']);
     // Add links to administration, and translation to the breadcrumb.
     if (\Drupal::config('tmgmt_local.settings')->get('use_admin_theme') || strpos($route_match->getRouteObject()->getPath(), '/manage-translate') === 0) {
         $breadcrumb->addLink(Link::createFromRoute($this->t('Administration'), 'system.admin'));
         $breadcrumb->addLink(Link::createFromRoute($this->t('Translation'), 'tmgmt.admin_tmgmt'));
     }
     if ($route_match->getParameter('tmgmt_local_task') instanceof LocalTaskInterface || $route_match->getParameter('tmgmt_local_task_item') instanceof LocalTaskItemInterface) {
         $breadcrumb->addLink(Link::createFromRoute($this->t('Local Tasks'), 'view.tmgmt_local_task_overview.unassigned'));
         if ($route_match->getParameter('tmgmt_local_task_item') instanceof LocalTaskItemInterface) {
             /** @var LocalTaskItemInterface $local_task_item */
             $local_task_item = $route_match->getParameter('tmgmt_local_task_item');
             $breadcrumb->addCacheableDependency($local_task_item);
             $breadcrumb->addLink(Link::createFromRoute($local_task_item->getTask()->label(), 'entity.tmgmt_local_task.canonical', array('tmgmt_local_task' => $local_task_item->getTask()->id())));
         }
     }
     return $breadcrumb;
 }
  /**
   * {@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 = db_query("SELECT uid FROM {file_managed} WHERE fid = :fid", array(':fid' => $fid))->fetchField();
      $account = \Drupal\user\Entity\User::load($uid);
      $username = $account->getUsername();
      $breadcrumb->addLink(Link::createFromRoute($this->t('Images by :name', array(':name' => $username)), 'photos.user.images', ['user' => $uid]));
      // Album.
      $pid = db_query("SELECT pid FROM {photos_image} WHERE fid = :fid", array(':fid' => $fid))->fetchField();
      $node = \Drupal\node\Entity\Node::load($pid);
      $breadcrumb->addLink(Link::createFromRoute($node->getTitle(), 'photos.album', ['node' => $pid]));
      // Image.
      // @todo image title?
    }

    return $breadcrumb;
  }
Exemplo n.º 20
0
 /**
  * @covers ::setLinks
  * @expectedException \LogicException
  * @expectedExceptionMessage Once breadcrumb links are set, only additional breadcrumb links can be added.
  */
 public function testSetLinks()
 {
     $breadcrumb = new Breadcrumb();
     $breadcrumb->setLinks([new Link('Home', Url::fromRoute('<front>'))]);
     $breadcrumb->setLinks([new Link('None', Url::fromRoute('<none>'))]);
 }
 /**
  * {@inheritdoc}
  */
 public function build(RouteMatchInterface $route_match)
 {
     $breadcrumb = new Breadcrumb();
     $links = array();
     // General path-based breadcrumbs. Use the actual request path, prior to
     // resolving path aliases, so the breadcrumb can be defined by simply
     // creating a hierarchy of path aliases.
     $path = trim($this->context->getPathInfo(), '/');
     $path_elements = explode('/', $path);
     $exclude = array();
     // Don't show a link to the front-page path.
     $front = $this->config->get('page.front');
     $exclude[$front] = TRUE;
     // /user is just a redirect, so skip it.
     // @todo Find a better way to deal with /user.
     $exclude['/user'] = TRUE;
     // Because this breadcrumb builder is entirely path-based, vary by the
     // 'url.path' cache context.
     $breadcrumb->addCacheContexts(['url.path']);
     while (count($path_elements) > 1) {
         array_pop($path_elements);
         // Copy the path elements for up-casting.
         $route_request = $this->getRequestForPath('/' . implode('/', $path_elements), $exclude);
         if ($route_request) {
             $route_match = RouteMatch::createFromRequest($route_request);
             $access = $this->accessManager->check($route_match, $this->currentUser, NULL, TRUE);
             // The set of breadcrumb links depends on the access result, so merge
             // the access result's cacheability metadata.
             $breadcrumb = $breadcrumb->addCacheableDependency($access);
             if ($access->isAllowed()) {
                 $title = $this->titleResolver->getTitle($route_request, $route_match->getRouteObject());
                 if (!isset($title)) {
                     // Fallback to using the raw path component as the title if the
                     // route is missing a _title or _title_callback attribute.
                     $title = str_replace(array('-', '_'), ' ', Unicode::ucfirst(end($path_elements)));
                 }
                 $url = Url::fromRouteMatch($route_match);
                 $links[] = new Link($title, $url);
             }
         }
     }
     if ($path && '/' . $path != $front) {
         // Add the Home link, except for the front page.
         $links[] = Link::createFromRoute($this->t('Home'), '<front>');
     }
     return $breadcrumb->setLinks(array_reverse($links));
 }
 /**
  * {@inheritdoc}
  */
 public function build(RouteMatchInterface $route_match)
 {
     $breadcrumb = new Breadcrumb();
     $breadcrumb->addCacheContexts(['route']);
     // Add all parent forums to breadcrumbs.
     /** @var Node $node */
     $node = $route_match->getParameter('node');
     $breadcrumb->addCacheableDependency($node);
     // Add all parent forums to breadcrumbs.
     /** @var \Drupal\Taxonomy\TermInterface $term */
     $term = !empty($node->field_channel) ? $node->field_channel->entity : '';
     $links = [];
     if ($term) {
         $breadcrumb->addCacheableDependency($term);
         $channels = $this->termStorage->loadAllParents($term->id());
         foreach (array_reverse($channels) as $term) {
             $term = $this->entityManager->getTranslationFromContext($term);
             $breadcrumb->addCacheableDependency($term);
             $links[] = Link::createFromRoute($term->getName(), 'entity.taxonomy_term.canonical', array('taxonomy_term' => $term->id()));
         }
     }
     if (!$links || '/' . $links[0]->getUrl()->getInternalPath() != $this->configFactory->get('system.site')->get('page.front')) {
         array_unshift($links, Link::createFromRoute($this->t('Home'), '<front>'));
     }
     return $breadcrumb->setLinks($links);
 }
Exemplo n.º 23
0
/**
 * Perform alterations to the breadcrumb built by the BreadcrumbManager.
 *
 * @param \Drupal\Core\Breadcrumb\Breadcrumb $breadcrumb
 *   A breadcrumb object returned by BreadcrumbBuilderInterface::build().
 * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
 *   The current route match.
 * @param array $context
 *   May include the following key:
 *   - builder: the instance of
 *     \Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface that constructed this
 *     breadcrumb, or NULL if no builder acted based on the current attributes.
 *
 * @ingroup menu
 */
function hook_system_breadcrumb_alter(\Drupal\Core\Breadcrumb\Breadcrumb &$breadcrumb, \Drupal\Core\Routing\RouteMatchInterface $route_match, array $context)
{
    // Add an item to the end of the breadcrumb.
    $breadcrumb->addLink(\Drupal\Core\Link::createFromRoute(t('Text'), 'example_route_name'));
}