public function WidgetPluginManager::getOptions

Returns an array of widget type options for a field type.

Parameters

string|null $field_type: (optional) The name of a field type, or NULL to retrieve all widget options. Defaults to NULL.

Return value

array If no field type is provided, returns a nested array of all widget types, keyed by field type human name.

File

drupal/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php, line 142
Definition of Drupal\field\Plugin\Type\Widget\WidgetPluginManager.

Class

WidgetPluginManager
Plugin type manager for field widgets.

Namespace

Drupal\field\Plugin\Type\Widget

Code

public function getOptions($field_type = NULL) {
  if (!isset($this->widgetOptions)) {
    $options = array();
    $field_types = field_info_field_types();
    $widget_types = $this
      ->getDefinitions();
    uasort($widget_types, 'drupal_sort_weight');
    foreach ($widget_types as $name => $widget_type) {
      foreach ($widget_type['field_types'] as $widget_field_type) {

        // Check that the field type exists.
        if (isset($field_types[$widget_field_type])) {
          $options[$widget_field_type][$name] = $widget_type['label'];
        }
      }
    }
    $this->widgetOptions = $options;
  }
  if (isset($field_type)) {
    return !empty($this->widgetOptions[$field_type]) ? $this->widgetOptions[$field_type] : array();
  }
  return $this->widgetOptions;
}