You are here

public static function DropzoneJs::processDropzoneJs in DropzoneJS 8

Same name and namespace in other branches
  1. 8.2 src/Element/DropzoneJs.php \Drupal\dropzonejs\Element\DropzoneJs::processDropzoneJs()

Processes a dropzone upload element.

File

src/Element/DropzoneJs.php, line 87

Class

DropzoneJs
Provides a DropzoneJS atop of the file element.

Namespace

Drupal\dropzonejs\Element

Code

public static function processDropzoneJs(&$element, FormStateInterface $form_state, &$complete_form) {
  $element['uploaded_files'] = [
    '#type' => 'hidden',
    // @todo Handle defaults.
    '#default_value' => '',
    // If we send a url with a token through drupalSettings the placeholder
    // doesn't get replaced, because the actual scripts markup is not there
    // yet. So we pass this information through a data attribute.
    '#attributes' => [
      'data-upload-path' => Url::fromRoute('dropzonejs.upload')
        ->toString(),
    ],
  ];
  if (empty($element['#max_filesize'])) {
    $element['#max_filesize'] = file_upload_max_size();
  }

  // Set #max_files to NULL (explicitly unlimited) if #max_files is not
  // specified.
  if (empty($element['#max_files'])) {
    $element['#max_files'] = NULL;
  }
  if (!\Drupal::currentUser()
    ->hasPermission('dropzone upload files')) {
    $element['#access'] = FALSE;
    drupal_set_message(new TranslatableMarkup("You don't have sufficent permissions to use the DropzoneJS uploader. Contact your system administrator"), 'warning');
  }
  return $element;
}