protected function BynderFormatterBase::getAttributesFieldsCandidates in Bynder 8.3
Same name and namespace in other branches
- 4.0.x src/Plugin/Field/FieldFormatter/BynderFormatterBase.php \Drupal\bynder\Plugin\Field\FieldFormatter\BynderFormatterBase::getAttributesFieldsCandidates()
Gets list of fields that are candidates for IMG attributes.
Return value
array List of fields with machine names as keys and human-readable names as values.
4 calls to BynderFormatterBase::getAttributesFieldsCandidates()
- BynderDocumentFormatter::settingsForm in src/
Plugin/ Field/ FieldFormatter/ BynderDocumentFormatter.php - Returns a form to configure settings for the formatter.
- BynderDocumentFormatter::settingsSummary in src/
Plugin/ Field/ FieldFormatter/ BynderDocumentFormatter.php - Returns a short summary for the current formatter settings.
- BynderFormatter::settingsForm in src/
Plugin/ Field/ FieldFormatter/ BynderFormatter.php - Returns a form to configure settings for the formatter.
- BynderFormatter::settingsSummary in src/
Plugin/ Field/ FieldFormatter/ BynderFormatter.php - Returns a short summary for the current formatter settings.
File
- src/
Plugin/ Field/ FieldFormatter/ BynderFormatterBase.php, line 133
Class
- BynderFormatterBase
- Base class for Bynder formatters.
Namespace
Drupal\bynder\Plugin\Field\FieldFormatterCode
protected function getAttributesFieldsCandidates() {
$allowed_field_types = [
'string',
'string_long',
'text',
'text_long',
];
$handler_settings = NULL;
if (strpos($this->fieldDefinition
->getSetting('handler'), 'default:') === 0) {
$handler_settings = $this->fieldDefinition
->getSetting('handler_settings');
}
$bundles = [];
if ($handler_settings && is_array($handler_settings['target_bundles'])) {
foreach ($handler_settings['target_bundles'] as $bundle) {
/** @var \Drupal\media\MediaTypeInterface $type */
$type = $this->entityTypeManager
->getStorage('media_type')
->load($bundle);
if ($type && $type
->getSource() instanceof Bynder) {
$bundles[] = $type;
}
}
}
else {
/** @var \Drupal\media\MediaTypeInterface $type */
foreach ($this->entityTypeManager
->getStorage('media_type')
->loadMultiple() as $type) {
if ($type && $type
->getSource() instanceof Bynder) {
$bundles[] = $type;
}
}
}
$options = [];
foreach ($bundles as $type) {
foreach ($this->entityFieldManager
->getFieldDefinitions('media', $type
->id()) as $field_name => $field) {
if (in_array($field
->getType(), $allowed_field_types)) {
$options[$field_name] = $field
->getLabel();
}
}
}
return $options;
}