You are here

function _social_group_get_allowed_visibility in Open Social 8.8

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

Get the allowed visibility of a group.

Parameters

Drupal\group\Entity\GroupInterface $group: the Group interface.

Return value

array Returns allowed visibility of a group.

2 calls to _social_group_get_allowed_visibility()
social_group_preprocess_group in modules/social_features/social_group/social_group.module
Prepares variables for profile templates.
social_group_preprocess_group__hero in modules/social_features/social_group/social_group.module
Implements hook_preprocess_HOOK().

File

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

Code

function _social_group_get_allowed_visibility(GroupInterface $group) {
  $group_type = $group
    ->getGroupType();
  $group_type_id = $group_type
    ->id();
  $allowed_visibility = [];

  // Get allowed visibility based on group type. TODO get it programmatically.
  switch ($group_type_id) {
    case 'secret_group':
    case 'closed_group':
      $allowed_visibility = [
        'group' => t('Group members'),
      ];
      break;
    case 'open_group':
      $allowed_visibility = [
        'community' => t('Community'),
      ];
      break;
    case 'public_group':
      $allowed_visibility = [
        'public' => t('Public'),
      ];
      break;
    case 'flexible_group':

      // Try to retrieve allowed visibility from Group directly.
      $allowed_options = $group
        ->get('field_group_allowed_visibility')
        ->getValue();
      foreach ($allowed_options as $option) {
        $value = $option['value'];
        if ($value === 'public') {
          $allowed_visibility['public'] = t('Public');
        }
        if ($value === 'community') {
          $allowed_visibility['community'] = t('Community');
        }
        if ($value === 'group') {
          $allowed_visibility['group'] = t('Group members');
        }
      }
      break;
  }
  return $allowed_visibility;
}