You are here

function xmlsitemap_term_form_alter in XML sitemap 5.2

Same name and namespace in other branches
  1. 5 xmlsitemap_term/xmlsitemap_term.module \xmlsitemap_term_form_alter()

Implementation of hook_form_alter().

File

xmlsitemap_term/xmlsitemap_term.module, line 20
Adds taxonomy terms to the sitemap.

Code

function xmlsitemap_term_form_alter($form_id, &$form) {
  if (isset($form['type']['#value']) && $form_id == $form['type']['#value'] . '_node_form') {
    $node = $form['#node'];
    if (isset($form['type']) && isset($node->nid)) {
      if (isset($node->taxonomy)) {
        $terms = $node->taxonomy;
      }
      else {
        $terms = taxonomy_node_get_terms($node->nid);
      }
      $form['xmlsitemap_term_taxonomy'] = array(
        '#type' => 'value',
        '#value' => $terms,
      );
    }
  }
  else {
    switch ($form_id) {
      case 'taxonomy_form_term':
        $priority = isset($form['tid']['#value']) ? db_result(db_query("SELECT priority_override FROM {xmlsitemap_term} WHERE tid = %d", $form['tid']['#value'])) : 'NULL';
        if ($priority === FALSE) {
          $priority = 'NULL';
        }
        if (user_access('override term priority')) {
          $options = xmlsitemap_priority_options('both');
          $default = variable_get('xmlsitemap_term_vocabulary_priority_' . $form['vid']['#value'], '0.5');
          $form['xmlsitemap_term_priority'] = array(
            '#type' => 'select',
            '#title' => t('sitemap priority'),
            '#default_value' => $priority,
            '#options' => $options,
            '#description' => t('The default priority is %priority.', array(
              '%priority' => $options[$default],
            )),
          );
          $form['submit']['#weight'] = 1;
          $form['delete']['#weight'] = 1;
        }
        else {
          $form['xmlsitemap_term_priority'] = array(
            '#type' => 'value',
            '#value' => $priority,
          );
        }
        break;
      case 'taxonomy_form_vocabulary':
        $form['xmlsitemap_term_vocabulary_priority'] = array(
          '#type' => 'select',
          '#title' => t('sitemap priority'),
          '#default_value' => variable_get('xmlsitemap_term_vocabulary_priority_' . $form['vid']['#value'], 0.5),
          '#options' => xmlsitemap_priority_options('exclude'),
          '#description' => t('This will be the default priority of terms in this vocabulary.'),
        );
        $form['submit']['#weight'] = 1;
        $form['delete']['#weight'] = 1;
        break;
    }
  }
}