You are here

function spaces_taxonomy_settings in Spaces 7

Same name and namespace in other branches
  1. 6.3 spaces_taxonomy/spaces_taxonomy.module \spaces_taxonomy_settings()
  2. 6 spaces_taxonomy/spaces_taxonomy.module \spaces_taxonomy_settings()
  3. 6.2 spaces_taxonomy/spaces_taxonomy.module \spaces_taxonomy_settings()
  4. 7.3 spaces_taxonomy/spaces_taxonomy.module \spaces_taxonomy_settings()

Spaces Taxonomy settings form.

A node can only belong to one space, so only provide options for the Space vocabulary that are single valued. This means that:

1) In various hook_form_alters we will need to disable the cardinality selection on term references that are for this specified Spaces vocab. 2) On any term reference field in a node form, do not allow them to change the value of this vocabulary once it has been selected.

1 string reference to 'spaces_taxonomy_settings'
spaces_taxonomy_menu in spaces_taxonomy/spaces_taxonomy.module
Implements hook_menu().

File

spaces_taxonomy/spaces_taxonomy.module, line 238
spaces_taxonomy.module

Code

function spaces_taxonomy_settings($form, &$form_state) {
  $form = array();

  // Collect an array of valid vocab options
  $vocabs = array(
    0 => '---',
  );
  foreach (taxonomy_get_vocabularies() as $vocab) {
    $vocabs[$vocab->machine_name] = $vocab->name;
  }

  // Get all fields that are taxonomy terms, if they allow more than one
  // term to be selected remove them from this dropdown.
  $fields = field_info_fields();
  foreach ($fields as $name => $field) {
    if ($field['type'] == 'taxonomy_term_reference' && $field['cardinality'] != 1) {
      unset($vocabs[$field['settings']['allowed_values'][0]['vocabulary']]);
    }
  }
  $form['spaces_taxonomy_machine_name'] = array(
    '#type' => 'select',
    '#title' => t('Spaces vocabulary'),
    '#description' => t('Choose one of the following vocabularies to enable for use with Spaces.'),
    '#options' => $vocabs,
    '#default_value' => variable_get('spaces_taxonomy_machine_name', 0),
  );
  $form = system_settings_form($form);
  return $form;
}