You are here

function social_event_an_enroll_preprocess_node in Open Social 8.8

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_event/modules/social_event_an_enroll/social_event_an_enroll.module \social_event_an_enroll_preprocess_node()
  2. 8.6 modules/social_features/social_event/modules/social_event_an_enroll/social_event_an_enroll.module \social_event_an_enroll_preprocess_node()
  3. 8.7 modules/social_features/social_event/modules/social_event_an_enroll/social_event_an_enroll.module \social_event_an_enroll_preprocess_node()
  4. 10.3.x modules/social_features/social_event/modules/social_event_an_enroll/social_event_an_enroll.module \social_event_an_enroll_preprocess_node()
  5. 10.0.x modules/social_features/social_event/modules/social_event_an_enroll/social_event_an_enroll.module \social_event_an_enroll_preprocess_node()
  6. 10.1.x modules/social_features/social_event/modules/social_event_an_enroll/social_event_an_enroll.module \social_event_an_enroll_preprocess_node()
  7. 10.2.x modules/social_features/social_event/modules/social_event_an_enroll/social_event_an_enroll.module \social_event_an_enroll_preprocess_node()

Override variables for the social page hero data.

File

modules/social_features/social_event/modules/social_event_an_enroll/social_event_an_enroll.module, line 97
The Social event AN enroll module.

Code

function social_event_an_enroll_preprocess_node(array &$variables) {
  $account = \Drupal::currentUser();
  if ($account
    ->isAnonymous() && !empty($variables['event_enrollment'])) {
    $node = $variables['node'];
    if ($variables['view_mode'] === 'hero' && social_event_an_enroll_is_enabled($node)) {
      $form = \Drupal::formBuilder()
        ->getForm('Drupal\\social_event_an_enroll\\Form\\EventAnEnrollActionForm', $node);
      $variables['event_enrollment'] = [
        'enroll_action_form' => $form,
      ];
      $an_enroll_routes = [
        'social_event_an_enroll.enroll_dialog',
        'social_event_an_enroll.enroll_form',
      ];
      if (in_array(\Drupal::routeMatch()
        ->getRouteName(), $an_enroll_routes)) {
        unset($variables['event_enrollment']);
      }

      // Add caching context to anonymous users.
      // This is custom context. We added it in order to vary page cache
      // of routes given in $an_enroll_routes.
      $variables['#cache']['contexts'][] = 'event_an_enroll_route';
    }
  }
}