You are here

protected function SvgImageWidget::formMultipleElements in Svg Image 8

Same name and namespace in other branches
  1. 2.x src/Plugin/Field/FieldWidget/SvgImageWidget.php \Drupal\svg_image\Plugin\Field\FieldWidget\SvgImageWidget::formMultipleElements()
  2. 1.x src/Plugin/Field/FieldWidget/SvgImageWidget.php \Drupal\svg_image\Plugin\Field\FieldWidget\SvgImageWidget::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/SvgImageWidget.php, line 155

Class

SvgImageWidget
Override plugin of the 'image_image' widget.

Namespace

Drupal\svg_image\Plugin\Field\FieldWidget

Code

protected function formMultipleElements(FieldItemListInterface $items, array &$form, FormStateInterface $formState) {
  $elements = parent::formMultipleElements($items, $form, $formState);
  $cardinality = $this->fieldDefinition
    ->getFieldStorageDefinition()
    ->getCardinality();
  $fileUploadHelp = [
    '#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'])) {
      $fileUploadHelp['#description'] = $this
        ->getFilteredDescription();
      $elements[0]['#description'] = $this->renderer
        ->renderPlain($fileUploadHelp);
    }
  }
  else {
    $elements['#file_upload_description'] = $fileUploadHelp;
  }
  return $elements;
}