Drupal has a powerful menu system, but most of the content on a typical Drupal website doesn't end up in the menu navigation. Articles, blog posts, events, you name it. Most content is linked to from views, not directly from a menu. So how do we make it easy for users to know where they are in the hierarchy of the site if they are looking at content that isn't in a menu?
Let's look at an example. On our website, if you navigate to the Blog page, the Blog link in the main menu is highlighted. Drupal can see that the current page is in a menu, so it sets the active trail, a CSS class gets added to the menu item to mark it as active, and everything just works. Thanks, Drupal!
But what about individual blog posts, like this very page? We're not going to put every post in the main menu, so Drupal has no idea what the active menu item should be. Our poor user is now lost. Looking up in the menu, the user doesn't know which section of the site they've ended up in. Note that we've fixed this on our site, so you'll see that the blog menu item is active on this page! Read on to learn how...
The good old days
In Drupal 7, we would just use the Context module for this. In our case, we'd create a context to say that on Article nodes, the active menu item should be Blog. Problem solved!
But the current version of the Context module for Drupal 8 is much more limited, and no longer includes most reactions. Notably absent are Menu and Breadcrumbs, which help users keep track of where on the site they are.
A Drupal 8 solution
Context in Drupal 8 may not have many reactions, but it's easy to extend with new ones. So we did! The Context Active Trail module gives us active trail functionality for Context in Drupal 8, just like we had in Drupal 7. Never let your users get lost again!
As a bonus, Context Active Trail can also add breadcrumbs. Drupal 8 by default sets breadcrumbs based on URLs, but that's not too useful if your blog posts have URLs like /2016/09/my-post. With Context Active Trail, the breadcrumb will be set based on the parent menu items from the active trail.
What do you think?
We've already used this module on several sites we're building, and we think it's ready for the world to see. There's even already a feature request! We'd love to hear your feedback.
- Should we have more settings for breadcrumbs, like "Don't show home page in breadcrumbs"? Or should we let other modules handle that? I have a patch for better integration with the Menu Breadcrumbs, but I could also add some simple settings.
- Should this functionality come with Context? Or is it better in its own module?
- Any features you want added?