You are here

function location_taxonomy_form_alter in Location 7.5

Same name and namespace in other branches
  1. 6.3 contrib/location_taxonomy/location_taxonomy.module \location_taxonomy_form_alter()
  2. 7.3 contrib/location_taxonomy/location_taxonomy.module \location_taxonomy_form_alter()
  3. 7.4 contrib/location_taxonomy/location_taxonomy.module \location_taxonomy_form_alter()

Implements hook_form_alter().

File

contrib/location_taxonomy/location_taxonomy.module, line 32
Associate locations with taxonomy terms.

Code

function location_taxonomy_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'taxonomy_form_vocabulary') {
    $settings = array();
    if (isset($form['vid'])) {
      $settings = variable_get('location_taxonomy_' . $form['vid']['#value'], array());
    }
    $form['location_settings'] = location_settings($settings);
    $form['#submit'][] = 'location_taxonomy_vocabulary_form_submit';
  }
  if ($form_id == 'taxonomy_form_term') {
    $vid = $form['vid']['#value'];
    $settings = variable_get('location_taxonomy_' . $vid, FALSE);
    if ($settings && $settings['multiple']['max']) {
      $locations = array();
      if (isset($form['tid']) && $form['tid']['#value']) {
        $locations = location_load_locations('taxonomy:' . $form['tid']['#value'], 'genid');
      }
      $form['locations'] = location_form($settings, $locations);
      $form['#submit'][] = 'location_taxonomy_term_form_submit';
    }
  }

  // Move the Save and Delete buttons down below our additions.
  if ($form_id == 'taxonomy_form_vocabulary' || $form_id == 'taxonomy_form_term') {
    if (isset($form['submit']['#weight'])) {
      $form['submit']['#weight']++;
    }
    else {
      $form['submit']['#weight'] = 1;
    }
    if (isset($form['delete'])) {
      if (isset($form['delete']['#weight'])) {
        $form['delete']['#weight'] += 2;
      }
      else {
        $form['delete']['#weight'] = 2;
      }
    }
  }
}