Hi,
I was getting a strange error on my drupal instance:
Fatal error: [] operator not supported for strings in [my site]/includes/common.inc on line 2353
I've traced it down to this module. I thought it had to do with line 39, which is:
$item['options']['attributes']['class'] = 'menu-node-unpublished';
and probably should be:
$item['options']['attributes']['class'][] = 'menu-node-unpublished';
(I believe that entry should always be treated as an array). I tried it, but that conversion didn't help the problem. I felt it best to hand it back at this point to see if you had insight before I delved further.
The problem shows up when I'm attempting to view leaf nodes in my menu, and nowhere else.
Comment | File | Size | Author |
---|---|---|---|
#8 | menu_view_unpublished-1696836-8-7.patch | 3.87 KB | gooddesignusa |
#5 | 1696836-unique-class-assignment-and-class-removal.patch | 1.59 KB | Anonymous (not verified) |
#2 | menu_view_unpublished-class_as_array_or_string-1696836-2.patch | 970 bytes | azinck |
Comments
Comment #1
Anonymous (not verified) CreditAttribution: Anonymous commentedFinal rewrite of that function (what works for my instance, anyways):
Comment #2
azinck CreditAttribution: azinck commentedHere's a patch. In my experience there's some inconsistency in that sometimes the classes come through as an array and sometimes as a string.
Comment #3
casey CreditAttribution: casey commentedThanks, committed half of your patch. Unique classes is not our deal.
Comment #4
lahode CreditAttribution: lahode commentedHi
I opened this ticket again because I noticed in version beta3, the patch proposed by azinck was not completely applied.
In fact, when I save my node several times, sometimes, the class "menu-node-unpublished" is added everytime, so that after 4 times (menu-node-unpublished menu-node-unpublished menu-node-unpublished menu-node-unpublished), I receive an error from Drupal telling me that the "class" field cannot have more than 128 caracters.
In azinck's patch #2, he wrote the following line which solve this problem:
instead of
Any reason not to integrate this line to the module ?
Cheers
Comment #5
Anonymous (not verified) CreditAttribution: Anonymous commentedHi again. I made some other modifications to this function: the line from #2, as well as code to remove the class from the menu item once it actually is published.
Comment #6
Anonymous (not verified) CreditAttribution: Anonymous commentedHi,
I noticed that the class "menu-node-unpublished" sometimes is not removed from a menu item after publishing the node belonging to the menu item. I applied the patch from #5, you state it might fix exactly that. But it didn't work. I cleared caches multiple times, un-/published nodes multiple times but the class is still being added to the item.
I'm using the module "menu_attributes". Editing a menu item directly actually shows the class in menu_attributes form. I think a conflict might be there, maybe it's the module weight, since menu_attributes always seems to override menu_view_unpublished?
I disabled menu_attributes and tried again, but the menu item's class still didn't change upon publish/unpublish.
Comment #7
gooddesignusa CreditAttribution: gooddesignusa commentedgenox, I actually got this working by changing the module a little. I will post a patch in the next day or so.
Comment #7.0
gooddesignusa CreditAttribution: gooddesignusa commentedRemoving domain name, irrelevant to the issue.
Comment #8
gooddesignusa CreditAttribution: gooddesignusa commentedSorry it took so long. I totally forgot about this issue.
This fixes the issues genox mentioned by using hook_node_presave(). This fixes the issue with menu_attributes and the menu-node-unpublished class issue.
Comment #9
Matroschker CreditAttribution: Matroschker commentedI have implemented patch 'menu_view_unpublished-1696836-8-7.patch' - now the class will not be duplicated if I'm save as unpublished and publish later - that's good.
But how can I delete all the other old entries?
Comment #10
DaleTrexelI found this issue because of the same problem genox mentioned in #6: publishing a node did not lead to the menu-node-unpublished class being removed. I wanted to report that I've tried the patch in #8, menu_view_unpublished-1696836-8-7.patch, and while it appears to be a step in the right direction, it's not quite there yet for my problem. After adding the patch, you have to save TWICE for the class to appear/disappear as expected.
My experience after applying the patch (this is consistent, repeatable behavior):
1. Create a new node in draft state, WITH a menu link set. Upon saving, the menu link does NOT have the menu-node-unpublished class present.
2. Save the node again, keeping the draft state, and the menu-node-unpublished DOES appear.
3. Publish the node, and the menu-node-unpublished class REMAINS.
4. Re-save the node as published and the menu-node-unpublished disappears.
In my case, I'm running a site with Workbench Moderation using Draft, Needs Review and Published states, though I don't suspect that this is involved.
Side note: I have also noted that menu-node-unpublished can be added multiple times to the same link (though I haven't dug into this to see if the number of repeats is related to, for example, the number of drafts). This is a behavior also noted in https://www.drupal.org/node/2414653 so these bug reports may be related.