You are here

function filefield_widget_settings in FileField 5.2

Same name and namespace in other branches
  1. 5 filefield.module \filefield_widget_settings()
  2. 6.3 filefield.module \filefield_widget_settings()
  3. 6.2 filefield.module \filefield_widget_settings()

Implementation of hook_widget_settings().

File

./filefield.module, line 298
Defines a file field type.

Code

function filefield_widget_settings($op, $widget) {
  switch ($op) {
    case 'callbacks':
      return array(
        'default value' => CONTENT_CALLBACK_CUSTOM,
      );
    case 'form':
      $form = array();
      $form['file_extensions'] = array(
        '#type' => 'textfield',
        '#title' => t('Permitted upload file extensions'),
        '#default_value' => isset($widget['file_extensions']) ? $widget['file_extensions'] : 'txt',
        '#size' => 64,
        '#description' => t('Extensions a user can upload to this field. Separate extensions with a space and do not include the leading dot. Leaving this blank will allow users to upload a file with any extension.'),
      );
      $form['file_path'] = array(
        '#type' => 'textfield',
        '#title' => t('File path'),
        '#default_value' => $widget['file_path'] ? $widget['file_path'] : '',
        '#description' => t('Optional subdirectory within the "%dir" directory where files will be stored. Do not include trailing slash.', array(
          '%dir' => variable_get('file_directory_path', 'files'),
        )),
      );
      if (function_exists('token_replace')) {
        $form['file_path']['#description'] .= theme('token_help', 'user');
      }

      // Let extension modules add their settings to the form.
      foreach (module_implements('filefield_widget_settings') as $module) {
        $function = $module . '_filefield_widget_settings';
        $function('form_alter', $widget, $form);
      }
      return $form;
    case 'validate':
      module_invoke_all('filefield_widget_settings', $op, $widget, NULL);
      break;
    case 'save':
      $core_settings = array(
        'file_extensions',
        'file_path',
      );
      $additional_settings = module_invoke_all('filefield_widget_settings', $op, $widget, NULL);
      return array_merge($core_settings, $additional_settings);
  }
}