You are here

protected function FineImageUpload::formMultipleElements in Fine Image Upload 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldWidget/FineImageUpload.php \Drupal\fiu\Plugin\Field\FieldWidget\FineImageUpload::formMultipleElements()

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

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

Overrides ImageWidget::formMultipleElements

File

src/Plugin/Field/FieldWidget/FineImageUpload.php, line 44

Class

FineImageUpload
Plugin implementation of the 'fine_image' widget.

Namespace

Drupal\fiu\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();
  switch ($cardinality) {
    case FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED:
      $is_multiple = TRUE;
      break;
    default:
      $is_multiple = $cardinality > 1;
      break;
  }
  if ($is_multiple) {
    $elements['#theme'] = 'fine_image_widget_multiple';
  }
  else {
    $elements['#theme'] = 'fine_image_widget_unitary';
  }
  return $elements;
}