You are here

public static function FlexibleGroupContentVisibilityUpdate::calculateVisibility in Open Social 8.9

Same name and namespace in other branches
  1. 8.6 modules/social_features/social_group/modules/social_group_flexible_group/src/FlexibleGroupContentVisibilityUpdate.php \Drupal\social_group_flexible_group\FlexibleGroupContentVisibilityUpdate::calculateVisibility()
  2. 8.7 modules/social_features/social_group/modules/social_group_flexible_group/src/FlexibleGroupContentVisibilityUpdate.php \Drupal\social_group_flexible_group\FlexibleGroupContentVisibilityUpdate::calculateVisibility()
  3. 8.8 modules/social_features/social_group/modules/social_group_flexible_group/src/FlexibleGroupContentVisibilityUpdate.php \Drupal\social_group_flexible_group\FlexibleGroupContentVisibilityUpdate::calculateVisibility()
  4. 10.3.x modules/social_features/social_group/modules/social_group_flexible_group/src/FlexibleGroupContentVisibilityUpdate.php \Drupal\social_group_flexible_group\FlexibleGroupContentVisibilityUpdate::calculateVisibility()
  5. 10.0.x modules/social_features/social_group/modules/social_group_flexible_group/src/FlexibleGroupContentVisibilityUpdate.php \Drupal\social_group_flexible_group\FlexibleGroupContentVisibilityUpdate::calculateVisibility()
  6. 10.1.x modules/social_features/social_group/modules/social_group_flexible_group/src/FlexibleGroupContentVisibilityUpdate.php \Drupal\social_group_flexible_group\FlexibleGroupContentVisibilityUpdate::calculateVisibility()
  7. 10.2.x modules/social_features/social_group/modules/social_group_flexible_group/src/FlexibleGroupContentVisibilityUpdate.php \Drupal\social_group_flexible_group\FlexibleGroupContentVisibilityUpdate::calculateVisibility()

Calculate the new visibility options.

Parameters

string $current_visibility: The current visibility.

array $new_options: The new options to choose from.

Return value

string The new visibility.

1 call to FlexibleGroupContentVisibilityUpdate::calculateVisibility()
FlexibleGroupContentVisibilityUpdate::updateVisibility in modules/social_features/social_group/modules/social_group_flexible_group/src/FlexibleGroupContentVisibilityUpdate.php
Update visibility for all Group Content based on a new group type.

File

modules/social_features/social_group/modules/social_group_flexible_group/src/FlexibleGroupContentVisibilityUpdate.php, line 214

Class

FlexibleGroupContentVisibilityUpdate
Class FlexibleGroupContentVisibilityUpdate.

Namespace

Drupal\social_group_flexible_group

Code

public static function calculateVisibility($current_visibility, array $new_options) {

  // If there is only one option just return that one.
  if (count($new_options) === 1) {
    return reset($new_options)['value'];
  }

  /** @var \Drupal\user\RoleInterface $role */
  $role = \Drupal::entityTypeManager()
    ->getStorage('user_role')
    ->load($current_visibility);
  if ($role instanceof RoleInterface) {
    return reset($new_options)['value'];
  }
  $visibility = '';
  $option_values = array_column($new_options, 'value');

  // Calculate new options based on what it was before editting.
  switch ($current_visibility) {
    case 'community':
      $visibility = 'public';
      if (in_array('group', $option_values)) {
        $visibility = 'group';
      }
      break;
    case 'public':
      $visibility = 'group';
      if (in_array('community', $option_values)) {
        $visibility = 'community';
      }
      break;
    case 'group':
      $visibility = 'public';
      if (in_array('community', $option_values)) {
        $visibility = 'community';
      }
      break;
  }
  return $visibility;
}