You are here

function opigno_learning_path_system_breadcrumb_alter in Opigno Learning path 8

Same name and namespace in other branches
  1. 3.x opigno_learning_path.module \opigno_learning_path_system_breadcrumb_alter()

Implements hook_system_breadcrumb_alter().

File

./opigno_learning_path.module, line 3958
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);
    }
  }
}