You are here

function content_taxonomy_field_settings in Content Taxonomy 5

Same name and namespace in other branches
  1. 6.2 content_taxonomy.module \content_taxonomy_field_settings()
  2. 6 content_taxonomy.module \content_taxonomy_field_settings()

Implementation of hook_field_settings().

File

./content_taxonomy.module, line 31
Defines a field type for referencing a taxonomy term.

Code

function content_taxonomy_field_settings($op, $field) {
  switch ($op) {
    case 'form':
      $form = array();
      $form['save'] = array(
        '#type' => 'radios',
        '#title' => t('Save options'),
        '#options' => array(
          'tag' => t('Save as tag'),
          'cck_table' => t('Save in cck table'),
          'both' => t('Both'),
        ),
        '#default_value' => isset($field['save']) ? $field['save'] : 'tag',
      );
      $form['vocabulary'] = array(
        '#type' => 'fieldset',
        '#title' => t('Specify terms to show'),
        '#collapsible' => TRUE,
      );
      $options_term = array();
      $options_voc = array();
      $options_term[0] = '---';
      foreach (taxonomy_get_vocabularies() as $voc) {
        $options_voc[$voc->vid] = $voc->name;
        foreach (taxonomy_get_tree($voc->vid) as $term) {
          $options_term[$voc->name][$term->tid] = str_repeat('- ', $term->depth) . $term->name;
        }
      }
      $form['vocabulary']['vid'] = array(
        '#title' => t('Vocabulary'),
        '#type' => 'select',
        '#default_value' => isset($field['vid']) ? $field['vid'] : 0,
        '#options' => $options_voc,
      );
      $form['vocabulary']['tid'] = array(
        '#title' => t('Terms'),
        '#type' => 'select',
        '#default_value' => isset($field['tid']) ? $field['tid'] : 0,
        '#options' => $options_term,
      );
      $form['vocabulary']['depth'] = array(
        '#type' => 'textfield',
        '#title' => t('Depth of taxonomy tree'),
        '#default_value' => isset($field['depth']) ? $field['depth'] : 1,
        '#description' => t('leave blank for unlimited depth'),
      );
      return $form;
    case 'save':
      return array(
        'save',
        'vid',
        'tid',
        'depth',
      );
    case 'database columns':
      if (isset($field['save']) && $field['save'] != 'tag') {
        return array(
          'value' => array(
            'type' => 'int',
            'not null' => TRUE,
            'default' => 0,
            'sortable' => TRUE,
          ),
        );
      }
  }
}