public function PhotoswipeFieldFormatter::addEntityReferenceSettings in PhotoSwipe 3.x
Same name and namespace in other branches
- 8.2 src/Plugin/Field/FieldFormatter/PhotoswipeFieldFormatter.php \Drupal\photoswipe\Plugin\Field\FieldFormatter\PhotoswipeFieldFormatter::addEntityReferenceSettings()
Adds extra settings related when dealing with an entity reference.
Parameters
array $element: The settings form structure of this formatter.
Return value
array The modified settings form structure of this formatter.
1 call to PhotoswipeFieldFormatter::addEntityReferenceSettings()
- PhotoswipeFieldFormatter::settingsForm in src/
Plugin/ Field/ FieldFormatter/ PhotoswipeFieldFormatter.php - Returns a form to configure settings for the formatter.
File
- src/
Plugin/ Field/ FieldFormatter/ PhotoswipeFieldFormatter.php, line 287
Class
- PhotoswipeFieldFormatter
- Plugin implementation of the 'photoswipe_field_formatter' formatter.
Namespace
Drupal\photoswipe\Plugin\Field\FieldFormatterCode
public function addEntityReferenceSettings(array $element) {
if ($this->fieldDefinition
->getType() !== 'entity_reference') {
return $element;
}
$target_type = $this->fieldDefinition
->getSetting('target_type');
$target_bundles = $this->fieldDefinition
->getSetting('handler_settings')['target_bundles'];
/** @var \Drupal\Core\Field\FieldDefinitionInterface[] $fields */
$fields = [];
foreach ($target_bundles as $bundle) {
$fields += $this->entityFieldManager
->getFieldDefinitions($target_type, $bundle);
}
$fields = array_filter($fields, function (FieldDefinitionInterface $field) {
return $field
->getType() === 'image' && $field
->getName() !== 'thumbnail';
});
$field_options = [];
foreach ($fields as $name => $field) {
$field_options[$name] = $field
->getName();
}
$element['photoswipe_reference_image_field'] = [
'#title' => $this
->t('Image field of the referenced entity'),
'#type' => 'select',
'#default_value' => $this
->getSetting('photoswipe_reference_image_field'),
'#options' => $field_options,
'#description' => $this
->t('Field that contains the image to be used.'),
];
return $element;
}