You are here

function filefield_field_settings in FileField 6.2

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

Implementation of hook_field_settings().

File

./filefield.module, line 183

Code

function filefield_field_settings($op, $field) {
  switch ($op) {
    case 'form':
      $form = array();
      $form['force_list'] = array(
        '#type' => 'checkbox',
        '#title' => t('Always list files'),
        '#default_value' => isset($field['force_list']) ? $field['force_list'] : 0,
        '#description' => t('If enabled, the "List" checkbox will be hidden and files are always shown. Otherwise, the user can choose for each file whether it should be listed or not.'),
      );
      $form['file_formatters'] = array(
        '#title' => t('File display'),
        '#description' => t('Control how files may be displayed in the node view and other views for this field. If no formatters are enabled or are able to handle a file then that specific file will not be displayed. You can also reorder the formatters to specify their priority: the top-most enabled formatter always gets to display the files that it supports, whereas the bottom-most enabled formatter only gets to handle them if the file is not supported by any other other one.'),
        '#weight' => 5,
        '#settings_type' => 'formatters',
      );
      $file_formatter_info = _filefield_file_formatter_info($field);
      $form['file_formatters'] = _filefield_draggable_settings_table($form['file_formatters'], $file_formatter_info, $field['file_formatters'], 'file_formatter_settings');
      return $form;
    case 'validate':

      // Let modules add their own formatter specific validations.
      $file_formatter_info = _filefield_file_formatter_info($field);
      foreach ($file_formatter_info as $file_formatter => $info) {
        $file_formatter_settings = isset($field['file_formatters'][$file_formatter]) ? $field['file_formatters'][$file_formatter] : array();
        module_invoke($info['module'], 'file_formatter_settings_' . $info['name'], 'validate', $file_formatter_settings);
      }
      break;
    case 'save':
      return array(
        'force_list',
        'file_formatters',
      );
    case 'database columns':
      $columns = array(
        'fid' => array(
          'type' => 'int',
          'not null' => FALSE,
        ),
        'description' => array(
          'type' => 'varchar',
          'length' => 255,
          'not null' => FALSE,
          'sortable' => TRUE,
        ),
        'list' => array(
          'type' => 'int',
          'size' => 'tiny',
          'not null' => FALSE,
        ),
        'data' => array(
          'type' => 'text',
          'serialize' => true,
        ),
      );
      return $columns;
    case 'views data':
      $data = content_views_field_views_data($field);
      $db_info = content_database_info($field);
      $table_alias = content_views_tablename($field);

      // Set our own field handler so that we can hook the file formatter
      // configuration table into the options form.
      // By defining the relationship, we already have a "Has file" filter
      // plus all the filters that Views already provides for files.
      // No need for having a filter by ourselves.
      unset($data[$table_alias][$field['field_name'] . '_fid']['filter']);

      // Add a relationship for related file.
      $data[$table_alias][$field['field_name'] . '_fid']['relationship'] = array(
        'base' => 'files',
        'field' => $db_info['columns']['fid']['column'],
        'handler' => 'views_handler_relationship',
      );
      return $data;
  }
}