You are here

function social_group_invite_preprocess_views_view_field in Open Social 8.9

Same name and namespace in other branches
  1. 10.3.x modules/social_features/social_group/modules/social_group_invite/social_group_invite.module \social_group_invite_preprocess_views_view_field()
  2. 10.0.x modules/social_features/social_group/modules/social_group_invite/social_group_invite.module \social_group_invite_preprocess_views_view_field()
  3. 10.1.x modules/social_features/social_group/modules/social_group_invite/social_group_invite.module \social_group_invite_preprocess_views_view_field()
  4. 10.2.x modules/social_features/social_group/modules/social_group_invite/social_group_invite.module \social_group_invite_preprocess_views_view_field()

Implements hook_preprocess_HOOK().

File

modules/social_features/social_group/modules/social_group_invite/social_group_invite.module, line 170
The Social Invite group module.

Code

function social_group_invite_preprocess_views_view_field(&$variables) {
  $view = $variables['view'];

  // Alter some group invite fields for better representation in the
  // custom social overview.
  if ($view
    ->id() === 'social_group_invitations') {

    // For invite status we want to show the readable name.
    if ($variables['field']->field === 'invitation_status' && !empty($variables['row']->_entity)) {

      /** @var \Drupal\group\Entity\GroupContent $entity */
      $entity = $variables['row']->_entity;

      // If we have a invite we check it's status.
      $field_value = _social_group_get_group_invite_value($entity, 'invitation_status');
      if (NULL !== $field_value) {

        // Field values are always returned as string,
        // so lets typecast them for now.
        $current_status = (int) $field_value;
        switch ($current_status) {
          case GroupInvitation::INVITATION_PENDING:
            $output = t('Pending reply');
            break;
          case GroupInvitation::INVITATION_ACCEPTED:
            $output = t('Accepted and joined');
            break;
          case GroupInvitation::INVITATION_REJECTED:
            $output = t('Declined');
            break;
          default:
            $output = $variables['output'];
            break;
        }
        $variables['output'] = $output;
      }
    }

    // If user accepted the invite, don't render the actions.
    if ($variables['field']->field === 'dropbutton' && !empty($variables['row']->_entity)) {
      $entity = $variables['row']->_entity;
      $field_value = _social_group_get_group_invite_value($entity, 'invitation_status');

      // Field values are always returned as string,
      // so lets typecast them for now.
      if (NULL !== $field_value) {
        $current_status = (int) $field_value;
        if ($current_status === GroupInvitation::INVITATION_ACCEPTED) {
          $variables['output'] = '';
        }
      }
    }
  }
}