You are here

function nat_form_alter in Node Auto Term [NAT] 5

Same name and namespace in other branches
  1. 6.2 nat.module \nat_form_alter()
  2. 6 nat.module \nat_form_alter()
  3. 7.2 nat.module \nat_form_alter()
  4. 7 nat.module \nat_form_alter()

Implementation of hook_form_alter().

File

./nat.module, line 131
NAT - node auto term - is a helper module that automatically creates a term using the same title as a node.

Code

function nat_form_alter($form_id, &$form) {
  if ($form['#id'] == 'node-form') {
    $config = _nat_variable_get();
    foreach ($config['types'] as $type => $associations) {
      if (count($associations) && $form_id == $type . '_node_form' && $config['related'][$type] == 1) {
        $form['nat'] = array(
          '#type' => 'fieldset',
          '#title' => t('Term information'),
          '#tree' => TRUE,
          '#weight' => -2,
          '#collapsible' => TRUE,
          '#collapsed' => FALSE,
        );

        // Related terms.
        if (isset($form['#node']->nat)) {
          foreach ($form['#node']->nat as $term) {
            $terms[$term->vid] = $term->tid;
          }
        }
        foreach ($associations as $vocabulary_id) {
          $vocabulary = taxonomy_get_vocabulary($vocabulary_id);
          if ($vocabulary->relations) {
            $form['nat']['related'][$vocabulary_id] = _taxonomy_term_select(t('Related !terms', array(
              '!terms' => $vocabulary->name,
            )), 'relations', array_keys(taxonomy_get_related($terms[$vocabulary_id])), $vocabulary_id, NULL, 1, '<' . t('none') . '>', array(
              $term->tid,
            ));
          }
        }

        // Synonyms.
        $form['nat']['synonyms'] = array(
          '#type' => 'textarea',
          '#title' => t('Synonyms'),
          '#default_value' => implode("\n", taxonomy_get_synonyms($term->tid)),
          '#description' => t('Synonyms of this term; one synonym per line.'),
        );

        // This can only match once, so we just break the foreach.
        break;
      }
    }
  }
}