You are here

private function SocialGroupSelectorWidget::removeGroupsWithoutCreateAccess in Open Social 8.7

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_group/src/Plugin/Field/FieldWidget/SocialGroupSelectorWidget.php \Drupal\social_group\Plugin\Field\FieldWidget\SocialGroupSelectorWidget::removeGroupsWithoutCreateAccess()
  2. 8 modules/social_features/social_group/src/Plugin/Field/FieldWidget/SocialGroupSelectorWidget.php \Drupal\social_group\Plugin\Field\FieldWidget\SocialGroupSelectorWidget::removeGroupsWithoutCreateAccess()
  3. 8.2 modules/social_features/social_group/src/Plugin/Field/FieldWidget/SocialGroupSelectorWidget.php \Drupal\social_group\Plugin\Field\FieldWidget\SocialGroupSelectorWidget::removeGroupsWithoutCreateAccess()
  4. 8.3 modules/social_features/social_group/src/Plugin/Field/FieldWidget/SocialGroupSelectorWidget.php \Drupal\social_group\Plugin\Field\FieldWidget\SocialGroupSelectorWidget::removeGroupsWithoutCreateAccess()
  5. 8.4 modules/social_features/social_group/src/Plugin/Field/FieldWidget/SocialGroupSelectorWidget.php \Drupal\social_group\Plugin\Field\FieldWidget\SocialGroupSelectorWidget::removeGroupsWithoutCreateAccess()
  6. 8.5 modules/social_features/social_group/src/Plugin/Field/FieldWidget/SocialGroupSelectorWidget.php \Drupal\social_group\Plugin\Field\FieldWidget\SocialGroupSelectorWidget::removeGroupsWithoutCreateAccess()
  7. 8.6 modules/social_features/social_group/src/Plugin/Field/FieldWidget/SocialGroupSelectorWidget.php \Drupal\social_group\Plugin\Field\FieldWidget\SocialGroupSelectorWidget::removeGroupsWithoutCreateAccess()
  8. 8.8 modules/social_features/social_group/src/Plugin/Field/FieldWidget/SocialGroupSelectorWidget.php \Drupal\social_group\Plugin\Field\FieldWidget\SocialGroupSelectorWidget::removeGroupsWithoutCreateAccess()
  9. 10.3.x modules/social_features/social_group/src/Plugin/Field/FieldWidget/SocialGroupSelectorWidget.php \Drupal\social_group\Plugin\Field\FieldWidget\SocialGroupSelectorWidget::removeGroupsWithoutCreateAccess()
  10. 10.0.x modules/social_features/social_group/src/Plugin/Field/FieldWidget/SocialGroupSelectorWidget.php \Drupal\social_group\Plugin\Field\FieldWidget\SocialGroupSelectorWidget::removeGroupsWithoutCreateAccess()
  11. 10.1.x modules/social_features/social_group/src/Plugin/Field/FieldWidget/SocialGroupSelectorWidget.php \Drupal\social_group\Plugin\Field\FieldWidget\SocialGroupSelectorWidget::removeGroupsWithoutCreateAccess()
  12. 10.2.x modules/social_features/social_group/src/Plugin/Field/FieldWidget/SocialGroupSelectorWidget.php \Drupal\social_group\Plugin\Field\FieldWidget\SocialGroupSelectorWidget::removeGroupsWithoutCreateAccess()

Remove options from the list.

Parameters

array $options: A list of options to check.

\Drupal\user\Entity\User $account: The user to check for.

\Drupal\Core\Entity\EntityInterface $entity: The entity to check for.

Return value

array An list of options for the field containing groups with create access.

1 call to SocialGroupSelectorWidget::removeGroupsWithoutCreateAccess()
SocialGroupSelectorWidget::getOptions in modules/social_features/social_group/src/Plugin/Field/FieldWidget/SocialGroupSelectorWidget.php
Returns the array of options for the widget.

File

modules/social_features/social_group/src/Plugin/Field/FieldWidget/SocialGroupSelectorWidget.php, line 273

Class

SocialGroupSelectorWidget
A widget to select a group when creating an entity in a group.

Namespace

Drupal\social_group\Plugin\Field\FieldWidget

Code

private function removeGroupsWithoutCreateAccess(array $options, User $account, EntityInterface $entity) {
  foreach ($options as $option_category_key => $groups_in_category) {
    if (is_array($groups_in_category)) {
      foreach ($groups_in_category as $gid => $group_title) {
        if (!$this
          ->checkGroupContentCreateAccess($gid, $account, $entity)) {
          unset($options[$option_category_key][$gid]);
        }
      }

      // Remove the entire category if there are no groups for this author.
      if (empty($options[$option_category_key])) {
        unset($options[$option_category_key]);
      }
    }
    else {
      if (!$this
        ->checkGroupContentCreateAccess($option_category_key, $account, $entity)) {
        unset($options[$option_category_key]);
      }
    }
  }
  return $options;
}