Here's a weird one;
I just updated an 8.2.8 site to 8.3.2 and updated DS to 3.x-dev. Actually I tried the release version first. Either way, on certain pages the site would consistently generate PHP errors like this;
Error: [] operator not supported for strings in ds_preprocess_ds_layout() (line 573 of modules/ds/ds.module)
and;
Error: [] operator not supported for strings in ds_preprocess_ds_layout() (line 580 of modules/ds/ds.module)
The code in question looks like this;
$variables['attributes']['class'][] = 'view-mode-' . $variables['content']['#view_mode'];
.. I saw nothing wrong with that. I am running PHP 7 on Ubuntu 16. That could should work, but for whatever reason it did not. On a whim I tried changing it to array() instead, like this;
$variables['attributes']['class'] = array('view-mode-' . $variables['content']['#view_mode'];)
.. and that worked. No more errors. I have gone back through and re-saved the various displays I have in Display Suite, just to see if A) those generate errors when saving, B) that saving them does not mess up existing layouts, and C) any other weirdness. That all looks fine.
It doesn't really make sense to me that this would fix it... I mean, [] brackets have been a thing since PHP 5.4+... yet this does fix it for me. Sharing the patch in case it helps anyone else out.
Comment | File | Size | Author |
---|---|---|---|
#2 | 2880080.patch | 1.74 KB | caspervoogt |
#10 | ds-class_in_layout_attributes-2880080-10.patch | 554 bytes | dshields |
#16 | 2880080-15.patch | 1.65 KB | swentel |
#16 | 2880080-15-test-only.patch | 1.11 KB | swentel |
Comments
Comment #2
caspervoogt CreditAttribution: caspervoogt at Plethora commentedComment #4
caspervoogt CreditAttribution: caspervoogt at Plethora commentedComment #5
caspervoogt CreditAttribution: caspervoogt at Plethora commentedPatch failed testing but apparently due to other issues in DS.. not the lines I modified.
Comment #6
aspilicious CreditAttribution: aspilicious commentedIncorrect, the patch failed because your patch is overwriting existing classes.
If class is a string something else is causing this. You should debug_backtrace to see what function is adding a string to the class property.
Comment #7
Eric115 CreditAttribution: Eric115 at PreviousNext commentedI am seeing this error when trying to add a "layout attribute" to the "custom wrappers" section, although only when trying to add a "class|some-class" attribute, which makes sense as classes are normally stored as an array an imploded just before render.
On reflection however, it looks like trying to override the class attribute from this field is a bad approach when you can use the custom classes for the layout / regions using the "custom classes" section. If that understanding is correct, perhaps this patch should be code to skip over "protected" attributes (I can only think of "class" being one at the moment however) and updating the field description?
@aspilicious would you agree with that?
Comment #8
caspervoogt CreditAttribution: caspervoogt at Plethora commentedThanks @aspilicious. I don't have time right now to go back and modify the patch. I threw mine together for a quick fix and it did work for me.
Comment #9
dqdJust to report that nothing has changed in connection with core until now.
The issue still persist (WSOD)
#7: correct, same here. I can reproduce your description.
Then you will come back when the mistakes @aspilicious mentioned gonna affect your stack under the hood one day. :)
Comment #10
dshields CreditAttribution: dshields at Canadian Blood Services commentedThis should fix the error and make it possible to add a class (or multiple classes separated by spaces) to the Layout Attributes.
Comment #11
mducharme CreditAttribution: mducharme as a volunteer commentedPerfect. Works for me on 8.5.6
Comment #12
dqdNot happy with that description (nitpicking), but the patch looks good so far.
Comment #13
swentel CreditAttribution: swentel at eps & kaas for Dropsolid commentedI tried reproducing this on the latest dev and 8.6 core. But can't make it crash, so is this still a problem ?
Comment #14
swentel CreditAttribution: swentel at eps & kaas for Dropsolid commentedComment #15
oemer CreditAttribution: oemer at Computer Manufaktur GmbH commentedIt is still a problem in Display Suite 8.x-3.4 and Core 8.7.10.
Adding a class attribute at "custom wrappers" crashes the site.
Comment #16
swentel CreditAttribution: swentel at eps & kaas for Dropsolid commentedFinally able to reproduce this! Added a test for it.
Comment #19
swentel CreditAttribution: swentel at eps & kaas for Dropsolid commentedcommitted and pushed