/** * {@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; }
/** * {@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; }
/** * {@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; }
/** * 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')); }