Problem/Motivation

I updated CS Adaptive Image to CS Adaptive Image 7.x-1.1 on my Drupal 7 Site and it started throwing this error on every page using CS Adaptive Image:

Error: [] operator not supported for strings in theme_cs_adaptive_image_formatter() (line 252 of /code/sites/all/modules/cs_adaptive_image/cs_adaptive_image.module).

Steps to reproduce

Update to CS Adaptive Image 7.x-1.1 on a server running PHP 7.1.33

Proposed resolution

Add one line above line 252 to first define an empty array before giving the array a value.

It looks like the error may be caused by a PHP syntax change in PHP 7.1

See this resource: https://wordpress.org/support/topic/fatal-error-operator-not-supported-f...

diff --git a/sites/all/modules/cs_adaptive_image/cs_adaptive_image.module b/sites/all/modules/cs_adaptive_image/cs_adaptive_image.module
index fd4790384..bf92be20c 100644
--- a/sites/all/modules/cs_adaptive_image/cs_adaptive_image.module
+++ b/sites/all/modules/cs_adaptive_image/cs_adaptive_image.module
@@ -249,6 +249,7 @@ function theme_cs_adaptive_image_formatter($variables) {
   // to serve an adapted image. Some browsers cannot access the
   // children of a <noscript> element, thus all the data needs to be
   // attached to the <noscript> element.
+  $image['attributes']['class'] = [];
   $image['attributes']['class'][] = 'adaptive-image';
   $attributes['class'][] = 'adaptive-image';
   if (isset($variables['breakpoint_styles'])) {
CommentFileSizeAuthor
#4 3218361-4.patch600 bytesvuil

Comments

ldwyer created an issue. See original summary.

vuil’s picture

Status: Needs review » Active

There is no patch for a review. I set the issue back to Active.

vuil’s picture

vuil’s picture

Version: 7.x-1.1 » 7.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new600 bytes
vuil’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -

  • vuil committed eb2f0512 on 7.x-1.x
    Issue #3218361 by carroll_webprog, vuil: Error: [] operator not...
vuil’s picture

Status: Reviewed & tested by the community » Fixed

I close the issue as Fixed.

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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