diff --git a/taxonomy_menu.admin.inc b/taxonomy_menu.admin.inc index 804d582..ca8bd66 100644 --- a/taxonomy_menu.admin.inc +++ b/taxonomy_menu.admin.inc @@ -180,71 +180,59 @@ function taxonomy_menu_form_taxonomy_form_vocabulary(&$form, &$form_state) { * @see taxonomy_menu_form_taxonomy_form_vocabulary() */ function taxonomy_menu_vocab_submit($form, &$form_state) { - // Initialize flag variables for updating/rebuilding the taxonomy menu. - $update = FALSE; - $insert = FALSE; - - $menu_disabled = $form_state['values']['taxonomy_menu']['vocab_parent'] == '0'; $vid = $form_state['values']['vid']; + // Flatten array of submitted settings so we can save them more easily. $flatten_settings = _taxonomy_menu_flatten_form_settings($form_state['values']['taxonomy_menu']); - // If menu location has been set to disabled, don't throw notices by trying to - // explode 0 with ':' . - $vocab_parent = $flatten_settings['vocab_parent']; - $menu_location = ($vocab_parent == '0') ? '0:0' : $vocab_parent; - list($flatten_settings['vocab_menu'], $flatten_settings['vocab_parent']) = explode(':', $menu_location); - - // Get all the settings that have changed since the last submit. If some of - // them have changed, then update the taxonomy menu. - $changed_settings = array(); - if ($vid != 0) { - $changed_settings = _taxonomy_menu_get_changed_settings($flatten_settings, $vid); - if (!empty($changed_settings)) { - $update = TRUE; - // Options have changed, save/update the menu. - $menu_change = in_array('vocab_parent', $changed_settings) || in_array('vocab_menu', $changed_settings); - if ($menu_change) { - // Menu location has changed. - if ($menu_disabled) { - // Menu was disabled, delete all existing menu links. - taxonomy_menu_menu_links_delete($vid); - } - else { - // Menu location has been changed and is not disabled. - $old_vocab_parent = taxonomy_menu_variable_get('vocab_parent', $vid, '0'); - $old_vocab_menu = taxonomy_menu_variable_get('vocab_menu', $vid, '0'); - if ($old_vocab_menu == '0' && $old_vocab_parent == '0') { - // Menu was disabled before, create new links. - $insert = TRUE; - } - } - // Do a full menu rebuild in case we have removed or moved the menu. - variable_set('menu_rebuild_needed', TRUE); - } - } - elseif (!$flatten_settings['rebuild']) { - // Display a notification message. Nothing to update. - drupal_set_message(t('The Taxonomy menu was not updated. Nothing to update.'), 'status'); - } + // If menu location has been set to disabled, normalize to : = '0:0'. + if ($flatten_settings['vocab_parent'] == '0') { + $menu_location = '0:0'; + $flatten_settings['vocab_menu'] = '0'; + $flatten_settings['vocab_parent'] = '0'; + } + else { + $menu_location = $flatten_settings['vocab_parent']; + list($flatten_settings['vocab_menu'], $flatten_settings['vocab_parent']) = explode(':', $menu_location); } - // Save all the submitted values. + $old_vocab_menu = taxonomy_menu_variable_get('vocab_menu', $vid, '0'); + $old_vocab_parent = taxonomy_menu_variable_get('vocab_parent', $vid, '0'); + $old_menu_location = $old_vocab_menu . ':' . $old_vocab_parent; + + // If vocabulary is and was not activated, skip all processing. + if ($menu_location == '0:0' && $old_menu_location == '0:0') { + return; + } + + $menu_changed = ($menu_location != $old_menu_location); + $menu_disabled = ($menu_location == '0:0'); + // Check if the user explicitly wants to rebuild the menu. Do not save this setting. + $menu_rebuild = $flatten_settings['rebuild']; + unset($flatten_settings['rebuild']); + + $changed_settings = _taxonomy_menu_get_changed_settings($flatten_settings, $vid); + + // Save all submitted values. _taxonomy_menu_save_form_settings($flatten_settings, $vid); - // We don't need to check for the disabled menu location because the rebuild - // function will delete the taxonomy menu in all cases. - if ($flatten_settings['rebuild']) { + // Options have changed, save/update the menu. + if ($menu_disabled || $menu_rebuild) { taxonomy_menu_rebuild($vid); } - elseif ($insert) { - // Update only menu links that are available in taxonomy_menu table. + elseif ($menu_changed) { taxonomy_menu_menu_links_insert($vid); } - elseif ($update) { - // Update only menu links that are available in taxonomy_menu table. + elseif (!empty($changed_settings)) { + // Menu location did not change, but some settings have. taxonomy_menu_menu_links_update($vid); } + else { + // Display a notification message. Nothing to update. + drupal_set_message(t('The Taxonomy menu was not updated. Nothing to update.'), 'status'); + } + + variable_set('menu_rebuild_needed', TRUE); } /** @@ -308,23 +296,24 @@ function taxonomy_menu_get_vocabulary_settings() { * Implements hook_taxonomy_menu_vocabulary_settings() */ function taxonomy_menu_taxonomy_menu_vocabulary_settings() { + // Make sure the values are consistent with an empty submitted form. $defaults = array( 'vocab_parent' => 0, 'vocab_menu' => 0, 'path' => 0, - 'sync' => TRUE, - 'rebuild' => FALSE, - 'expanded' => TRUE, - 'term_item_description' => FALSE, - 'display_num' => FALSE, - 'hide_empty_terms' => FALSE, - 'flat' => FALSE, - 'voc_item_description' => FALSE, - 'voc_item' => FALSE, + 'sync' => 1, + 'rebuild' => 0, + 'expanded' => 1, + 'term_item_description' => 0, + 'display_num' => 0, + 'hide_empty_terms' => 0, + 'flat' => 0, + 'voc_item_description' => 0, + 'voc_item' => 0, 'voc_name' => '', //'display_descendants' => FALSE, 'end_all' => FALSE, - 'display_title_attr' => FALSE, + 'display_title_attr' => 0, ); return $defaults;