You are here

function taxonomy_menu_vocab_submit in Taxonomy menu 6.2

Same name and namespace in other branches
  1. 8 taxonomy_menu.admin.inc \taxonomy_menu_vocab_submit()
  2. 7.2 taxonomy_menu.admin.inc \taxonomy_menu_vocab_submit()
  3. 7 taxonomy_menu.module \taxonomy_menu_vocab_submit()

Submit handler for the extra settings added to the taxonomy vocab form.

Check to see if the user has selected a different menu, and only rebuild if this is the case.

1 string reference to 'taxonomy_menu_vocab_submit'
taxonomy_menu_form_alter in ./taxonomy_menu.module
Implementation of hook_form_alter().

File

./taxonomy_menu.module, line 94
It Generates menu links for all selected taxonomy terms

Code

function taxonomy_menu_vocab_submit($form, &$form_state) {
  $vid = $form_state['values']['vid'];
  $changed = FALSE;

  // Split the menu location into menu name and menu item id.
  list($vocab_parent['vocab_menu'], $vocab_parent['vocab_parent']) = explode(':', $form_state['values']['taxonomy_menu']['vocab_parent']);

  // set the menu name and check for changes
  $variable_name = _taxonomy_menu_build_variable('vocab_menu', $vid);
  if (_taxonomy_menu_check_variable($variable_name, $vocab_parent['vocab_menu'])) {
    $changed_menu = TRUE;
  }
  variable_set($variable_name, $vocab_parent['vocab_menu']);

  // set the menu parent item and check for changes
  $variable_name = _taxonomy_menu_build_variable('vocab_parent', $vid);
  if (_taxonomy_menu_check_variable($variable_name, $vocab_parent['vocab_parent'])) {
    $changed_menu = TRUE;
  }
  variable_set($variable_name, $vocab_parent['vocab_parent']);

  // set the path and check for changes
  $variable_name = _taxonomy_menu_build_variable('path', $vid);
  if (_taxonomy_menu_check_variable($variable_name, $form_state['values']['taxonomy_menu']['path'])) {
    $changed_path = TRUE;
  }
  variable_set($variable_name, $form_state['values']['taxonomy_menu']['path']);
  foreach ($form_state['values']['taxonomy_menu']['options'] as $key => $value) {

    // create the variable name
    $variable_name = _taxonomy_menu_build_variable($key, $vid);

    // check to see if the vocab enable options has changed
    if ($key == 'voc_item') {
      if (_taxonomy_menu_check_variable($variable_name, $value)) {
        $change_vocab_item = TRUE;
      }
    }

    // if $changed is alreayd set to true, then don't bother checking any others
    if (!$changed) {

      // check to see if the variable has changed
      if (_taxonomy_menu_check_variable($variable_name, $value)) {
        $changed = TRUE;
      }
    }

    // save variable
    variable_set($variable_name, $value);
  }

  // if the menu hasn't changed and the menu is disabled then do not do anything else
  if ($form_state['values']['taxonomy_menu']['options']['rebuild'] || $changed_menu || !$changed_menu && variable_get('taxonomy_menu_vocab_menu_' . $vid, FALSE) == 0) {

    // rebuild if rebuild is selected, menu has changed or vocabulary option changed
    if ($form_state['values']['taxonomy_menu']['options']['rebuild'] || $changed_menu || $change_vocab_item || $changed_path) {
      $message = _taxonomy_menu_rebuild($vid);
    }
    elseif ($changed && variable_get('taxonomy_menu_vocab_menu_' . $vid, FALSE)) {
      $message = _taxonomy_menu_update_link_items($vid);
    }

    // do a full menu rebuild incase we have removed the menu or moved it between menus
    variable_set('menu_rebuild_needed', TRUE);
    drupal_set_message($message, 'status');
  }
}