You are here

function social_group_views_post_render in Open Social 8

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_group/social_group.module \social_group_views_post_render()
  2. 8.2 modules/social_features/social_group/social_group.module \social_group_views_post_render()
  3. 8.3 modules/social_features/social_group/social_group.module \social_group_views_post_render()
  4. 8.4 modules/social_features/social_group/social_group.module \social_group_views_post_render()
  5. 8.5 modules/social_features/social_group/social_group.module \social_group_views_post_render()
  6. 8.6 modules/social_features/social_group/social_group.module \social_group_views_post_render()
  7. 8.7 modules/social_features/social_group/social_group.module \social_group_views_post_render()
  8. 8.8 modules/social_features/social_group/social_group.module \social_group_views_post_render()
  9. 10.3.x modules/social_features/social_group/social_group.module \social_group_views_post_render()
  10. 10.0.x modules/social_features/social_group/social_group.module \social_group_views_post_render()
  11. 10.1.x modules/social_features/social_group/social_group.module \social_group_views_post_render()
  12. 10.2.x modules/social_features/social_group/social_group.module \social_group_views_post_render()

Implements hook_views_post_render().

Alter "Group Members" views. Replace user IDs with profile teasers.

File

modules/social_features/social_group/social_group.module, line 775
The Social group module.

Code

function social_group_views_post_render(ViewExecutable $view, &$output, CachePluginBase $cache) {
  if ($view
    ->id() == 'group_members') {
    if (!empty($output['#rows'][0]['#rows'])) {
      foreach ($output['#rows'][0]['#rows'] as $key => $row) {

        // Get Group membership content entity.
        $group_content = $row['#group_content'];

        // Get Profile.
        $user_profile = _social_group_get_member_profile($group_content);
        if ($user_profile) {

          // Use teaser for page and small_teaser for block.
          $view_mode = $view->current_display === 'block_newest_members' ? 'small_teaser' : 'teaser';

          // Replace output with profile teaser.
          $output['#rows'][0]['#rows'][$key] = \Drupal::entityTypeManager()
            ->getViewBuilder('profile')
            ->view($user_profile, $view_mode);
        }
        else {

          // Remove output if user don't have profile (admin).
          unset($output['#rows'][0]['#rows'][$key]);
        }
      }
    }
  }
}