You are here

function taxonomy_menu_overview_submit in Taxonomy menu 7

Submit handler, reacting on form ID: taxonomy_overview_terms.

1 string reference to 'taxonomy_menu_overview_submit'
taxonomy_menu_form_alter in ./taxonomy_menu.module
Implements hook_form_alter().

File

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

Code

function taxonomy_menu_overview_submit(&$form, &$form_state) {

  // Only sync if taxonomy_menu is enabled for this vocab and the 'sync'
  // option has been checked.
  // This form has the following flow of buttons:
  // 1. [Save] --> rebuild taxonomy_menu
  // 2. [Reset to alphabetical] --> no rebuild yet
  // 3. [Reset to alphabetical][Reset to alphabetical] --> rebuild
  // 4. [Reset to alphabetical][Cancel] --> no rebuild
  // The code below avoids rebuilding after situation 2.
  if ($form_state['rebuild'] == FALSE && isset($form['#vocabulary']->vid)) {

    // Try to catch the 'Save' button.
    $vid = $form['#vocabulary']->vid;
  }
  elseif ($form_state['rebuild'] == TRUE && isset($form['#vocabulary']->vid)) {

    // Try to catch the 'Reset to alphabetical' button.
    $vid = NULL;
  }
  elseif ($form_state['rebuild'] == FALSE && isset($form['vid']['#value'])) {

    // Try to catch the second (confirming) 'Reset to alphabetical' button.
    $vid = $form['vid']['#value'];
  }
  else {

    // The button [Reset to alphabetical] [Cancel] does not call this page.
    $vid = NULL;
  }
  if (isset($vid)) {
    $menu_name = variable_get(_taxonomy_menu_build_variable('vocab_menu', $vid), 0);
    $sync = variable_get(_taxonomy_menu_build_variable('sync', $vid), 0);
    if ($menu_name && $sync) {

      // Update all menu items (do not rebuild the menu).
      $message = _taxonomy_menu_update_link_items($vid);

      // Report status.
      if (isset($message)) {

        // Message is sanitized coming out of _taxonomy_menu_update_link_items
        // no need to reclean it here.
        drupal_set_message($message, 'status');
      }

      // Rebuild the menu.
      menu_cache_clear($menu_name);
    }
  }
}