Notice: Undefined index: class in ais_preprocess_image() (line 204 of C:\xampp\htdocs\playground2\sites\all\modules\ais\ais.module).
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

spotzero’s picture

Status: Active » Fixed

Notice could occur if your theme doesn't add any css classes to your images.

Fixed in the dev branch.

spotzero’s picture

Status: Fixed » Closed (fixed)

Closing issue.

JohnAlbin’s picture

Status: Closed (fixed) » Needs review

Your fix did not work. See http://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_ima...

For one thing, you would still get an "undefined index: class" notice. You are now using it twice; you should have checked if it existed first.

Also, the $variables['attributes']['class'] is actually an array, not a string. (Though the docs don't show this well.)

What you should be doing is appending your class to the end of the list of existing classes. If the "class" array doesn't exist previously, that code will also have the advantage of creating the array without generating any errors/notices.

$variables['attributes']['class'][] = AIS_ADAPTIVE_CLASS;
spotzero’s picture

[attributes][class] should totally be an array, not a string. I've updated the 7.x-1.x branch to reflect this.

Thanks JohnAlbin!

spotzero’s picture

Status: Needs review » Fixed
steve65140’s picture

Status: Fixed » Active
FileSize
128.1 KB

Hi,

I've just followed the excellent documentation on http://coldfrontlabs.ca/blog/creating-responsive-image-slider-galleries-... to build my first Flex Slider based on AIS.

I've loaded 3 pictures on a node. When I then view the node the first two pictures are shown OK then just the side arrows and 3 dots but no third picture. I then get the error message in the title of this issue.

Please see screen shot.

Please let me know if there's anything else I can provide to help get this fixed.

minorOffense’s picture

Status: Active » Closed (fixed)

This isn't an issue with ais, it was a bug with Flex Slider. See issue #1509102: slideToStart value set to string '0' instead of integer 0. It should now fixed in the RC. If you have any other issues with Flex Slider, feel free to drop it in the issue queue over there and I'll have a look.

Thanks!

nflowers1228’s picture

I'm having the same problem and I have the most current versions of Flex Slider and Adaptive Image Styles. Not sure where to post to get help.
Notice: Undefined index: class in ais_preprocess_image() (line 204 of /home5/sitename/public_html/drupal7/sites/all/modules/ais/ais.module).

spotzero’s picture

This issue is currently only fixed in the dev branch. I'll be rolling a 1.1 release soon however.

onehandsomedog’s picture

Version: 7.x-1.0 » 7.x-1.1

I just updated to the newest dev version and the 'Notice: Undefined index: class in ais_preprocess_image() (line 205' problem came back. I also tried the newest recommended release and have the same issue. Any ideas? Also, I noticed the 'adaptive' class has a single space preceding it in the markup.

selinav’s picture

Version: 7.x-1.1 » 7.x-1.x-dev
Status: Closed (fixed) » Active

+1

jordiserratosa’s picture

+1

s_u_s_a_f_o_n’s picture

Hi guys, thanks for your hard work. I've checked the code around the line 205 of dev version of ais.module file, found logical error. I guess, it would be better to replace the following code:

if (!isset($variables['attributes']['class']) or !is_array($variables['attributes']['class'])) {
        $variables['attributes']['class'] = array($variables['attributes']['class']);
      }
      $variables['attributes']['class'][] = AIS_ADAPTIVE_CLASS;

with:

      if (isset($variables['attributes']['class']) && !is_array($variables['attributes']['class'])) {
        $variables['attributes']['class'] = array($variables['attributes']['class']);
      } else {
        $variables['attributes']['class'] = array();
      }
      $variables['attributes']['class'][] = AIS_ADAPTIVE_CLASS;
kingfisher64’s picture

#13 works great - thanks

spotzero’s picture

Status: Active » Fixed

Pushed the fixed into the dev branch.

DigitalFrontiersMedia’s picture

Status: Fixed » Needs work

Updated to latest ais-7.x-1.x-dev (Last packaged version: 7.x-1.1+1-dev, Last updated: May 17, 2012 - 19:02) and still getting this error:

Notice: Undefined index: class in ais_preprocess_image() (line 205 of .../sites/all/modules/ais/ais.module).

One error for each adaptive image on the page.

kingfisher64’s picture

Can confirm this. Don't know what's going on as #13 fixed the problem then out of the blue the error has returned? Strange.

s_u_s_a_f_o_n’s picture

The problem remains due to wrong / insufficient IF clause:

if (!isset($variables['attributes']['class']) or !is_array($variables['attributes']['class']))

should be:

if (!isset($variables['attributes']['class']) && !is_array($variables['attributes']['class']))

replace "or" and with "&&", so #13 should be ok.

DigitalFrontiersMedia’s picture

Status: Needs work » Needs review
FileSize
871 bytes

I think the code (even the proposed patch) is flawed. I believe it should be:

      if (!isset($variables['attributes']['class'])) {
        $variables['attributes']['class'] = array();
      } else if ( !is_array($variables['attributes']['class']) ) {
        $variables['attributes']['class'] = array($variables['attributes']['class']);
      }
      $variables['attributes']['class'][] = AIS_ADAPTIVE_CLASS;
kingfisher64’s picture

Status: Needs review » Needs work

Yep #18 solves the issue. Think I must have copied that fix into another install of the mod and not changed or to &&. Many thanks s_u_s_a_f_o_n

DigitalFrontiersMedia’s picture

s_u_s_a_f_o_n snipes me while I'm building a patch! :-D

My thinking on my version was that it might be possible for one to wipe out the values entirely if the variable is set but it's not an array with earlier proposed method (instead of recasting it).

s_u_s_a_f_o_n’s picture

DigitalFrontier is right, his latest patch provided in #19 is much safer!

spotzero’s picture

The 'or' definitely needed to be an 'and', but Digital's patch is a complete fix, so I've committed it to dev.

Please report if the latest dev clears the warning, if so I'll roll a release 1.2 and hopefully close this issue once and for all :D

lameei’s picture

@spotzero I confirm that Dev clears the warning.

s_u_s_a_f_o_n’s picture

I can confirm that, too.

spotzero’s picture

Status: Needs work » Fixed

Tagged release 7.x-1.2 with the fix for this issue.

Status: Fixed » Closed (fixed)

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