You are here

protected function SocialGroupSelectorWidget::getOptions in Open Social 8

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::getOptions()
  2. 8.2 modules/social_features/social_group/src/Plugin/Field/FieldWidget/SocialGroupSelectorWidget.php \Drupal\social_group\Plugin\Field\FieldWidget\SocialGroupSelectorWidget::getOptions()
  3. 8.3 modules/social_features/social_group/src/Plugin/Field/FieldWidget/SocialGroupSelectorWidget.php \Drupal\social_group\Plugin\Field\FieldWidget\SocialGroupSelectorWidget::getOptions()
  4. 8.4 modules/social_features/social_group/src/Plugin/Field/FieldWidget/SocialGroupSelectorWidget.php \Drupal\social_group\Plugin\Field\FieldWidget\SocialGroupSelectorWidget::getOptions()
  5. 8.5 modules/social_features/social_group/src/Plugin/Field/FieldWidget/SocialGroupSelectorWidget.php \Drupal\social_group\Plugin\Field\FieldWidget\SocialGroupSelectorWidget::getOptions()
  6. 8.6 modules/social_features/social_group/src/Plugin/Field/FieldWidget/SocialGroupSelectorWidget.php \Drupal\social_group\Plugin\Field\FieldWidget\SocialGroupSelectorWidget::getOptions()
  7. 8.7 modules/social_features/social_group/src/Plugin/Field/FieldWidget/SocialGroupSelectorWidget.php \Drupal\social_group\Plugin\Field\FieldWidget\SocialGroupSelectorWidget::getOptions()
  8. 8.8 modules/social_features/social_group/src/Plugin/Field/FieldWidget/SocialGroupSelectorWidget.php \Drupal\social_group\Plugin\Field\FieldWidget\SocialGroupSelectorWidget::getOptions()
  9. 10.3.x modules/social_features/social_group/src/Plugin/Field/FieldWidget/SocialGroupSelectorWidget.php \Drupal\social_group\Plugin\Field\FieldWidget\SocialGroupSelectorWidget::getOptions()
  10. 10.0.x modules/social_features/social_group/src/Plugin/Field/FieldWidget/SocialGroupSelectorWidget.php \Drupal\social_group\Plugin\Field\FieldWidget\SocialGroupSelectorWidget::getOptions()
  11. 10.1.x modules/social_features/social_group/src/Plugin/Field/FieldWidget/SocialGroupSelectorWidget.php \Drupal\social_group\Plugin\Field\FieldWidget\SocialGroupSelectorWidget::getOptions()
  12. 10.2.x modules/social_features/social_group/src/Plugin/Field/FieldWidget/SocialGroupSelectorWidget.php \Drupal\social_group\Plugin\Field\FieldWidget\SocialGroupSelectorWidget::getOptions()

Returns the array of options for the widget.

Parameters

\Drupal\Core\Entity\FieldableEntityInterface $entity: The entity for which to return options.

Return value

array The array of options for the widget.

Overrides OptionsWidgetBase::getOptions

File

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

Class

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

Namespace

Drupal\social_group\Plugin\Field\FieldWidget

Code

protected function getOptions(FieldableEntityInterface $entity) {
  if (!isset($this->options)) {
    $account = $entity
      ->getOwner();

    // Limit the settable options for the current user account.
    $options = $this->fieldDefinition
      ->getFieldStorageDefinition()
      ->getOptionsProvider($this->column, $entity)
      ->getSettableOptions($account);

    // Remove groups the user does not have create access to.
    if (!$account
      ->hasPermission('manage all groups')) {
      $options = $this
        ->removeGroupsWithoutCreateAccess($options, $account, $entity);
    }

    // Add an empty option if the widget needs one.
    if ($empty_label = $this
      ->getEmptyLabel()) {
      $options = [
        '_none' => $empty_label,
      ] + $options;
    }
    $module_handler = $this->moduleHander;
    $context = [
      'fieldDefinition' => $this->fieldDefinition,
      'entity' => $entity,
    ];
    $module_handler
      ->alter('options_list', $options, $context);
    array_walk_recursive($options, [
      $this,
      'sanitizeLabel',
    ]);
    $this->options = $options;
  }
  return $this->options;
}