Setting up a class for image fields in the admin console was working, however it didn't apply the changes to the elements rendered.

A look to the source revealed that not all child elements (fields) of the entity to be rendered had been looped through, because a misplaced 'return' left the hook as soon as it looped through a child-element without the class-setting.

The attached patch fixed this problem for me.

Comments

mario steinitz’s picture

Issue summary: View changes
Anonymous’s picture

I agree I have the same problem here. After testing your patch it works. Danke Mario

mario steinitz’s picture

StatusFileSize
new983 bytes

Now that the project using this module is done, here's the refined and cleaned up version of my above patch.
It has corresponding remarks added and forces class strings to be applied as array. The latter was necessary due to problems with a theme function applying further classes to images.

Angry Dan’s picture

Status: Needs review » Reviewed & tested by the community

This patch really needs a commit, no? The module is ineffective without it.

markchitty’s picture

Agreed, dead in the water without it.

yannickoo’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/image_class.module	(working copy)
@@ -72,13 +72,16 @@ Image Class 7.x-1.0, function image_class_field_attach_view_alter(&$out
+      if (is_array($settings['class']) || is_string($settings['class'])) {

Thanks for the patch!

There is a question: Why should $settings['class'] be an array? I will commit a patch ASAP but I don't get why you are checking for an array. Could you please explain that?

yannickoo’s picture

Status: Needs work » Fixed

Should be fixed with a4baf33. Please test the next dev version of Image Class so that I can release a new version ASAP.

@Mario could you please explain the array thing anyway?

Status: Fixed » Closed (fixed)

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

mario steinitz’s picture

@yannico:
Sry for the late reply. I've been busy with some other projects recently.

Unlike in D6, the Drupal 7 render arrays use an array of classes for the class attribute.
We had some other modules within the above project, that already stored the display setting 'class' as array. (I honestly can't remember which ones...)

So checking for/handling an array while looping over ALL fields was necessary, to prevent some nasty PHP exceptions.

Best regards

Mario