Menu active trail

A menu trail is a list (array) of menu link plugins that are parents of a menu link. For the active trail, that specific menu link represents the current route (if there is a menu link for that route).

The Drupal 8 menu system also has a service that can be used to determine the active trail of the current route if used by a menu link. Passing a menu name to look inside of the MenuActiveTrail service returns an array of plugin IDs of the parents all the way up to the menu root, if the current route is in fact an active link. The following is a method that can be used to check that--getActiveLink().

Get Drupal 8 Module Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.