You are here

function _webform_edit_file in Webform 7.3

Same name and namespace in other branches
  1. 5.2 components/file.inc \_webform_edit_file()
  2. 5 components/file.inc \_webform_edit_file()
  3. 6.3 components/file.inc \_webform_edit_file()
  4. 6.2 components/file.inc \_webform_edit_file()
  5. 7.4 components/file.inc \_webform_edit_file()

Implements _webform_edit_component().

File

components/file.inc, line 54
Webform module file component.

Code

function _webform_edit_file($component) {
  $form = array();
  $form['#element_validate'] = array(
    '_webform_edit_file_check_directory',
  );
  $form['#after_build'] = array(
    '_webform_edit_file_check_directory',
  );
  $form['validation']['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 such as 2 MB or 800 KB. Your server has a max upload size of @size.', array(
      '@size' => format_size(file_upload_max_size()),
    )),
    '#size' => 10,
    '#parents' => array(
      'extra',
      'filtering',
      'size',
    ),
    '#element_validate' => array(
      '_webform_edit_file_size_validate',
    ),
    '#weight' => 1,
  );
  $form['validation']['extensions'] = array(
    '#element_validate' => array(
      '_webform_edit_file_extensions_validate',
    ),
    '#parents' => array(
      'extra',
      'filtering',
    ),
    '#theme' => 'webform_edit_file_extensions',
    '#theme_wrappers' => array(
      'form_element',
    ),
    '#title' => t('Allowed file extensions'),
    '#attached' => array(
      'js' => array(
        drupal_get_path('module', 'webform') . '/js/webform-admin.js',
      ),
      'css' => array(
        drupal_get_path('module', 'webform') . '/css/webform-admin.css',
      ),
    ),
    '#weight' => 2,
  );

  // 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']['extensions']['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']['extensions']['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']['extensions']['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']['extensions']['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']['extensions']['types']['archives'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Archives'),
    '#options' => drupal_map_assoc($types),
    '#default_value' => array_intersect($current_types, $types),
  );
  $form['validation']['extensions']['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, separated by commas.<br /> Entered extensions will be appended to checked items above.'),
    '#size' => 20,
    '#weight' => 3,
  );
  $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' => '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',
    ),
  );

  // TODO: Make managed_file respect the "size" parameter.

  /*
    $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;
}