You are here

function social_event_an_enroll_views_post_render 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_views_post_render()
  2. 8.3 modules/social_features/social_event/modules/social_event_an_enroll/social_event_an_enroll.module \social_event_an_enroll_views_post_render()
  3. 8.4 modules/social_features/social_event/modules/social_event_an_enroll/social_event_an_enroll.module \social_event_an_enroll_views_post_render()
  4. 8.5 modules/social_features/social_event/modules/social_event_an_enroll/social_event_an_enroll.module \social_event_an_enroll_views_post_render()
  5. 8.6 modules/social_features/social_event/modules/social_event_an_enroll/social_event_an_enroll.module \social_event_an_enroll_views_post_render()
  6. 8.7 modules/social_features/social_event/modules/social_event_an_enroll/social_event_an_enroll.module \social_event_an_enroll_views_post_render()
  7. 10.3.x modules/social_features/social_event/modules/social_event_an_enroll/social_event_an_enroll.module \social_event_an_enroll_views_post_render()
  8. 10.0.x modules/social_features/social_event/modules/social_event_an_enroll/social_event_an_enroll.module \social_event_an_enroll_views_post_render()
  9. 10.1.x modules/social_features/social_event/modules/social_event_an_enroll/social_event_an_enroll.module \social_event_an_enroll_views_post_render()
  10. 10.2.x modules/social_features/social_event/modules/social_event_an_enroll/social_event_an_enroll.module \social_event_an_enroll_views_post_render()

Implements hook_views_post_render().

Alter "Event enrollments" views. Add number of anonymous enrollments.

File

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

Code

function social_event_an_enroll_views_post_render(ViewExecutable $view, &$output, CachePluginBase $cache) {
  if ($view
    ->id() == 'event_enrollments' && $view->current_display == 'event_enrollments') {
    if (isset($output['#rows'])) {
      if (!empty($view->args[0])) {
        $nid = $view->args[0];
        $node = Node::load($nid);
        $an_count = \Drupal::service('social_event_an_enroll.service')
          ->enrollmentCount($nid);
        if (social_event_an_enroll_is_enabled($node) && $an_count && $an_count > 0) {

          // Fix counter in block title.
          $view->total_rows += $an_count;

          // Add default avatar image with counter.
          if (empty($output['#rows'])) {
            $output['#rows'][0]['#theme'] = $output['#theme'];
            $output['#rows'][0]['#view'] = $output['#view'];
            $output['#rows'][0]['#grouping_level'] = 0;
            $output['#rows'][0]['#title'] = '';
          }

          // Get default profile image uri.
          $default_image = social_profile_get_default_image();
          if (!empty($default_image['id'])) {
            $file = File::load($default_image['id']);
            $uri = $file
              ->getFileUri();
            $output['#rows'][0]['#rows'][] = [
              '#prefix' => '<div class="avatar">',
              '#theme' => 'image_style',
              '#style_name' => 'social_medium',
              '#uri' => $uri,
              '#suffix' => '<span class="badge badge--pill">' . $an_count . '</span></div>',
            ];
          }
          $output['#attached']['library'][] = 'social_event_an_enroll/event_an_enroll';
        }
      }
    }
  }
}