Getting this error in the preprocess function, when the value of attributes is already an array of classes.

CommentFileSizeAuthor
#2 remove_php_warning-2660606-2.patch625 bytestom friedhof
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tom friedhof created an issue. See original summary.

tom friedhof’s picture

Status: Active » Needs review
FileSize
625 bytes

Here is a patch

joelpittet’s picture

Status: Needs review » Needs work
+++ b/menu_attributes.module
@@ -337,7 +337,7 @@ function menu_attributes_preprocess_menu_link(&$variables) {
-          $value = explode(' ', $value);
+          $value = is_array($value) ? $value : explode(' ', $value);

That's backwards but I get your gist;) Also, I'd actually consider to throw a watchdog error here because you have some other rogue module sending your classes in non-array format which is not part of the API. I know I've fixed this in other modules before...

tom friedhof’s picture

What do you mean "That's backwards"? The ternary implies if $value is an array, then use the array instead of exploding the space separated string to an array. Can you clarify what is backwards?

menu_attributes expects $value to be a string, not an array.

joelpittet’s picture

@tom friedhof Oh it's not backwards, I just have it backwards in my head... I usually do !is_array() ? ACTION : DEFAULT... not to worry there.

I'm just a bit curious why nobody has brought this up before? And how did it get to be not a string in the first place? I know drupal_attributes() expects an array for the class attribute.

joelpittet’s picture

Status: Needs work » Fixed

@tom friedhof I'm going to commit this, but if you could tell me how it got in there as a string to begin with it would really help.

tom friedhof’s picture

I'm not sure why menu_attributes was expecting a string. We're using the bootstrap theme which sets the class attributes as an array which caused PHP Warnings.

I was just cleaning up the PHP Warnings on a site we're building.

joelpittet’s picture

Well it should expect an array as that's how Drupal's attribute APIs work. I'm guessing on the other end we aren't usually serializing the attributes with that in mind. Strange indeed. Oh well thanks again for the patch and the bug report.

Status: Fixed » Closed (fixed)

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