Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The Image Caption Filter module looks for an exact match on the class="..." string for each img tag, which means that images with multiple classes (such as the extra class created by ImageCache when combined with Insert module) won't get captions.
In other words, class="imagecache_thumb image-right" SHOULD get a caption because it contains "image-right", but currently it does not.
The expected behavior would be for the module split the classes up and check each one.
Comments
Comment #1
bradweikel CreditAttribution: bradweikel commentedThe fix for this is pretty basic:
1) change Line 71 to this:
$class = explode(" ", $matches[1]);
2) the conditional at Line 83 needs to be modified to check the entire array for matches, probably using count(array_intersect(class, array("image-right"...)))
3) the return value inside that conditional will need to be tweaked a bit so that the correct classes are preserved
I'd get us started on a patch, but I'm traveling and don't have a suitable dev environment, so hopefully somebody else can put together a patch.
Comment #2
vood002 CreditAttribution: vood002 commentedThe fix isn't quite this simple...although these two small changes will leave it in a partially-working state
Change line 71 to
$class = explode(" ", $matches[1]);
Change line 83 to
if ( array_intersect( $class, array('image-left', 'image-right', 'standalone-image')) && ($title)){
Then, the class is passed on to the
so this comes up as 'Array', and the line:
will remove all classes from the image, where we'd like to only remove the class that causes captioning.
I'm going to work on this as soon as i can...should be pretty easy to roll a patch that makes this module very usable...unfortunately I have a lot on my plate ahead of it.
The only other problem I can see is that this module grabs the width of the image-containing div from the image width tag...which really isn't a tag that anyone should be using. This should be updated to use
imagesx()
if GD is detected....unless there's something I'm overlooking.Comment #3
bradweikel CreditAttribution: bradweikel commentedIn my defense, that's precisely what I meant by "the return value... will need to be tweaked... so that the correct classes are preserved"
:)
You should file the width problem in another issue, so any patches in this queue don't get cluttered or delayed by multiple issues.
Comment #4
fletchgqc CreditAttribution: fletchgqc commentedYou are right that this is a limitation. A patch would be welcomed but I'm about to submit some major code changes to this module so please just wait until they're in.
Regarding using the width attribute of the image tag, that is totally valid and not deprecated (won't explain here but you can research it). However new code which I'm about to submit will also allow width from inline style.
Comment #5
fletchgqc CreditAttribution: fletchgqc commentedSee #777364: Major update for filter for new code.
Comment #6
brian_c CreditAttribution: brian_c commentedPlease note that the patch in #5 does NOT fix the multiple classes issue that is the subject of this thread (it's a little confusing that you've linked to it from here)
Comment #7
NPC CreditAttribution: NPC commentedSubscribing. The patch to the patch in #5 fixed it (THANK YOU!), but I want to know when it will be done properly (or checked in to the main branch).