You are here

function taxonomy_menu_vocab_submit in Taxonomy menu 7

Same name and namespace in other branches
  1. 8 taxonomy_menu.admin.inc \taxonomy_menu_vocab_submit()
  2. 6.2 taxonomy_menu.module \taxonomy_menu_vocab_submit()
  3. 7.2 taxonomy_menu.admin.inc \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
Implements hook_form_alter().

File

./taxonomy_menu.module, line 128
Adds links to taxonomy terms into a menu.

Code

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

    // Menu location has been set to disabled, don't want to throw notices.
    $form_state['values']['taxonomy_menu']['vocab_parent'] = '0:0';
  }

  // 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']);

  // Init flag variables to avoid notices if changes haven't happened.
  $changed_menu = FALSE;
  $change_vocab_item = FALSE;
  $changed_path = FALSE;

  // 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 already 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_build_variable('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_build_variable('vocab_menu', $vid), FALSE)) {
      $message = _taxonomy_menu_update_link_items($vid);
    }

    // Do a full menu rebuild in case we have removed the menu or moved it between menus.
    variable_set('menu_rebuild_needed', TRUE);

    // Only send a message if one has been created.
    if (isset($message) && $message) {

      // $message is sanitized coming out of its source function,
      // No need to reclean it here.
      drupal_set_message($message, 'status');
    }
  }
}