When i change an option in the taxonomy options block, for instance set or switch off "Hide empty terms", and klik save the menu concerned is deleted and rebuild even when the "Select to rebuild the menu on submit." option is off. This results in messing up the menu's order.

I found the reason why this happens. In file "taxonomy_menu.module,v 1.19.2.2.2.53" on line 130 there is this statement: if ($key = 'voc_item') :

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

This sets $key always to 'voc_item' and is allways TRUE. Hence always run a rebuild in stead of an update.

When i change "if ($key = 'voc_item')" into "if ($key == 'voc_item')" it get worse.
The update function is called, and a message is send "The Taxonomy Menu has been updated.", but all taxonomy menu's
have disapeared an a bunch of error messages is given:

# warning: Illegal offset type in isset or empty in C:\wamp\www\lockman\includes\common.inc on line 902.
# warning: Illegal offset type in isset or empty in C:\wamp\www\lockman\modules\locale\locale.module on line 362.
# warning: mysqli_real_escape_string() expects parameter 2 to be string, array given in C:\wamp\www\lockman\includes\database.mysqli.inc on line 323.
# warning: Illegal offset type in C:\wamp\www\lockman\modules\locale\locale.module on line 369.
# warning: Illegal offset type in C:\wamp\www\lockman\modules\locale\locale.module on line 388.
# warning: Illegal offset type in C:\wamp\www\lockman\modules\locale\locale.module on line 388.
# warning: trim() expects parameter 1 to be string, array given in C:\wamp\www\lockman\sites\all\modules\taxonomy_menu\taxonomy_menu.module on line 523.
...
(These messages are repeated many times, once for every term i gues)
....
# Could not save the menu link for the taxonomy menu.

I think much more is wrong here. I did not have time yet to get deeper into this.

Best regards,
hovel

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alb’s picture

I maked this change in the code and in the menu is added some void link menu;
I suggest for who would like to do make this test of create a copy of the site; because this
test change all the menu links;

hovel’s picture

alb,
Yes it is dangerous to correct this one code error because there is more wrong.
I my case it destroyed the taxonomy menu and i was not able to repair it. I had to restore the database again! (of which i had a backup of cource).

hovel’s picture

An other consequence of allways rebuilding the taxonomy menu has to do with translation.
If the translation mode is "Localise Terms" the translatable strings are build again aswell hereby losing existing translations.
The old ones are left in the system and are messing up the string translation page with many unused textgroup:menu strings.

hovel’s picture

I looked a bit deeper into the code and came up with ...
The following patch should solve this issue. at least it is working for me.

The following has been changed/corrected:
- Run update in stead of rebuild, as designed.
- Corrections to make update work.
- Use taxonomy term weight for the taxonomy menu link weight to preserve sequence
- Do not increment variable taxonomy_menu_weight in case of update

Regards,
hovel

indytechcook’s picture

Status: Active » Needs review

Thanks hovel, I've been feeling really sick this week and haven't been able to tend to the issues much.

hovel’s picture

No problem, Get better soon.

rocketeerbkw’s picture

Status: Needs review » Reviewed & tested by the community

Your patch fixed the issues you described, thx

Having the menus jump to the end after every minor change was really annoying.

alb’s picture

when I change a position of an item is necessary to click on Select to rebuild the menu on submit.
isn't possible automatically update the list?
this because in this area
admin/content/taxonomy/edit/vocabulary/id vocabulary
I prefer that an user, that must only add terms, is better that not use;

alb’s picture

see that when one move the position of a items is necessary to rebuild the list (there is a specific function), in the code which is the
point where the code 'reknow' that an element is moved form its initially position;
so in that poin think is possible to recall the function rebuild

indytechcook’s picture

Status: Reviewed & tested by the community » Fixed

The patch in #4 has been committed. Thanks hovel :)

http://drupal.org/node/767734

alb’s picture

in version taxonomy_menu 6.x-2.6 respect at 2.5

at row 42 is inserted code $item['mlid']=0;
which patch is this?

at row 128 is remained $key='voc_item' while in the patch is $key=='voc_item'
at row 215 is remained $args['vid'] = $menu_link->vid; while in the patch is $args['vid'] = $vid;

other for resolve my point #9;
I tested to recall function _taxonomy_menu_rebuild($vid) inner taxonomy delegate but not work
any ideas ?

alb’s picture

regard this
at row 128 is remained $key='voc_item' while in the patch is $key=='voc_item'
is better how maked you $key='voc_item' because with == I have problem if select options
in Edit vocabulary;

regard this
if (strlen($item['name']) > 256) {
preg_match('/(.{256}.*?)\b/', $item['name'], $matches);
$item['name'] = rtrim($matches[1]);
}

I tested to write not 256 but 2 for to have in the url not many terms but only two ;
but not work, in the url there always many terms; so think isn't this solution.

but is there a solution for not to have a long url?
in drupal 5 this not was so;
in the url there was only the id of the vocabulary and not all the terms

indytechcook’s picture

alb,

Thank for the catches. This is what happens when I manually patch late at night after a long day.

The missed items form the patches are not commited: http://drupal.org/project/cvs/3724 and 2.7 has been created.

at row 42 is inserted code $item['mlid']=0;
which patch is this?

This was added to be more compatible with the menu_parent_options function.

f (strlen($item['name']) > 256) {
preg_match('/(.{256}.*?)\b/', $item['name'], $matches);
$item['name'] = rtrim($matches[1]);
}
?>

This code is for the title and not the url. It keeps the title less then 256 characters and only breaks at blanks.

