You are here

function _social_group_get_allowed_visibility in Open Social 10.3.x

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. 8.8 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.

1 call to _social_group_get_allowed_visibility()
_social_group_render_group_settings_hero in modules/social_features/social_group/social_group.module
Renders the group settings based on available fields for the hero.

File

modules/social_features/social_group/social_group.module, line 554
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 = [];
  $group_types = [
    'flexible_group',
  ];
  \Drupal::moduleHandler()
    ->alter('social_group_settings', $group_types);
  if (in_array($group_type_id, $group_types)) {

    // Try to retrieve allowed visibility from Group directly.
    $allowed_options = $group
      ->get('field_group_allowed_visibility')
      ->getValue();
    foreach ($allowed_options as $option) {
      if (!empty($option['value']) && is_string($option['value'])) {
        $allowed_visibility[$option['value']] = social_group_allowed_visibility_description($option['value']);
      }
    }
  }

  // Get allowed visibility based on group type. TODO get it programmatically.
  switch ($group_type_id) {
    case 'secret_group':
    case 'closed_group':
      $allowed_visibility['group'] = social_group_allowed_visibility_description('group');
      break;
    case 'open_group':
      $allowed_visibility['community'] = social_group_allowed_visibility_description('community');
      break;
    case 'public_group':
      $allowed_visibility['public'] = social_group_allowed_visibility_description('public');
      break;
  }
  return $allowed_visibility;
}