protected function OptionsWidgetBase::getOptions

Returns the array of options for the widget.

Return value

array The array of options for the widget.

4 calls to OptionsWidgetBase::getOptions()
ButtonsWidget::formElement in drupal/core/modules/options/lib/Drupal/options/Plugin/field/widget/ButtonsWidget.php
Returns the form for a single field widget.
OnOffWidget::formElement in drupal/core/modules/options/lib/Drupal/options/Plugin/field/widget/OnOffWidget.php
Returns the form for a single field widget.
OptionsWidgetBase::getSelectedOptions in drupal/core/modules/options/lib/Drupal/options/Plugin/field/widget/OptionsWidgetBase.php
Determines selected options from the incoming field values.
SelectWidget::formElement in drupal/core/modules/options/lib/Drupal/options/Plugin/field/widget/SelectWidget.php
Returns the form for a single field widget.

File

drupal/core/modules/options/lib/Drupal/options/Plugin/field/widget/OptionsWidgetBase.php, line 113
Contains \Drupal\options\Plugin\field\widget\OptionsWidgetBase.

Class

OptionsWidgetBase
Base class for the 'options_*' widgets.

Namespace

Drupal\options\Plugin\field\widget

Code

protected function getOptions() {
  if (!isset($this->options)) {
    $module_handler = \Drupal::moduleHandler();

    // Get the list of options from the field type module, and sanitize them.
    $options = (array) $module_handler
      ->invoke($this->field['module'], 'options_list', array(
      $this->field,
      $this->instance,
      $this->entity,
    ));

    // Add an empty option if the widget needs one.
    if ($empty_option = $this
      ->getEmptyOption()) {
      switch ($this
        ->getPluginId()) {
        case 'options_buttons':
          $label = t('N/A');
          break;
        case 'options_select':
          $label = $empty_option == static::OPTIONS_EMPTY_NONE ? t('- None -') : t('- Select a value -');
          break;
      }
      $options = array(
        '_none' => $label,
      ) + $options;
    }
    $context = array(
      'field' => $this->field,
      'instance' => $this->instance,
      'entity' => $this->entity,
    );
    $module_handler
      ->alter('options_list', $options, $context);
    array_walk_recursive($options, array(
      $this,
      'sanitizeLabel',
    ));

    // Options might be nested ("optgroups"). If the widget does not support
    // nested options, flatten the list.
    if (!$this
      ->supportsGroups()) {
      $options = $this
        ->flattenOptions($options);
    }
    $this->options = $options;
  }
  return $this->options;
}