You are here

function template_preprocess_opigno_calendar_event in Opigno calendar event 3.x

File

./opigno_calendar_event.module, line 236
Main file for the "Calendar event" module.

Code

function template_preprocess_opigno_calendar_event(&$variables) {

  // Helpful $content variable for templates.
  $variables['content'] = [];

  //  $variables['#attached']['library'][] = 'core/jquery.form';
  //  $variables['#attached']['library'][] = 'core/drupal.dialog.ajax';
  foreach (\Drupal\Core\Render\Element::children($variables['elements']) as $key) {
    $variables['content'][$key] = $variables['elements'][$key];
  }
  $event = $variables['elements']['#opigno_calendar_event'];
  $variables['event_type'] = t('Event');
  $user = \Drupal\user\Entity\User::load(\Drupal::currentUser()
    ->id());
  $check = $event
    ->access('update', $user);
  if ($check) {
    $edit_url = URL::fromRoute('entity.opigno_calendar_event.edit_form', [
      'opigno_calendar_event' => $event
        ->id(),
    ]);

    // TODO. Make edit in modal.
    $edit_url
      ->setOptions([
      'attributes' => [
        'target' => '_blank',
      ],
    ]);
    $variables['edit_link'] = Link::fromTextAndUrl(t('Edit'), $edit_url)
      ->toString();
  }
  if (!empty($event->field_meeting)) {
    $variables['event_type'] = t('Live meeting');
    $link = Link::createFromRoute(t('Join the meeting'), 'opigno_moxtra.meeting', [
      'opigno_moxtra_meeting' => $event->field_meeting->target_id,
    ]);
    $variables['event_link'] = $link
      ->toRenderable();
    $link = Link::createFromRoute(t('Join'), 'opigno_moxtra.meeting', [
      'opigno_moxtra_meeting' => $event->field_meeting->target_id,
    ]);
    $variables['mobile_link'] = $link
      ->toRenderable();
    $entity = \Drupal::entityTypeManager()
      ->getStorage('opigno_moxtra_meeting')
      ->load($event->field_meeting->target_id);
    if ($entity
      ->getTrainingId()) {
      $link = Link::createFromRoute(t('See the training'), 'entity.group.canonical', [
        'group' => $entity
          ->getTrainingId(),
      ]);
      $variables['training_link'] = $link
        ->toRenderable();
    }
    else {
      $variables['training_link'] = '';
    }
  }
  if (!empty($event->field_ilt)) {
    $variables['event_type'] = t('ILT');
    $link = Link::createFromRoute(t('Some address'), 'entity.opigno_ilt.canonical', [
      'opigno_ilt' => $event->field_ilt->target_id,
    ]);
    $variables['event_link'] = $link
      ->toRenderable();
    $ilt_id = $event->field_ilt->target_id;
    $entity = \Drupal::entityTypeManager()
      ->getStorage('opigno_ilt')
      ->load($ilt_id);
    $place = $entity->place;
    $prepared_view = $place
      ->view([
      'type' => 'simple_gmap',
      'settings' => [
        'include_map' => FALSE,
        'include_link' => TRUE,
        'link_text' => 'use_address',
      ],
    ]);
    $prepared_view['#label_display'] = 0;
    $variables['event_link'] = \Drupal::service('renderer')
      ->render($prepared_view);
    if ($entity
      ->getTrainingId()) {
      $link = Link::createFromRoute(t('See the training'), 'entity.group.canonical', [
        'group' => $entity
          ->getTrainingId(),
      ]);
      $variables['training_link'] = $link
        ->toRenderable();
    }
    else {
      $variables['training_link'] = '';
    }
  }
}