1 file.field.inc file_field_instance_settings_form($field, $instance)

Implements hook_field_instance_settings_form().

File

core/modules/file/file.field.inc, line 79
Field module functionality for the File module.

Code

function file_field_instance_settings_form($field, $instance) {
  $settings = $instance['settings'];

  $form['file_directory'] = array(
    '#type' => 'textfield',
    '#title' => t('File directory'),
    '#default_value' => $settings['file_directory'],
    '#field_prefix' => $field['settings']['uri_scheme'] == 'public' ? config_get('system.core', 'file_public_path') . '/' : '',
    '#description' => t('Optional subdirectory within the upload destination where files will be stored. Do not include preceding or trailing slashes.'),
    '#element_validate' => array('_file_generic_settings_file_directory_validate'),
    '#weight' => 3,
  );

  // Make the extension list a little more human-friendly by comma-separation.
  $extensions = str_replace(' ', ', ', $settings['file_extensions']);
  $form['file_extensions'] = array(
    '#type' => 'textfield',
    '#title' => t('Allowed file extensions'),
    '#default_value' => $extensions,
    '#description' => t('Separate extensions with a space or comma and do not include the leading dot.'),
    '#element_validate' => array('_file_generic_settings_extensions'),
    '#weight' => 1,
    '#maxlength' => 512,
    // By making this field required, we prevent a potential security issue
    // that would allow files of any type to be uploaded.
    '#required' => TRUE,
  );

  $form['max_filesize'] = array(
    '#type' => 'textfield',
    '#title' => t('Maximum upload size'),
    '#default_value' => $settings['max_filesize'],
    '#description' => t('Enter a value like "512" (bytes), "80 KB" (kilobytes) or "50 MB" (megabytes) in order to restrict the allowed file size. If left empty the file sizes will be limited only by PHP\'s maximum post and file upload sizes (current limit <strong>%limit</strong>).', array('%limit' => format_size(file_upload_max_size()))),
    '#size' => 10,
    '#element_validate' => array('_file_generic_settings_max_filesize'),
    '#weight' => 5,
  );

  $form['description_field'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show <em>File display title</em> field'),
    '#description' => t('This text will be used in links to the uploaded file. When not available, the filename will be used.'),
    '#default_value' => isset($settings['description_field']) ? $settings['description_field'] : '',
    '#parents' => array('instance', 'settings', 'description_field'),
    '#weight' => 11,
  );

  // Check that this widget is supported.
  if (array_key_exists($instance['widget']['type'], file_field_inline_fields_widgets())) {
    $widget = $instance['widget'];
    $settings = $widget['settings'];

    $description = t('These options allow extended file fields to be edited inline after a file has been uploaded into this field. The fields displayed will depend upon the type of file uploaded. Setting or changing a value in these fields will affect the file everywhere throughout the site. More fields may be added in the <a href="!file-types">File types configuration</a>.', array('!file-types' => url('admin/structure/file-types')));
    if ($instance['entity_type'] == 'file') {
      $description = t('This option is <strong>disabled</strong>. Inline file fields are disabled for file fields attached to a <em>file type</em>.');
    }

    $form['inline_fields'] = array(
      '#type' => 'fieldset',
      '#title' => t('Inline fields'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#description' => $description,
      '#weight' => 30,
      '#parents' => array('instance', 'widget', 'settings'),
    );

    $form['inline_fields']['inline_fields_option'] = array(
      '#type' => 'select',
      '#title' => t('Inline fields option'),
      '#options' => array(
        FILE_INLINE_FIELDS_ALL => t('All available fields'),
        FILE_INLINE_FIELDS_SOME => t('Only specific fields'),
        FILE_INLINE_FIELDS_NONE => t('None (disabled)'),
      ),
      '#default_value' => isset($settings['inline_fields_option']) ? $settings['inline_fields_option'] : 0,
      '#weight' => -9,
      '#disabled' => ($instance['entity_type'] == 'file'),
    );

    $options = array();
    $option_occurences = array();
    $instance_info = field_info_instances('file');
    $bundle_info = field_info_bundles('file');
    foreach ($instance_info as $bundle_name => $bundle_fields) {
      foreach ($bundle_fields as $field_name => $field_instance) {
        $options[$field_name] = $field_instance['label'];
        $option_occurences[$field_name][] = $bundle_info[$bundle_name]['label'];
      }
    }

    // Add bundle information to each field name.
    foreach ($options as $field_name => $field_label) {
      $options[$field_name] .= ' (' . implode(',', $option_occurences[$field_name]) . ')';
    }

    $form['inline_fields']['inline_fields'] = array(
      '#title' => t('Included inline fields'),
      '#type' => 'checkboxes',
      '#options' => $options,
      '#default_value' => isset($settings['inline_fields']) ? $settings['inline_fields'] : array(),
      '#weight' => 0,
      '#states' => array(
        'visible' => array(
          'select[name="instance[widget][settings][inline_fields_option]"]' => array('value' => 2),
        ),
      ),
      '#element_validate' => array('_file_generic_settings_inline_fields_validate'),
    );
  }

  return $form;
}