function FormatterPluginManager::getOptions
Same name in other branches
- 8.9.x core/lib/Drupal/Core/Field/FormatterPluginManager.php \Drupal\Core\Field\FormatterPluginManager::getOptions()
- 10 core/lib/Drupal/Core/Field/FormatterPluginManager.php \Drupal\Core\Field\FormatterPluginManager::getOptions()
- 11.x core/lib/Drupal/Core/Field/FormatterPluginManager.php \Drupal\Core\Field\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
-
core/
lib/ Drupal/ Core/ Field/ FormatterPluginManager.php, line 169
Class
- FormatterPluginManager
- Plugin type manager for field formatters.
Namespace
Drupal\Core\FieldCode
public function getOptions($field_type = NULL) {
if (!isset($this->formatterOptions)) {
$options = [];
$field_types = $this->fieldTypeManager
->getDefinitions();
$formatter_types = $this->getDefinitions();
uasort($formatter_types, [
'Drupal\\Component\\Utility\\SortArray',
'sortByWeightElement',
]);
foreach ($formatter_types as $name => $formatter_type) {
foreach ($formatter_type['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_type['label'];
}
}
}
$this->formatterOptions = $options;
}
if ($field_type) {
return !empty($this->formatterOptions[$field_type]) ? $this->formatterOptions[$field_type] : [];
}
return $this->formatterOptions;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.