In some circumstances, some content types (like Articles) have no designation in the menu, but menu links can get you to a page like /news where news is listed, and then you get to the detail page.

How can I add the node title to the breadcrumb in this circumstance to match consistency with the rest of the site in this scenario?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kevinquillen created an issue. See original summary.

rphair’s picture

There's not enough detail here to understand the circumstance you are talking about, but I suggest this may be a duplicate of issue 2804943 which provides for setting the breadcrumb trail by context (e.g., by content type). The module option "Append current page to breadcrumb" should then allow adding the node title itself.

If that is not what you are talking about here, then please be far more specific about what you are trying to do.

kevinquillen’s picture

I read that thread and really don't want to drop on context and context active trail for this.... also append current page title to breadcrumb did not work if the node was not in the menu.

I wound up having to do this for content types with no menu setting:

use Drupal\Core\Breadcrumb\Breadcrumb;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Link;

/**
 * Implements hook_system_breadcrumb_alter().
 *
 * Append node title to breadcrumb for certain content types that are not in the menu.
 *
 * @param \Drupal\Core\Breadcrumb\Breadcrumb $breadcrumb
 * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
 * @param array $context
 */
function mymodule_breadcrumbs_system_breadcrumb_alter(Breadcrumb &$breadcrumb, RouteMatchInterface $route_match, array $context) {
  $node = \Drupal::request()->get('node');
  $types = ['article', 'faq', 'product'];

  if ($node && in_array($node->bundle(), $types)) {
    $breadcrumb->addLink(Link::createFromRoute($node->getTitle(), '<nolink>'));
  }
}
rphair’s picture

Status: Active » Closed (works as designed)

If a node truly has no association with a menu, then Menu Breadcrumb does not, and should not, generate any breadcrumb for it (unless its active trail is manipulated to make it look like it has that association). When there's no menu association, its designed behaviour is to roll over and let some other breadcrumb builder generate the breadcrumb.

We don't require Context Active Trail / Context UI to use with this module, since the context for a breadcrumb builder is set by its own applies() function: therefore another module can take over where Menu Breadcrumb leaves off. The issue of "context" came up in the issue thread I suggested because the Taxonomy Attachment feature was added to support blogs with taxonomy-based categorisation but couldn't otherwise generate the same kind of breadcrumb trail for uncategorised articles.

Therefore, this module works as designed because, in your example, the articles showing in the /news view would have a taxonomy membership which determines their breadcrumbs, assuming that taxonomy term's menu has its "Taxonomy Attachment" box checked in the module settings... and if you tick the "show title" settings, it shows the node title after those breadcrumbs.

And if they don't, and you're not somehow setting the active trail explicitly (like through "context") to an applicable menu, then Menu Breadcrumb doesn't apply. To talk about how this module would work for all nodes of a certain content type is pointless, since such a breadcrumb builder would be content-type-based, not menu-based.

akalam’s picture

Category: Support request » Feature request
Status: Closed (works as designed) » Active

Reopening.
We think that this can be part of this module to be more flexible, not needing extra modules to have a functional breacrumb.
Maybe an extra setting can be implemented to have the current page title appended even if it has no menu link associated to the breadcrumb to make it look and feel coherent.

akalam’s picture

akalam’s picture

I forgot to save the configuration :p. Also updated the settings and schema.

rphair’s picture

Assigned: kevinquillen » rphair

thanks for contribution... testing together with patch for issue 2977598; will check them both ASAP into dev when done.

RumyanaRuseva’s picture

I don't think the suggested patch solves the original feature request - it only adds the current page to the breadcrumb, but it is not under any parent page such as "news" listing as requested by the reporter.

I recommend using Menu position module for defining menu rules without adding the individual articles to the menu.
It can be used in combination with Token Conditions for even more complex conditions like menu position depending on a taxonomy tag field value.

rphair’s picture

Priority: Normal » Minor
Status: Needs review » Postponed (maintainer needs more info)

Thanks @RumyanaRuseva - I agree with your reasoning. There are a lot of ways of dealing with menu-less articles and all of them, except for taxonomy memberships, are beyond the scope of this breadcrumb builder. Still I would like to leave this open for a while to give @akalam or others a chance to address comment #8.

rphair’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

No further activity in over 3 weeks, so closing this again with the further rationale given in the last 2 comments.