You are here

protected function WebformEntityReferenceSelectWidget::getOptions in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Plugin/Field/FieldWidget/WebformEntityReferenceSelectWidget.php \Drupal\webform\Plugin\Field\FieldWidget\WebformEntityReferenceSelectWidget::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

1 call to WebformEntityReferenceSelectWidget::getOptions()
WebformEntityReferenceSelectWidget::getTargetIdElement in src/Plugin/Field/FieldWidget/WebformEntityReferenceSelectWidget.php
Returns the target id element form for a single webform field widget.

File

src/Plugin/Field/FieldWidget/WebformEntityReferenceSelectWidget.php, line 100

Class

WebformEntityReferenceSelectWidget
Plugin implementation of the 'webform_entity_reference_select' widget.

Namespace

Drupal\webform\Plugin\Field\FieldWidget

Code

protected function getOptions(FieldableEntityInterface $entity) {
  if (!isset($this->options)) {
    $webform_ids = $this
      ->getSetting('webforms');
    if ($webform_ids) {
      $webforms = Webform::loadMultiple($webform_ids);
      $options = [];
      foreach ($webforms as $webform) {
        $options[$webform
          ->id()] = $webform
          ->label();
      }
      asort($options);
    }
    else {

      // Limit the settable options for the current user account.
      // Note: All active webforms are returned and grouped by category.
      // @see \Drupal\webform\Plugin\Field\FieldType\WebformEntityReferenceItem::getSettableOptions
      // @see \Drupal\webform\WebformEntityStorageInterface::getOptions
      $options = $this->fieldDefinition
        ->getFieldStorageDefinition()
        ->getOptionsProvider($this->column, $entity)
        ->getSettableOptions(\Drupal::currentUser());
    }
    $module_handler = \Drupal::moduleHandler();
    $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;
}