function opigno_learning_path_system_breadcrumb_alter in Opigno Learning path 3.x
Same name and namespace in other branches
- 8 opigno_learning_path.module \opigno_learning_path_system_breadcrumb_alter()
Implements hook_system_breadcrumb_alter().
File
- ./
opigno_learning_path.module, line 3854 - Contains opigno_learning_path.module.
Code
function opigno_learning_path_system_breadcrumb_alter(Breadcrumb &$breadcrumb, RouteMatchInterface $route_match, array $context) {
// Replace link on user result page.
if ($route_match
->getRouteName() == 'opigno_module.module_result') {
// Get group.
// First try to get group from route.
$group = $route_match
->getParameter('group');
if (empty($group)) {
// Try to get group from context.
$gid = OpignoGroupContext::getCurrentGroupId();
if (!empty($gid)) {
$group = Group::load($gid);
}
}
if ($group instanceof Group) {
$links = $breadcrumb
->getLinks();
// Replace link with link to training homepage.
$links[1] = Link::createFromRoute($group
->label(), 'entity.group.canonical', [
'group' => $group
->id(),
]);
$breadcrumb = new Breadcrumb();
$breadcrumb
->setLinks($links);
}
}
if ($route_match
->getRouteName() == 'entity.group.canonical') {
$link = Link::createFromRoute(t('Catalog'), 'view.opigno_training_catalog.training_catalogue');
$breadcrumb
->addLink($link);
}
if ($route_match
->getRouteName() == 'forum.page') {
$term = $route_match
->getParameter('taxonomy_term');
/** @var Group $group */
$group = LearningPathController::loadGroupByForum($term);
if ($group) {
$breadcrumb
->addLink($group
->toLink());
}
}
}