You are here

function opigno_class_preprocess_page in Opigno class 8

Same name and namespace in other branches
  1. 3.x opigno_class.module \opigno_class_preprocess_page()

Implements hook_preprocess_page().

File

./opigno_class.module, line 40
Contains opigno_class.module.

Code

function opigno_class_preprocess_page(&$variables) {
  $route = \Drupal::routeMatch();
  $route_name = $route
    ->getRouteName();

  /** @var \Drupal\group\Entity\GroupInterface $group */
  $group = $route
    ->getParameter('group');
  if ($group && !is_object($group)) {
    $group = Group::load($group);
  }
  if ($group === NULL || $group
    ->bundle() !== 'opigno_class') {
    return;
  }
  if ($route_name === 'entity.group.canonical') {
    $user = \Drupal::currentUser();
    if ($user
      ->hasPermission('manage group members in any group') || $group
      ->hasPermission('administer members', $user)) {

      // If user can manage group members, add link to the members overview.
      $url = Url::fromRoute('opigno_learning_path.membership.overview', [
        'group' => $group
          ->id(),
      ]);
      $link = Link::fromTextAndUrl(t('Manage members'), $url)
        ->toRenderable();
      array_unshift($variables['page']['content'], $link);
    }
  }
}