You are here

public static function S3CorsManagedFileHelper::postProcessCors in Flysystem - S3 8

Same name and namespace in other branches
  1. 2.0.x src/S3CorsManagedFileHelper.php \Drupal\flysystem_s3\S3CorsManagedFileHelper::postProcessCors()

Function postProcessCors add data attributes that are used flysystem_s3.js.

File

src/S3CorsManagedFileHelper.php, line 59

Class

S3CorsManagedFileHelper
Helper for altering and processing a managed_file element for CORS upload.

Namespace

Drupal\flysystem_s3

Code

public static function postProcessCors(array &$element) {
  if (!empty($element['#s3_cors'])) {

    // Add data attributes that are used by flysystem_s3.js to submit the
    // AJAX request to sign the upload.
    $element['upload']['#attributes']['data-s3-acl'] = $element['#s3_acl'];
    $element['upload']['#attributes']['data-s3-destination'] = $element['#upload_location'];
    $element['upload']['#attributes']['data-flysystem-s3-cors'] = TRUE;

    // Add the valid extensions as data attributes.
    if (!empty($element['#upload_validators']['file_validate_extensions'][0])) {
      $element['upload']['#attributes']['data-valid-extensions'] = $element['#upload_validators']['file_validate_extensions'][0];
    }
  }
  return $element;
}