protected function FieldFormatterBase::getAvailableFieldNames in (Entity Reference) Field Formatters 8
Same name and namespace in other branches
- 8.2 src/Plugin/Field/FieldFormatter/FieldFormatterBase.php \Drupal\field_formatter\Plugin\Field\FieldFormatter\FieldFormatterBase::getAvailableFieldNames()
- 3.x src/Plugin/Field/FieldFormatter/FieldFormatterBase.php \Drupal\field_formatter\Plugin\Field\FieldFormatter\FieldFormatterBase::getAvailableFieldNames()
Gets list of supported fields.
Return value
array List of fields that are supported keyed by field machine name.
2 calls to FieldFormatterBase::getAvailableFieldNames()
- FieldFormatterFromViewDisplay::settingsForm in src/
Plugin/ Field/ FieldFormatter/ FieldFormatterFromViewDisplay.php - Returns a form to configure settings for the formatter.
- FieldFormatterWithInlineSettings::settingsForm in src/
Plugin/ Field/ FieldFormatter/ FieldFormatterWithInlineSettings.php - Returns a form to configure settings for the formatter.
File
- src/
Plugin/ Field/ FieldFormatter/ FieldFormatterBase.php, line 143
Class
- FieldFormatterBase
- Base class for field formatters.
Namespace
Drupal\field_formatter\Plugin\Field\FieldFormatterCode
protected function getAvailableFieldNames() {
$field_names = [];
$entity_type_id = $this->fieldDefinition
->getSetting('target_type');
/** @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface $bundle_info */
$bundle_info = \Drupal::service('entity_type.bundle.info');
$fieldDefinitionHandlerSettings = $this->fieldDefinition
->getSetting('handler_settings');
$target_bundles = empty($fieldDefinitionHandlerSettings['target_bundles']) ? array_keys($bundle_info
->getBundleInfo($entity_type_id)) : $fieldDefinitionHandlerSettings['target_bundles'];
foreach ($target_bundles as $value) {
$bundle_field_names = array_map(function (FieldDefinitionInterface $field_definition) {
return $field_definition
->getLabel();
}, \Drupal::service('entity_field.manager')
->getFieldDefinitions($entity_type_id, $value));
$field_names = array_merge($field_names, $bundle_field_names);
}
return $field_names;
}