Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Getting this error in the preprocess function, when the value of attributes is already an array of classes.
Comment | File | Size | Author |
---|---|---|---|
#2 | remove_php_warning-2660606-2.patch | 625 bytes | tom friedhof |
Comments
Comment #2
tom friedhof CreditAttribution: tom friedhof at ActiveLAMP commentedHere is a patch
Comment #3
joelpittetThat'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...
Comment #4
tom friedhof CreditAttribution: tom friedhof at ActiveLAMP commentedWhat 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.
Comment #5
joelpittet@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.
Comment #7
joelpittet@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.
Comment #9
tom friedhof CreditAttribution: tom friedhof at ActiveLAMP commentedI'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.
Comment #10
joelpittetWell 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.