I don't understand what you are trying to do with #9. Can you please elaborate.

alb’s picture

#9 really this problme can to be resolved if syncronize work, but isn't so;
if I delete an items ok sync work;

but if I change the position of an item the code not work, in the menu the position is always the same;
this in vers 2.5 and 2.6;

other small observation:
if I add an item "aaa" (with weight 0), it in the menu remain last while in taxonomy list is first;
but when I click on button save of the taxonomy list I have this two action:

with version 2.5 ok "aaa" also in menu is set how first

with your version 2.6 not work (remain last in the menu)

alb’s picture

regar version 2.7
I noticed that insert
$key=='voc_item'

in my #12 I write that also if is the php correct code there are some problems ;
for example with activation of Use 'all' at the end of URL I haved problems at menu;

if I have this
VOC
t1
t2

after Use 'all' ....
VOC
t1
t2
VOC

reinsert voice of menu with the name of the vocabulary

nb. make copy of db first of this test because menu isn't possible delete but only disable
and not know if there are other error in db; so better use originall db
--------------------------
other 1:
but the option "all at the end of url", is also possible to have for vocabolary and not only for terms?
so think is possible to solve the urls that are too much long
--------------------------

alb’s picture

this patch (in grey) (for maintain the position when change name at terms)

if (!$item['mlid']) {
// Set the weight. We need to do this becuase the menu system does not order the terms
// the same way that the taxonomy system does.
// We use a variable to store the value intead of static becuase
// using batch API loses the static value per requests.
$weight = variable_get('taxonomy_menu_weight', 0);
$weight++;
variable_set('taxonomy_menu_weight', $weight);

// Set the default expanded value 
$expanded = variable_get('taxonomy_menu_expanded_'. $item['vid'], TRUE);

$insert = TRUE;

 } else {
    $menu_link = menu_link_load($item['mlid']);
    $weight = $menu_link['weight'];
    $expanded = $menu_link['expanded'];
  }

respect at vers 2.5
when are add two or more new terms, they remain always at the end of the menu;
while in the 2.5 at click on the save button, the terms take the correct position in the menu;

----------------------------------------------------------------
other
in 2.5 work if insert two or more terms; if insert only a term not work;
----------------------------------------------------------------

synthesis when update, delete, insert terms:

delete works for all;
if insert only a new term, noone version work;
if insert new two or more terms, 2.5 work;
2.5 not work when change name at terms;
all version not work when change position at terms or better:
in 2.5 if you have this

Home
Sez 1
Sez 2
Sez 3
Other 1

and move Home so:
Sez 1
Home
Sez 2
Sez 3
Other 1

in menu you will have
Sez 2
Sez 3
Other 1
Sez 1
Home

all that above that you have moved, is moved at the end of menu.
think is here the problem or function that recall this

function _taxonomy_menu_save($item) {
   point x 
    $weight = variable_get('taxonomy_menu_weight', 0);
    $weight++;
    variable_set('taxonomy_menu_weight', $weight);

while in 2.5 you can move but with those error , 2.7 not move nothing because
there is an if in the pint x
if (!$item['mlid']) { so if remove this if you can move terms but with problem described

indytechcook’s picture

alb, can you please format your changes as a patch? It will make it easier to test. http://drupal.org/patch/create

alb’s picture

look, that who I have write in post #16, isn't a my patch;
are some observations

I simple notice how in 2.7, that is a 2.5 version integrated with some patchs, there is a patch that resolve one problem but create onother;

also noticed how when one move an item the code work partially because all is send at the end of the list;
the problem is that this code partially work
$weight = variable_get('taxonomy_menu_weight', 0);
$weight++;
variable_set('taxonomy_menu_weight', $weight);

infact in the example above (#16) Home is under Sez 1 but its position is moved at the end of menu;
so when I move Home under Sez 1 the code some work (Home is placed under Sez 1) but lost its really position in the menu for to restart from the end;
---------------------------------------------------------------------------------------------

tomsm’s picture

I have noticed the same thing with 6.x-2.7. When I reorder the terms alphabetically and click save, I get messages like "Term 'Testing' has been updated in taxonomy menu 'menu-products'". But the order is not changed. I have to rebuild the menu.

My previous version 6.x-2.4-beta1 did update the terms correctly without a rebuild.

Sorry, this comment is better placed here: http://drupal.org/node/768862#comment-2883362

alb’s picture

FileSize
8.37 KB

solved; I analyzed code in version 6.x-2.4-beta1 and found solution;

also at row 128 I removed the == also if isn't a correct php code,
because so
$key=='voc_item'
with activation of Use 'all' at the end of URL I haved problems at menu and also with set Display number of items;

-------------------------------

regard this
if (strlen($item['name']) > 256) {preg_match('/(.{256}.*?)\b/', $item['name'], $matches);
$item['name'] = rtrim($matches[1]);}

indytechcook answer that
It keeps the title less then 256 characters and only breaks at blanks.

the title is:
when is selected one vocabulary, the title of the page (that are all the terms of the vocabulary),

or the title is the name in the page of the term selected?

I ask, because the condition above: "if (strlen... ", can to make some slow the loading of the page? see that every time a page is called, the code must to verify the lenght of the title.

I ask because rarely the title can to be more than 250;
so is also possible to leave commented the code, and who have problem can to activate.

indytechcook’s picture

alb, the function _taxonomy_menu_save is only called when a term is updated/inserted, deleted or added/removed from a node. It should have been path rather then title. Related to this issue #738772: For large vocabularies, Taxonomy menu does not show up due to too-long URL (and a fix for the field length bug)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.