function ImageWidget::formMultipleElements

Same name in other branches
  1. 8.9.x core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php \Drupal\image\Plugin\Field\FieldWidget\ImageWidget::formMultipleElements()
  2. 10 core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php \Drupal\image\Plugin\Field\FieldWidget\ImageWidget::formMultipleElements()
  3. 11.x core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php \Drupal\image\Plugin\Field\FieldWidget\ImageWidget::formMultipleElements()

Overrides \Drupal\file\Plugin\Field\FieldWidget\FileWidget::formMultipleElements().

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

Overrides FileWidget::formMultipleElements

File

core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php, line 116

Class

ImageWidget
Plugin implementation of the 'image_image' widget.

Namespace

Drupal\image\Plugin\Field\FieldWidget

Code

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'] = \Drupal::service('renderer')->renderPlain($file_upload_help);
        }
    }
    else {
        $elements['#file_upload_description'] = $file_upload_help;
    }
    return $elements;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.