protected function SvgImageFieldWidget::formMultipleElements in SVG Image Field 8
Same name and namespace in other branches
- 2.1.x src/Plugin/Field/FieldWidget/SvgImageFieldWidget.php \Drupal\svg_image_field\Plugin\Field\FieldWidget\SvgImageFieldWidget::formMultipleElements()
- 2.0.x src/Plugin/Field/FieldWidget/SvgImageFieldWidget.php \Drupal\svg_image_field\Plugin\Field\FieldWidget\SvgImageFieldWidget::formMultipleElements()
Overrides \Drupal\Core\Field\WidgetBase::formMultipleElements().
Special handling for draggable multiple widgets and 'add more' button.
Overrides FileWidget::formMultipleElements
File
- src/
Plugin/ Field/ FieldWidget/ SvgImageFieldWidget.php, line 117
Class
- SvgImageFieldWidget
- Plugin implementation of the 'image_image' widget.
Namespace
Drupal\svg_image_field\Plugin\Field\FieldWidgetCode
protected function formMultipleElements(FieldItemListInterface $items, array &$form, FormStateInterface $form_state) {
$elements = parent::formMultipleElements($items, $form, $form_state);
$cardinality = $this->fieldDefinition
->getFieldStorageDefinition()
->getCardinality();
$file_upload_help = [
'#theme' => 'file_upload_help',
'#description' => '',
'#upload_validators' => $elements[0]['#upload_validators'],
'#cardinality' => $cardinality,
];
if ($cardinality == 1) {
// If there's only one field, return it as delta 0.
if (empty($elements[0]['#default_value']['fids'])) {
$file_upload_help['#description'] = $this
->getFilteredDescription();
$elements[0]['#description'] = $this->renderer
->renderPlain($file_upload_help);
}
}
else {
$elements['#file_upload_description'] = $file_upload_help;
}
return $elements;
}