public function FormatterPluginManager::getOptions

Returns an array of formatter options for a field type.

Parameters

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

Return value

array If no field type is provided, returns a nested array of all formatters, keyed by field type.

File

drupal/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php, line 144
Definition of Drupal\field\Plugin\Type\Formatter\FormatterPluginManager..

Class

FormatterPluginManager
Plugin type manager for field formatters.

Namespace

Drupal\field\Plugin\Type\Formatter

Code

public function getOptions($field_type = NULL) {
  if (!isset($this->formatterOptions)) {
    $field_types = field_info_field_types();
    $options = array();
    foreach ($this
      ->getDefinitions() as $name => $formatter) {
      foreach ($formatter['field_types'] as $formatter_field_type) {

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