Apache 2.2.11, PHP 5.2.6, Drupal 6.10.

At admin/content/types, I update the description of a custom content type, and save the new description. But at node/add, the old description is still displayed.

Thanks,
Andrew.

Comments

filipnest’s picture

I second this problem. Same set up. They appear as being changed in the content type screen but on the create content screen they are the same as they were before.

swentel’s picture

Version: 6.10 » 7.x-dev

This bug also exists in D7, changing version to fix it first in HEAD and provide backport later, looking for solution now ..

pwolanin’s picture

this is the function where they are actually generated: http://api.drupal.org/api/function/system_admin_menu_block/7

swentel’s picture

Ok, after some debugging, *I think* it's going wrong in the menu_link_save function. I tested with a custom content type called 'test' and with title test. I added some dsm in includes/menu.inc just before line 2186

  if ($item['title'] == "test") {
    drupal_set_message(print_r($existing_item, true));
    drupal_set_message(print_r($item, true));
    $diff = array_diff_assoc($existing_item, $item);
    drupal_set_message(print_r($diff, true));
  }
  if (!$existing_item || array_diff_assoc($existing_item, $item)) {
    ...

which gives:

# Array ( [menu_name] => management [mlid] => 141 [plid] => 13 [link_path] => node/add/test [router_path] => node/add/test [link_title] => test [options] => Array ( [attributes] => Array ( [title] => met description ) ) [module] => system [hidden] => 0 [external] => 0 [has_children] => 0 [expanded] => 0 [weight] => 0 [depth] => 2 [customized] => 0 [p1] => 13 [p2] => 141 [p3] => 0 [p4] => 0 [p5] => 0 [p6] => 0 [p7] => 0 [p8] => 0 [p9] => 0 [updated] => 0 )
# Array ( [title] => test [title callback] => check_plain [page callback] => node_add [page arguments] => Array ( [0] => 2 ) [access callback] => node_access [access arguments] => Array ( [0] => create [1] => test ) [description] => met description en nog een lijntje echt niet ? echt niet ? [module] => system [load_functions] => [to_arg_functions] => [weight] => 0 [type] => 6 [_number_parts] => 3 [_parts] => Array ( [0] => node [1] => add [2] => test ) [_fit] => 7 [_visible] => 1 [_tab] => [tab_parent] => [tab_root] => node/add/test [block callback] => [title arguments] => Array ( ) [position] => [path] => node/add/test [mlid] => 141 [menu_name] => management [plid] => 13 [has_children] => 0 [updated] => 0 [link_title] => test [link_path] => node/add/test [hidden] => 0 [options] => Array ( [attributes] => Array ( [title] => met description en nog een lijntje echt niet ? echt niet ? ) ) [external] => 0 [expanded] => 0 [customized] => 0 [depth] => 2 [p1] => 13 [p2] => 141 [p3] => 0 [p4] => 0 [p5] => 0 [p6] => 0 [p7] => 0 [p8] => 0 [p9] => 0 [parts] => Array ( [0] => node [1] => add [2] => test ) [router_path] => node/add/test )
# Array ( ) 

If you compare the attributes key in options key, you'll see the difference, however, the array_diff_assoc doesn't see the differences and doesn't update the item.

Should we fix that here or still in the system_admin_menu_block function ?

pwolanin’s picture

Ah, ok - so perhaps this is a problem since we are using nested arrays in terms of how array_diff_assoc() works?

indeed array_diff_assoc() has this on its docs page:

Note: This function only checks one dimension of a n-dimensional array. Of course you can check deeper dimensions by using, for example, array_diff_assoc($array1[0], $array2[0]);.

Can you double check in D6? There we don't have this check.

pwolanin’s picture

ok, so I think the code could be fixed like:

  if (!$existing_item || (array_intersect_assoc($item, $existing_item)) != $existing_item) {

This does the comparison after removing from $item all keys that are not present in $existing_item - i.e. what we were trying to achieve with the array diff.

swentel’s picture

Status: Active » Needs review
StatusFileSize
new853 bytes

That indeed fixes the problem. Patch attached for D7.
I can't reproduce it anymore on D6 on a new fresh install though, so no idea what went wrong on my existing installation ...

pwolanin’s picture

Status: Needs review » Needs work

Code looks fine, but the code comment above needs to be changed.

dave reid’s picture

Redundant parenthesis as well. Should be:
if (!$existing_item || array_intersect_assoc($item, $existing_item) != $existing_item) {

swentel’s picture

While this fixes the content type description, it seems to have some sort of side effect. When you create a new node and link it to the menu item, it enters the if statement and runs an update query which shouldn't happen - that is, if I understand the code correctly.
Just add a drupal_set_message($item['title']) inside the if statement and you'll see it gets there throwing a php notice.

Also, with administration menu turned on, it seems that a lot of menu items are updated too sometimes - although this module isn't core (yet), we might have to watch out before commiting this because it might cause a lot of overhead when there are more contribs out there touching the menu module.

* Administration menu
* Run updates
* Flush all caches
* Administration menu
* Cache tables
* Menu
* Page requisites
* Registry
* Theme registry
* Disable developer modules

pwolanin’s picture

@swentel - i don't understand your comment. If you create a new menu link this code must be executed.

Essentially the test is:

  1. Is this a new link?
  2. Is this an existing link which has had any of its properties changed?

If you compare to D6, we currently don't have this check at all. Hence, the performance cannot be any worse in D7.

pwolanin’s picture

Status: Needs work » Needs review
StatusFileSize
new1.14 KB

code for review.

swentel’s picture

Status: Needs review » Needs work

Small typo:
The intesect removes the extra keys, allowing a meaningful comparison.
should be
The intersect removes the extra keys, allowing a meaningful comparison.

pwolanin’s picture

StatusFileSize
new2.06 KB

Fixed typo. Added a test that fails in the absence of the change to menu.inc.

pwolanin’s picture

Status: Needs work » Needs review
catch’s picture

Status: Needs review » Reviewed & tested by the community

Read the discussion and the patch, test looks fine. This is ready to go.

dries’s picture

Status: Reviewed & tested by the community » Fixed

Looks good. Thanks Peter and swentel.

Andrew Schulman’s picture

I've just tried to apply this patch to my D6 installation in order to test it, and it won't apply-- source doesn't seem to match up. Is this patch just for D7 then? Will it be backported to D6? I wouldn't say that the priority is very high; just wondering. Thanks, Andrew.

catch’s picture

Version: 7.x-dev » 6.x-dev
Status: Fixed » Patch (to be ported)
pwolanin’s picture

Per comments above, as far as I know this bug is not present in D6 - it was due to the array_diff() optimization.

Andrew Schulman’s picture

I reported it for Drupal 6.10. I just tested and it's still present in 6.11. Thanks, Andrew.

sbydrupal’s picture

Same problem with Drupal 6.12. Thanks.

gpk’s picture

On the offchance ... in 6.x ... have you tried clearing the menu cache? Simply visiting the admin/build/modules page should do this.

vivianspencer’s picture

I can also report this problem in 6.12, clearing the cache has no effect

gpk’s picture

OK, it was a long shot. I actually can't reproduce this in 6.10. The change is immediately reflected at node/add and also on the text that displays when you hover over the relevant menu item in the Create content menu.

sbydrupal’s picture

There is a shortcut to solve the issue (for D.12 it works) : Under Menu --> Navigation, when the menu entry corresponding to the node type is edited, the description field shows up correctly on node/add.

BravoGolf’s picture

I have a similar error for which I logged a bug (#542654: Content Type not matching Add Node or Content Add) but no idea how to resolve.

HS’s picture

This is issue exists in D 6.14

HS’s picture

Actually ignore me. The Content Type can be assigned 'descriptions' in multiple locations. One at admin/build/menu when you edit the item and the other when you edit the content type.

albert volkman’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new839 bytes

Backported for 6.x.

xano’s picture

Status: Needs review » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.