You are here

function _webform_edit_multifile in Webform Multiple File Upload 7

Same name and namespace in other branches
  1. 6 multifile.inc \_webform_edit_multifile()

Implementation of _webform_edit_component().

File

./multifile.inc, line 57
Webform module file component.

Code

function _webform_edit_multifile($component) {
  webform_component_include('file');
  $form = array();
  $form['#theme'] = 'webform_edit_multifile';
  $form['#element_validate'] = array(
    '_webform_edit_multifile_check_directory',
  );
  $form['#after_build'] = array(
    '_webform_edit_multifile_check_directory',
  );
  $options[-1] = t('Unlimited');
  $options += drupal_map_assoc(range(1, 10));
  $form['validation']['max_amount'] = array(
    '#title' => t('File limit'),
    '#description' => t('The number of files the user is allowed to upload per submission with this component.'),
    '#type' => 'select',
    '#options' => $options,
    '#default_value' => $component['extra']['max_amount'],
    '#parents' => array(
      'extra',
      'max_amount',
    ),
  );
  $form['validation']['filtering'] = array(
    '#element_validate' => array(
      '_webform_edit_multifile_filtering_validate',
    ),
    '#parents' => array(
      'extra',
      'filtering',
    ),
  );

  // Find the list of all currently valid extensions.
  $current_types = isset($component['extra']['filtering']['types']) ? $component['extra']['filtering']['types'] : array();
  $types = array(
    'gif',
    'jpg',
    'png',
  );
  $form['validation']['filtering']['types']['webimages'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Web Images'),
    '#options' => drupal_map_assoc($types),
    '#default_value' => array_intersect($current_types, $types),
  );
  $types = array(
    'bmp',
    'eps',
    'tif',
    'pict',
    'psd',
  );
  $form['validation']['filtering']['types']['desktopimages'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Desktop Images'),
    '#options' => drupal_map_assoc($types),
    '#default_value' => array_intersect($current_types, $types),
  );
  $types = array(
    'txt',
    'rtf',
    'html',
    'odf',
    'pdf',
    'doc',
    'docx',
    'ppt',
    'pptx',
    'xls',
    'xlsx',
    'xml',
  );
  $form['validation']['filtering']['types']['documents'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Documents'),
    '#options' => drupal_map_assoc($types),
    '#default_value' => array_intersect($current_types, $types),
  );
  $types = array(
    'avi',
    'mov',
    'mp3',
    'ogg',
    'wav',
  );
  $form['validation']['filtering']['types']['media'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Media'),
    '#options' => drupal_map_assoc($types),
    '#default_value' => array_intersect($current_types, $types),
  );
  $types = array(
    'bz2',
    'dmg',
    'gz',
    'jar',
    'rar',
    'sit',
    'tar',
    'zip',
  );
  $form['validation']['filtering']['types']['archives'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Archives'),
    '#options' => drupal_map_assoc($types),
    '#default_value' => array_intersect($current_types, $types),
  );
  $form['validation']['filtering']['addextensions'] = array(
    '#type' => 'textfield',
    '#title' => t('Additional Extensions'),
    '#default_value' => $component['extra']['filtering']['addextensions'],
    '#description' => t('Enter a list of additional file extensions for this upload field, seperated by commas.<br /> Entered extensions will be appended to checked items above.'),
    '#size' => 60,
    '#weight' => 3,
    '#default_value' => $component['extra']['filtering']['addextensions'],
  );
  $form['validation']['filtering']['size'] = array(
    '#type' => 'textfield',
    '#title' => t('Max Upload Size'),
    '#default_value' => $component['extra']['filtering']['size'],
    '#description' => t('Enter the max file size a user may upload (in KB).'),
    '#size' => 10,
    '#weight' => 3,
    '#field_suffix' => t('KB'),
    '#default_value' => $component['extra']['filtering']['size'],
    '#parents' => array(
      'extra',
      'filtering',
      'size',
    ),
    '#element_validate' => array(
      '_webform_edit_multifile_size_validate',
    ),
  );
  $scheme_options = array();
  foreach (file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE) as $scheme => $stream_wrapper) {
    $scheme_options[$scheme] = $stream_wrapper['name'];
  }
  $form['extra']['scheme'] = array(
    '#type' => 'radios',
    '#title' => t('Upload destination'),
    '#options' => $scheme_options,
    '#default_value' => $component['extra']['scheme'],
    '#description' => t('Private file storage has significantly more overhead than public files, but restricts file access to users who can view submissions.'),
    '#weight' => 4,
    '#access' => count($scheme_options) > 1,
  );
  $form['extra']['directory'] = array(
    '#type' => 'textfield',
    '#title' => t('Upload directory'),
    '#default_value' => $component['extra']['directory'],
    '#description' => t('You may optionally specify a sub-directory to store your files.'),
    '#weight' => 5,
    '#field_prefix' => 'sites/default/files/webform/',
  );
  $form['display']['progress_indicator'] = array(
    '#type' => 'radios',
    '#title' => t('Progress indicator'),
    '#options' => array(
      'throbber' => t('Throbber'),
      'bar' => t('Bar with progress meter'),
    ),
    '#default_value' => $component['extra']['progress_indicator'],
    '#description' => t('The throbber display does not show the status of uploads but takes up less space. The progress bar is helpful for monitoring progress on large uploads.'),
    '#weight' => 16,
    '#access' => file_progress_implementation(),
    '#parents' => array(
      'extra',
      'progress_indicator',
    ),
  );
  $form['display']['width'] = array(
    '#type' => 'textfield',
    '#title' => t('Width'),
    '#default_value' => $component['extra']['width'],
    '#description' => t('Width of the file field.') . ' ' . t('Leaving blank will use the default size.'),
    '#size' => 5,
    '#maxlength' => 10,
    '#weight' => 4,
    '#parents' => array(
      'extra',
      'width',
    ),
  );
  return $form;
}