You are here

public function WidgetPluginManager::getOptions in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Field/WidgetPluginManager.php \Drupal\Core\Field\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

core/lib/Drupal/Core/Field/WidgetPluginManager.php, line 174
Contains \Drupal\Core\Field\WidgetPluginManager.

Class

WidgetPluginManager
Plugin type manager for field widgets.

Namespace

Drupal\Core\Field

Code

public function getOptions($field_type = NULL) {
  if (!isset($this->widgetOptions)) {
    $options = array();
    $field_types = $this->fieldTypeManager
      ->getDefinitions();
    $widget_types = $this
      ->getDefinitions();
    uasort($widget_types, array(
      'Drupal\\Component\\Utility\\SortArray',
      'sortByWeightElement',
    ));
    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;
}