Hi @sandip27, I am attaching the code how it will work. In my past experience...

Contribution Date
Technology
Contribution Project
Contribution Details

Hi @sandip27, I am attaching the code how it will work. In my past experience i have done the same thing. Where i created different file for each content type. please check below code once you will get your answer.

class JobsCampaignCustomBreadcrumb implements BreadcrumbBuilderInterface { use StringTranslationTrait; /** * The entity type manager. * * @var \Drupal\Core\Config\ConfigFactoryInterface */ protected $configFactory; /** * The entity type manager. * * @var \Drupal\Core\Path\CurrentPathStack */ protected $currentPath; /** * The entity type manager. * * @var \Drupal\path_alias\AliasManagerInterface */ protected $pathAlias; /** * Constructs the SpecialPagesCustomBreadcrumb. * * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The config factory service. * @param \Drupal\Core\Path\CurrentPathStack $current_path * The current path service. * @param \Drupal\path_alias\AliasManagerInterface $path_alias * The path alias service. */ public function __construct(ConfigFactoryInterface $config_factory, CurrentPathStack $current_path, AliasManagerInterface $path_alias) { $this->configFactory = $config_factory; $this->currentPath = $current_path; $this->pathAlias = $path_alias; } /** * {@inheritdoc} */ public function applies(RouteMatchInterface $route_match) { // Breadcrumb for 'jobs-campaign' pages. if ($route_match->getRouteName() == 'entity.node.canonical') { $node = $route_match->getParameter('node'); if ($node->bundle() == 'jobs_campaign' && $this->checkForIgnoredPaths()) { return TRUE; } } return FALSE; } /** * {@inheritdoc} */ public function build(RouteMatchInterface $route_match) { $breadcrumb = new Breadcrumb(); $node = $route_match->getParameter('node'); $breadcrumb->addCacheableDependency($node); $breadcrumb->addLink(Link::createFromRoute($this->t('Home', [], ['context' => 'breadcrumb']), '<front>')); $breadcrumb->addLink(Link::fromTextAndUrl($this->t('%title', ['%title' => $node->label()]), Url::fromRoute('<none>'))); $breadcrumb->addCacheContexts(['route', 'url.path']); return $breadcrumb; }
Contribution Author
Files count
0
Patches count
0