You are here

function content_taxonomy_field_settings in Content Taxonomy 6

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

Implementation of hook_field_settings().

File

./content_taxonomy.module, line 61
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_term_node'] = array(
        '#type' => 'checkbox',
        '#title' => t('Save values additionally to the core taxonomy system (into the \'term_node\' table).'),
        '#default_value' => is_numeric($field['save_term_node']) ? $field['save_term_node'] : 0,
        '#description' => t('If this option is set, saving of terms is additionally handled by the taxonomy module. So saved terms from Content Taxonomy fields will appear as any other terms saved by the core taxonomy module. Set this option if you are using any other taxonomy application, like tagadelic. Otherwise terms are only saved in the cck tables and can only be accessed via the node or a view'),
      );
      $options_voc = array();
      foreach (taxonomy_get_vocabularies() as $voc) {
        _content_taxonomy_localize_vocabulary($voc);
        $options_voc[$voc->vid] = $voc->name;
      }
      $form['vid'] = array(
        '#title' => t('Vocabulary'),
        '#type' => 'select',
        '#default_value' => is_numeric($field['vid']) ? $field['vid'] : 0,
        '#options' => $options_voc,
        '#description' => t('Terms of the selected vocabulary get exposed to the field'),
      );
      $form['hierarchical_vocabulary'] = array(
        '#type' => 'fieldset',
        '#title' => t('Advanced settings for hierarchical vocabularies'),
        '#collapsible' => TRUE,
      );
      $form['hierarchical_vocabulary']['parent'] = array(
        '#title' => t('Parent Term'),
        '#type' => 'select',
        '#default_value' => is_numeric($field['parent']) ? $field['parent'] : 0,
        '#options' => _content_taxonomy_get_all_terms(),
        '#description' => t('If any term is selected here, only child terms of the selected are going to be exposed the field. Otherwise the whole vocabulary selected above'),
      );
      $form['hierarchical_vocabulary']['parent_php_code_fieldset'] = array(
        '#type' => 'fieldset',
        '#title' => t('Advanced PHP code'),
        '#collapsible' => TRUE,
        '#collapsed' => empty($field['parent_php_code']),
      );
      $form['hierarchical_vocabulary']['parent_php_code_fieldset']['parent_php_code'] = array(
        '#title' => t('PHP Code for selecting the parent term'),
        '#type' => 'textarea',
        '#default_value' => !empty($field['parent_php_code']) ? $field['parent_php_code'] : '',
        '#rows' => 3,
        '#description' => t('Advanced usage only: PHP code that returns the parent term ID. Should not include <?php ?> delimiters. If this field is filled out, the ID returned by this code will override the selected parent above.'),
      );
      $form['hierarchical_vocabulary']['depth'] = array(
        '#type' => 'textfield',
        '#title' => t('Depth of taxonomy tree'),
        '#default_value' => is_numeric($field['depth']) ? $field['depth'] : '',
        '#description' => t('By setting a numeric value, the depth of the hierarchy shown can be limited. Leave this field blank to show the whole hierarchy.'),
      );
      return $form;
    case 'save':
      return array(
        'save_term_node',
        'vid',
        'parent',
        'parent_php_code',
        'depth',
      );
    case 'database columns':
      return array(
        'value' => array(
          'type' => 'int',
          'not null' => FALSE,
          'sortable' => FALSE,
        ),
      );
    case 'views data':
      $data = content_views_field_views_data($field);
      $table_alias = content_views_tablename($field);

      // Add a relation to the taxonomy term table.
      $data[$table_alias][$field['field_name'] . '_value']['relationship'] = array(
        'handler' => 'views_handler_relationship',
        'base' => 'term_data',
        'field' => 'tid',
        'label' => t('@field-title term', array(
          '@field-title' => check_plain(t($field['widget']['label'])),
        )),
      );

      // Swap the filter handler to the 'in' operator.
      $data[$table_alias][$field['field_name'] . '_value']['filter']['handler'] = 'content_taxonomy_handler_filter_many_to_one';
      return $data;
  }
}