protected function ImageWidget::formMultipleElements

Overrides \Drupal\file\Plugin\field\widget\FileWidget::formMultipleElements().

Special handling for draggable multiple widgets and 'add more' button.

Overrides FileWidget::formMultipleElements

File

drupal/core/modules/image/lib/Drupal/image/Plugin/field/widget/ImageWidget.php, line 59
Contains \Drupal\image\Plugin\field\widget\ImageWidget.

Class

ImageWidget
Plugin implementation of the 'image_image' widget.

Namespace

Drupal\image\Plugin\field\widget

Code

protected function formMultipleElements(EntityInterface $entity, array $items, $langcode, array &$form, array &$form_state) {
  $elements = parent::formMultipleElements($entity, $items, $langcode, $form, $form_state);
  if ($this->field['cardinality'] == 1) {

    // If there's only one field, return it as delta 0.
    if (empty($elements[0]['#default_value']['fid'])) {
      $elements[0]['#description'] = theme('file_upload_help', array(
        'description' => $this->instance['description'],
        'upload_validators' => $elements[0]['#upload_validators'],
      ));
    }
  }
  else {
    $elements['#file_upload_description'] = theme('file_upload_help', array(
      'upload_validators' => $elements[0]['#upload_validators'],
    ));
  }
  return $elements;
}