protected function FieldWrapperBase::getAvailableFormatterOptions in (Entity Reference) Field Formatters 3.x
Same name and namespace in other branches
- 8.2 src/Plugin/Field/FieldFormatter/FieldWrapperBase.php \Drupal\field_formatter\Plugin\Field\FieldFormatter\FieldWrapperBase::getAvailableFormatterOptions()
- 8 src/Plugin/Field/FieldFormatter/FieldWrapperBase.php \Drupal\field_formatter\Plugin\Field\FieldFormatter\FieldWrapperBase::getAvailableFormatterOptions()
Get all available formatters by loading available ones and filtering out.
Parameters
\Drupal\Core\Field\FieldStorageDefinitionInterface $field_storage_definition: The field storage definition.
Return value
string[] The field formatter labels keys by plugin ID.
1 call to FieldWrapperBase::getAvailableFormatterOptions()
- FieldWrapperBase::settingsForm in src/
Plugin/ Field/ FieldFormatter/ FieldWrapperBase.php - Returns a form to configure settings for the formatter.
File
- src/
Plugin/ Field/ FieldFormatter/ FieldWrapperBase.php, line 117
Class
- FieldWrapperBase
- Wraps an existing field.
Namespace
Drupal\field_formatter\Plugin\Field\FieldFormatterCode
protected function getAvailableFormatterOptions(FieldStorageDefinitionInterface $field_storage_definition) {
$formatters = $this->formatterPluginManager
->getOptions($field_storage_definition
->getType());
$formatter_instances = array_map(function ($formatter_id) {
// TODO: Ensure it is right to empty all values here, see:
// https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Field%21FormatterPluginManager.php/class/FormatterPluginManager/8.2.x
$configuration = [
'field_definition' => $this->fieldDefinition,
'settings' => [],
'label' => '',
'view_mode' => '',
'third_party_settings' => [],
];
return $this->formatterPluginManager
->createInstance($formatter_id, $configuration);
}, array_combine(array_keys($formatters), array_keys($formatters)));
$filtered_formatter_instances = array_filter($formatter_instances, function (FormatterInterface $formatter) {
return $formatter
->isApplicable($this->fieldDefinition);
});
$options = array_map(function (FormatterInterface $formatter) {
return $formatter
->getPluginDefinition()['label'];
}, $filtered_formatter_instances);
// Remove field_link itself.
unset($options['field_link']);
return $options;
}