You are here

function dragndrop_upload_dropzone_add in Drag & Drop Upload 7

Add a dropzone.

Parameters

string $selector: A jQuery selector of the element that must become a dropzone.

array $settings: Settings for the dropzone.

2 calls to dragndrop_upload_dropzone_add()
dragndrop_upload in ./dragndrop_upload.module
A callback to process '#attached' setting of the elements to add a dropzone.
dragndrop_upload_example_element in modules/dragndrop_upload_example/dragndrop_upload_example.module
Form callback for the 'dragndrop-upload/example-element'.

File

./dragndrop_upload.module, line 85
Provides API for drag & drop upload features.

Code

function dragndrop_upload_dropzone_add($selector, array $settings) {
  $js_added =& drupal_static(__FUNCTION__, array());
  if (!$js_added) {
    drupal_add_library('system', 'drupal.ajax');
    $path = drupal_get_path('module', 'dragndrop_upload');
    $options = array(
      'group' => JS_LIBRARY,
    );
    drupal_add_js($path . '/js/dragndrop-upload.formdata.js', $options);
    drupal_add_js($path . '/js/dragndrop-upload.dnd.js', $options);
    drupal_add_js($path . '/js/dragndrop-upload.js');
    $js_added = TRUE;
  }

  // Set default URL in DnD settings if callback is provided.
  if (!empty($settings['callback'])) {
    $id = drupal_hash_base64(uniqid(mt_rand(), TRUE) . mt_rand());
    $settings['url'] = url('system/dragndrop/' . $id);
    dragndrop_upload_cache_set($id, $settings);
  }

  // Give an ability to alter dropzone settings.
  drupal_alter('dragndrop_upload_dropzone', $settings, $selector);
  $settings += array(
    'selector' => $selector,
    'validators' => array(),
    'cardinality' => 1,
    'multiupload' => 0,
    'name' => '',
    'url' => '',
    'errorsInfo' => dragndrop_upload_errors_info(),
  );

  // Add Drupal setting in this way in order to escape from settings
  // duplicating.
  $javascript =& drupal_static('drupal_add_js', array());
  $javascript['settings']['data'][__FUNCTION__]['dragndropUpload'][$selector] = $settings;
}