You are here

function _webform_edit_file in Webform 6.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.2 components/file.inc \_webform_edit_file()
  4. 7.4 components/file.inc \_webform_edit_file()
  5. 7.3 components/file.inc \_webform_edit_file()

Implements _webform_edit_component().

File

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

Code

function _webform_edit_file($component) {
  $form = array();
  $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 (in KB).'),
    '#size' => 10,
    '#field_suffix' => t('KB'),
    '#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',
    '#title' => t('Allowed file extensions'),
    '#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,
  );
  $form['extra']['savelocation'] = array(
    '#type' => 'textfield',
    '#title' => t('Upload directory'),
    '#default_value' => $component['extra']['savelocation'],
    '#description' => t('Webform uploads are always saved in the site files directory. You may optionally specify a subfolder to store your files.'),
    '#weight' => 3,
    '#field_prefix' => file_directory_path() . '/webform/',
    '#element_validate' => array(
      '_webform_edit_file_check_directory',
    ),
    '#after_build' => array(
      '_webform_edit_file_check_directory',
    ),
  );
  $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;
}