You are here

function _social_group_get_group_visibility in Open Social 10.1.x

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

Get the group visibility label of a group.

Parameters

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

string $field_name: The field name of the visibility field for a group type.

Return value

array Returns the visibility options of a group.

1 call to _social_group_get_group_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 489
The Social group module.

Code

function _social_group_get_group_visibility(GroupInterface $group, $field_name = NULL) {
  $group_type = $group
    ->getGroupType();
  $group_type_id = $group_type
    ->id();
  $group_visibility = [];
  $group_types = [
    'flexible_group',
  ];
  \Drupal::moduleHandler()
    ->alter('social_group_settings', $group_types);
  if (in_array($group_type_id, $group_types)) {

    // By default we ship with the below field, lets grab its value(s).
    if ($group
      ->hasField('field_flexible_group_visibility')) {
      $visibility_values = $group
        ->get('field_flexible_group_visibility')
        ->getValue();

      // Lets grab the rendered description for the group visibility.
      if (!empty($visibility_values)) {
        foreach ($visibility_values as $visibility_value) {
          if (!empty($visibility_value['value']) && is_string($visibility_value['value'])) {
            $group_visibility[$visibility_value['value']] = social_group_group_visibility_description($visibility_value['value']);
          }
        }
      }
      return $group_visibility;
    }

    // If the above field doesn't exist the user might have a different one
    // so lets see if it's given as argument and get it's description.
    if ($field_name !== NULL && $group
      ->hasField($field_name)) {
      $visibility_values = $group
        ->get($field_name)
        ->getValue();

      // Lets grab the rendered description for the group visibility.
      if (!empty($visibility_values)) {
        foreach ($visibility_values as $visibility_value) {
          if (!empty($visibility_value['value']) && is_string($visibility_value['value'])) {
            $group_visibility[$visibility_value['value']] = social_group_group_visibility_description($visibility_value['value']);
          }
        }
      }
      return $group_visibility;
    }
  }

  // Get join method based on group type.
  switch ($group_type_id) {
    case 'secret_group':
    case 'closed_group':
    case 'public_group':
    case 'open_group':
      return $group_visibility;
    default:

      // For non Open Social group types, we can allow developers to pass
      // a field name to return a label instead.
      if ($field_name !== NULL && $group
        ->hasField($field_name)) {
        $group_visibility = $group
          ->get($field_name)
          ->getValue();
      }
      return $group_visibility;
  }
}