You are here

function spaces_taxonomy_form_alter in Spaces 7.3

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

Implements hook_form_alter().

This disables the term selection field on a node for the currently enabled taxonomy space. This is a precaution so that the node is not moved form one space to another.

File

spaces_taxonomy/spaces_taxonomy.module, line 146
spaces_taxonomy.module

Code

function spaces_taxonomy_form_alter(&$form, $form_state, $form_id) {
  if (!empty($form['#node_edit_form']) && arg(0) . '/' . arg(1) != 'admin/content') {
    $vocab = variable_get('spaces_taxonomy_machine_name', 0);
    $space = spaces_get_space();
    if ($vocab && $space && $space->type == 'taxonomy') {

      // Find term fields that are for the current spaces vocab
      $fields = field_info_fields();
      foreach ($fields as $name => $field) {
        if ($field['type'] == 'taxonomy_term_reference' && $vocab == $field['settings']['allowed_values'][0]['vocabulary']) {
          if ($term_field =& $form[$name]) {

            //TODO: Fix this whole 'und' thing
            $term_field['und']['#disabled'] = TRUE;
            $term_field['und']['#default_value'] = $space->id;
            $term_field['und']['#description'] = t('Spaces has disabled this field.  You cannot move a node from one term space to another.');
          }
        }
      }
    }
  }
}