You are here

function _webform_edit_file in Webform 5.2

Same name and namespace in other branches
  1. 5 components/file.inc \_webform_edit_file()
  2. 6.3 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()

Create a set of form items to be displayed on the form for editing this component. Use care naming the form items, as this correlates directly to the database schema. The component "Name" and "Description" fields are added to every component type and are not necessary to specify here (although they may be overridden if desired).

Return value

An array of form items to be displayed on the edit component page

File

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

Code

function _webform_edit_file($currfield) {
  $edit_fields = array();
  $edit_fields['#theme'] = 'webform_edit_file';
  $edit_fields['extra']['filtering'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#title' => t('Upload Filtering'),
    '#description' => t('Select the types of uploads you would like to allow.'),
    '#validate' => array(
      '_webform_edit_file_filtering_validate' => array(),
    ),
  );

  // Find the list of all currently valid extensions.
  $current_types = isset($currfield['extra']['filtering']['types']) ? $currfield['extra']['filtering']['types'] : array();
  $types = array(
    'gif',
    'jpg',
    'png',
  );
  $edit_fields['extra']['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',
  );
  $edit_fields['extra']['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',
    'ppt',
    'xls',
    'xml',
  );
  $edit_fields['extra']['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',
  );
  $edit_fields['extra']['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',
  );
  $edit_fields['extra']['filtering']['types']['archives'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Archives'),
    '#options' => drupal_map_assoc($types),
    '#default_value' => array_intersect($current_types, $types),
  );
  $edit_fields['extra']['filtering']['addextensions'] = array(
    '#type' => 'textfield',
    '#title' => t('Additional Extensions'),
    '#default_value' => $currfield['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' => $currfield['extra']['filtering']['addextensions'],
  );
  $edit_fields['extra']['filtering']['size'] = array(
    '#type' => 'textfield',
    '#title' => t('Max Upload Size'),
    '#default_value' => $currfield['extra']['filtering']['size'],
    '#description' => t('Enter the max file size a user may upload (in KB).'),
    '#size' => 10,
    '#weight' => 3,
    '#default_value' => $currfield['extra']['filtering']['size'],
  );
  $edit_fields['extra']['savelocation'] = array(
    '#type' => 'textfield',
    '#title' => t('Upload Directory'),
    '#default_value' => $currfield['extra']['savelocation'],
    '#description' => '<div style="display: block">' . t('Webform uploads are always saved in the site files directory. You may optionally specify a subfolder to store your files.') . '</div>',
    '#weight' => 3,
    '#validate' => array(
      '_webform_edit_file_check_directory' => array(),
    ),
    '#after_build' => array(
      '_webform_edit_file_check_directory',
    ),
  );
  $edit_fields['extra']['width'] = array(
    '#type' => 'textfield',
    '#title' => t('Width'),
    '#default_value' => $currfield['extra']['width'],
    '#description' => t('Width of the file field.') . ' ' . t('Leaving blank will use the default size.'),
    '#size' => 5,
    '#maxlength' => 10,
    '#weight' => 4,
  );
  return $edit_fields;
}