You are here

function opigno_learning_path_preprocess_html in Opigno Learning path 3.x

Same name and namespace in other branches
  1. 8 opigno_learning_path.module \opigno_learning_path_preprocess_html()

Implements hook_preprocess_html().

File

./opigno_learning_path.module, line 366
Contains opigno_learning_path.module.

Code

function opigno_learning_path_preprocess_html(&$variables) {

  // Remove admin bar for item form (included in iframe).
  if (\Drupal::routeMatch()
    ->getRouteName() == 'opigno_learning_path.manager.get_item_form') {
    unset($variables['page_top']);
  }
  $route = \Drupal::routeMatch()
    ->getRouteName();
  $account = \Drupal::currentUser();
  $group = \Drupal::routeMatch()
    ->getParameter('group');

  // Get join form.
  if ($route == 'entity.group.canonical' && $group) {
    $form_builder = \Drupal::service('opigno_learning_path.join_form');
    $form = $form_builder
      ->getForm($group);
    if ($group
      ->hasField('field_learning_path_visibility')) {
      $visibility = $group->field_learning_path_visibility->value;
      if ($visibility === 'semiprivate' && !$account
        ->isAuthenticated() || !$group
        ->hasPermission('join group', $account)) {
        return;
      }
    }
    if (!$group
      ->getMember($account)) {
      $variables['join_group_form'] = [
        '#theme' => 'opigno_learning_path_join_group_form_overlay',
        '#attributes' => [
          'id' => 'join-group-form-overlay',
          'class' => [
            'modal',
            'fade',
          ],
        ],
        [
          '#type' => 'container',
          'form' => $form,
        ],
      ];
    }
  }
  if (opigno_learning_path_is_lp_route()) {
    $variables['attributes']['class'][] = 'admin-learning-path';
  }
}