public static function FlexibleGroupContentVisibilityUpdate::calculateVisibility in Open Social 8.9
Same name and namespace in other branches
- 8.6 modules/social_features/social_group/modules/social_group_flexible_group/src/FlexibleGroupContentVisibilityUpdate.php \Drupal\social_group_flexible_group\FlexibleGroupContentVisibilityUpdate::calculateVisibility()
- 8.7 modules/social_features/social_group/modules/social_group_flexible_group/src/FlexibleGroupContentVisibilityUpdate.php \Drupal\social_group_flexible_group\FlexibleGroupContentVisibilityUpdate::calculateVisibility()
- 8.8 modules/social_features/social_group/modules/social_group_flexible_group/src/FlexibleGroupContentVisibilityUpdate.php \Drupal\social_group_flexible_group\FlexibleGroupContentVisibilityUpdate::calculateVisibility()
- 10.3.x modules/social_features/social_group/modules/social_group_flexible_group/src/FlexibleGroupContentVisibilityUpdate.php \Drupal\social_group_flexible_group\FlexibleGroupContentVisibilityUpdate::calculateVisibility()
- 10.0.x modules/social_features/social_group/modules/social_group_flexible_group/src/FlexibleGroupContentVisibilityUpdate.php \Drupal\social_group_flexible_group\FlexibleGroupContentVisibilityUpdate::calculateVisibility()
- 10.1.x modules/social_features/social_group/modules/social_group_flexible_group/src/FlexibleGroupContentVisibilityUpdate.php \Drupal\social_group_flexible_group\FlexibleGroupContentVisibilityUpdate::calculateVisibility()
- 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_groupCode
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;
}