Drupal 8 breadcrumb functions (menu_get_active_trail, and menu_link_get_preferred ...)

Submitted by editor on Mon, 09/26/2016 - 10:57

How to breadcrumb functions in drupal 8 ?
menu_get_active_trail(), menu_set_active_trail(), and menu_link_get_preferred()
menu_get_active_breadcrumb () ....

Those functions [ menu_set_active_item(), menu_set_active_trail(), menu_get_active_trail(), menu_link_get_preferred() ] are removed on D8 and replaces with drupal 8 service. You can use following example to get data and to edit.

Example :

$menu_name = NULL;
$active_trail = \Drupal::service('menu.active_trail');
//To get item ids
$ids = $active_trail->getActiveTrailIds($menu_name);
//To get links
$link = $active_trail->getActiveLink($menu_name);

//To get menu name
$menu_name = $link->getMenuName();


Add new comment