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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

caspervoogt created an issue. See original summary.

caspervoogt’s picture

FileSize
1.74 KB

Status: Needs review » Needs work

The last submitted patch, 2: 2880080.patch, failed testing.

caspervoogt’s picture

Status: Needs work » Needs review
caspervoogt’s picture

Patch failed testing but apparently due to other issues in DS.. not the lines I modified.

aspilicious’s picture

Status: Needs review » Needs work

Incorrect, 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.

Eric115’s picture

I 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?

caspervoogt’s picture

Thanks @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.

dqd’s picture

Just to report that nothing has changed in connection with core until now.

The issue still persist (WSOD)

The website encountered an unexpected error. Please try again later.
Error: [] operator not supported for strings in ds_preprocess_ds_layout() (line 573 of modules/contrib/ds/ds.module).

#7: correct, same here. I can reproduce your description.


I threw mine together for a quick fix and it did work for me.

Then you will come back when the mistakes @aspilicious mentioned gonna affect your stack under the hood one day. :)

dshields’s picture

Status: Needs work » Needs review
FileSize
554 bytes

This should fix the error and make it possible to add a class (or multiple classes separated by spaces) to the Layout Attributes.

mducharme’s picture

Status: Needs review » Reviewed & tested by the community

Perfect. Works for me on 8.5.6

dqd’s picture

+++ b/ds.module
@@ -536,7 +536,8 @@ function ds_preprocess_ds_layout(&$variables) {
+        // Handle the class attribute as an array and others as strings.

Not happy with that description (nitpicking), but the patch looks good so far.

swentel’s picture

Status: Reviewed & tested by the community » Needs review

I tried reproducing this on the latest dev and 8.6 core. But can't make it crash, so is this still a problem ?

swentel’s picture

Status: Needs review » Postponed (maintainer needs more info)
oemer’s picture

It 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.

swentel’s picture

Status: Postponed (maintainer needs more info) » Needs review
FileSize
1.11 KB
1.65 KB

Finally able to reproduce this! Added a test for it.

  • swentel committed 92db179 on 8.x-3.x
    Issue #2880080 by swentel, caspervoogt, dshields, diqidoq, mducharme,...

  • swentel committed 9960cc4 on 8.x-4.x
    Issue #2880080 by swentel, caspervoogt, dshields, diqidoq, mducharme,...
swentel’s picture

Status: Needs review » Fixed

committed and pushed

Status: Fixed » Closed (fixed)

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