You are here

function _webform_edit_file in Webform 7.4

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.3 components/file.inc \_webform_edit_file()

Implements _webform_edit_component().

File

components/file.inc, line 66
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',
      ),
    ),
    '#type' => 'webform_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',
    'pdf',
    'doc',
    'docx',
    'odt',
    'ppt',
    'pptx',
    'odp',
    'xls',
    'xlsx',
    'ods',
    '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('Public files upload destination is dangerous for forms that are available to anonymous and/or untrusted users. For more information, see <a href="@psa">DRUPAL-PSA-2016-003</a>.', array(
      '@psa' => 'https://www.drupal.org/psa-2016-003',
    )),
    '#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.') . ' ' . theme('webform_token_help'),
    '#weight' => 5,
    '#field_prefix' => 'webform/',
  );
  $form['extra']['rename'] = array(
    '#type' => 'textfield',
    '#title' => t('Rename files'),
    '#default_value' => $component['extra']['rename'],
    '#description' => t('You may optionally use tokens to create a pattern used to rename files upon submission. Omit the extension; it will be added automatically.') . ' ' . theme('webform_token_help', array(
      'groups' => array(
        'node',
        'submission',
      ),
    )),
    '#weight' => 6,
    '#element_validate' => array(
      '_webform_edit_file_rename_validate',
    ),
    '#access' => webform_variable_get('webform_token_access'),
  );
  $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',
    ),
  );
  return $form;
}