You are here

function social_event_an_enroll_preprocess_page_hero_data in Open Social 8.4

Same name and namespace in other branches
  1. 8.3 modules/social_features/social_event/modules/social_event_an_enroll/social_event_an_enroll.module \social_event_an_enroll_preprocess_page_hero_data()
  2. 8.5 modules/social_features/social_event/modules/social_event_an_enroll/social_event_an_enroll.module \social_event_an_enroll_preprocess_page_hero_data()

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 65
The Social event AN enroll module.

Code

function social_event_an_enroll_preprocess_page_hero_data(array &$variables) {
  $account = \Drupal::currentUser();
  if ($account
    ->isAnonymous() && !empty($variables['event_enrollment'])) {
    $node = $variables['node'];
    if ($node instanceof Node && 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']);
      }
    }
  }
}