Bug 1

Hello, I don't know if someone have the same problem with me~

After adding/updating a new term, this module would insert/update menu link.

But these link don't have any parent value.

They always on the top of menu even they have parent terms.

The only way seems to press the "SAVE Button" in the vocabulary edit page(admin/structure/taxonomy/x/edit).

I tried to find something useful from .module file and then I found 1 code that can solve this problem:

in the function _taxonomy_menu_update_link_items($vid) {:

$args['term']->parents = _taxonomy_menu_get_parents($tid);

Let's modify it to:
$item['term']->parents = _taxonomy_menu_get_parents($term->tid);

and insert into two functions:

/**
 * Implementation of hook_taxonomy_term_insert($term).
 */
function taxonomy_menu_taxonomy_term_insert($term) {
...
      'menu_name' => $menu_name,
    );

    $item['term']->parents = _taxonomy_menu_get_parents($term->tid); //<=There

    $message = t('Term %term has been added to taxonomy menu %menu_name.', array('%term' => $term->name, '%menu_name' => $menu_name));
...
/**
 * Implementation of hook_taxonomy_term_update().
 */
function taxonomy_menu_taxonomy_term_update($term) {
...
 'mlid' => _taxonomy_menu_get_mlid($term->tid, $term->vid),    );

    $item['term']->parents = _taxonomy_menu_get_parents($term->tid);//<=THERE
    
$message = t('Term %term has been updated in taxonomy menu %menu_name.', array('%term' => $term->name, '%menu_name' => $menu_name));
...

Now, every time you add/update a term, the menu link will update the term name and it's weights.

Bug 2

After fixing previous problem, I find another feature that we can improve~

If I want to change the menu links' order weight, there are 2 ways to do that:

  1. menu admin page(admin/structure/menu/manage/X)
  2. Change the terms order in taxonomy term overview page (admin/structure/taxonomy/X)

    and go to vocabulary edit page(admin/structure/taxonomy/X/edit) press "SAVE Button"

If you only change the terms order in taxonomy term overview page(with press "SAVE Button") without go to vocabulary edit page(admin/structure/taxonomy/X/edit) press "SAVE Button"...The menu links' order won't update.

If you can only adjust taxonomy value then menu link auto adjust, how wonderful is the world!!!

First, I add something to taxonomy_menu_form_alter function:

/**
 * Implementation of hook_form_alter().
 *
 * Modify the form at admin/content/taxonomy/edit/vocabulary/xx. We add
 * our taxonomy_menu options in here on a per-vocab basis.
 */
function taxonomy_menu_form_alter(&$form, &$form_state, $form_id) {
…
    // add an extra submit handler to save these settings
    $form['#submit'][] = 'taxonomy_menu_vocab_submit';

  }
	/*****Start*****/
	if ($form_id == 'taxonomy_overview_terms') {
		$form['#submit'][] = 'taxonomy_menu_taxonomy_overview_view_submit';
	}
	/*****End*****/
}

Then, I create a new function taxonomy_menu_taxonomy_overview_view_submit:

/**
 * Submit handler for taxonomy overview terms form changed.
 *
 * Update taxonomy menu links items.
 */
function taxonomy_menu_taxonomy_overview_view_submit($form, &$form_state) {
  $vocabulary = $form['#vocabulary'];
  //update the menu items
	$message = _taxonomy_menu_update_link_items($vocabulary->vid);

  // Only send a message if one has been created.
  if (isset($message) && $message) {
    drupal_set_message($message, 'status');
  }
}

Now, you no longer need to go over menu page and setting!

If you have better idea~ please tell me:)

Sorry for my poor English...

CommentFileSizeAuthor
#1 menu_link_parent_fix-1437660-1.patch2.34 KBryandekker

Comments

ryandekker’s picture

Component: Sync or Update Issues » Code
Status: Active » Needs review
StatusFileSize
new2.34 KB

I had this issue too. I think this is due to an API change in Drupal 7. $term->parents has become $term->parent (non-plural) and is always an array AFAIK. So this issue can be fixed by the attached patch.

On a style note, if $term->parent is always an array, this code in _taxonomy_menu_create_item():

  // get the first parent
  if(is_object($term) && isset($term->parent)) {
    if (is_array($term->parent)) {
      foreach ($term->parent as $key => $val) {
        $ptid = $val;
        break;
      }
    }
    else {
      $ptid = $term->parent;
    }
  }

  //if ptid is empty, then set it to 0
  if (empty($ptid)) {
    $ptid = 0;
  }

could be simplified to:

  // Get the first parent or set the parent to 0.
  $ptid = (isset($term->parent[0])) ? $term->parent[0] : 0;
johnv’s picture

I think the patch in the following issue resolves your problems: #1104028: Option 'Sync menu' in D7

ryandekker’s picture

Status: Needs review » Closed (duplicate)

johnv, you're right, thanks. That patch does the trick. Marking as a duplicate of #1104028: Option 'Sync menu' in D7.