You are here

function social_group_get_allowed_visibility_options_per_group_type in Open Social 8.9

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

Get the allowed visibility options for a given group type.

Parameters

string|null $group_type_id: The group type. Can be NULL to get visibility when it is not in a group.

\Drupal\Core\Session\AccountInterface|null $account: The account object that may have impact on the visibility options.

Return value

array An array of visibility options for the given group type.

3 calls to social_group_get_allowed_visibility_options_per_group_type()
PostForm::configureVisibilityField in modules/social_features/social_post/src/Form/PostForm.php
Configures the allows values for the visiblity field.
SocialGroupSelectorWidget::validateGroupSelection in modules/social_features/social_group/src/Plugin/Field/FieldWidget/SocialGroupSelectorWidget.php
Validate the group selection and change the visibility settings.
social_group_field_widget_form_alter in modules/social_features/social_group/social_group.module
Alter the visibility field within groups.

File

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

Code

function social_group_get_allowed_visibility_options_per_group_type($group_type_id, AccountInterface $account = NULL, $entity = NULL, $group = NULL) {

  // Get the logged in user.
  if ($account === NULL) {
    $account = \Drupal::currentUser();
  }
  $visibility_options = [];
  $visibility_options['public'] = FALSE;
  $visibility_options['community'] = TRUE;
  $visibility_options['group'] = FALSE;
  switch ($group_type_id) {
    case 'closed_group':
      $visibility_options['community'] = FALSE;
      $visibility_options['group'] = TRUE;
      break;
    case 'public_group':
      $visibility_options['public'] = TRUE;
      $visibility_options['community'] = FALSE;
      break;
    case 'open_group':
      $visibility_options['public'] = FALSE;
      $visibility_options['community'] = TRUE;
      $visibility_options['group'] = FALSE;
      break;
    case 'secret_group':
      $visibility_options['public'] = FALSE;
      $visibility_options['community'] = FALSE;
      $visibility_options['group'] = TRUE;
      break;
    case 'flexible_group':
      if (empty($group)) {
        $group = _social_group_get_current_group();
      }
      if ($group !== NULL) {
        $visibility_options['public'] = FALSE;
        $visibility_options['community'] = FALSE;
        $visibility_options['group'] = FALSE;

        // Try to retrieve allowed options from Group directly.
        $allowed_options = $group
          ->get('field_group_allowed_visibility')
          ->getValue();
        foreach ($allowed_options as $option) {
          $value = $option['value'];
          $visibility_options[$value] = TRUE;
        }
      }
      break;
    default:
      $config = \Drupal::config('entity_access_by_field.settings');
      $visibility_options['public'] = TRUE;
      if ($config
        ->get('disable_public_visibility') === 1 && !$account
        ->hasPermission('override disabled public visibility')) {

        // This is a new entity.
        if (!$entity) {
          $visibility_options['public'] = FALSE;
        }
        else {

          /** @var \Drupal\node\Entity\Node $entity */
          if ($entity
            ->hasField('field_content_visibility')) {
            $current_visibility = $entity
              ->get('field_content_visibility')
              ->getString();
            if ($current_visibility !== 'public') {
              $visibility_options['public'] = FALSE;
            }
          }
        }
      }
      $visibility_options['community'] = TRUE;
      $visibility_options['group'] = FALSE;
      break;
  }
  \Drupal::moduleHandler()
    ->alter('social_group_allowed_visibilities', $visibility_options, $group_type_id);
  return $visibility_options;
}