protected function FieldFormatterWithInlineSettings::getAvailableFormatterOptions in (Entity Reference) Field Formatters 8
Same name and namespace in other branches
- 8.2 src/Plugin/Field/FieldFormatter/FieldFormatterWithInlineSettings.php \Drupal\field_formatter\Plugin\Field\FieldFormatter\FieldFormatterWithInlineSettings::getAvailableFormatterOptions()
- 3.x src/Plugin/Field/FieldFormatter/FieldFormatterWithInlineSettings.php \Drupal\field_formatter\Plugin\Field\FieldFormatter\FieldFormatterWithInlineSettings::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 FieldFormatterWithInlineSettings::getAvailableFormatterOptions()
- FieldFormatterWithInlineSettings::settingsForm in src/
Plugin/ Field/ FieldFormatter/ FieldFormatterWithInlineSettings.php - Returns a form to configure settings for the formatter.
File
- src/
Plugin/ Field/ FieldFormatter/ FieldFormatterWithInlineSettings.php, line 128
Class
- FieldFormatterWithInlineSettings
- Plugin implementation of the 'link' formatter.
Namespace
Drupal\field_formatter\Plugin\Field\FieldFormatterCode
protected function getAvailableFormatterOptions(FieldStorageDefinitionInterface $field_storage_definition) {
$field_definition = $this
->getFieldDefinition($field_storage_definition);
$formatters = $this->formatterPluginManager
->getOptions($field_storage_definition
->getType());
$formatter_instances = array_map(function ($formatter_id) use ($field_definition) {
// 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' => $field_definition,
'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) use ($field_definition) {
return $formatter
->isApplicable($field_definition);
});
$options = array_map(function (FormatterInterface $formatter) {
return $formatter
->getPluginDefinition()['label'];
}, $filtered_formatter_instances);
return $options;
}