I need to hide the title in a lot of cases, but still want to keep the alt attribute for accessibility purposes.
This patch adds a checkbox to the image assist form that allows you to only add the title as an alt tag. It also adjusts the height of the properties window to accommodate added form elements.

Comments

zoo33’s picture

First: would it be sufficient for you to customize theme_img_assist_inline()? Or do you need the ability to choose for individual images if the title should be shown or not?

Anyway, I tested the patch and it works almost perfectly. The interface is nice with the checkbox on the side and the description below. (The table layout may not be the best solution, but that's another story, no use discussing that now.)

Personally I don't need the added window height, but that may differ a lot depending on circumstances.

One thing that actually doesn't work is the alt attribute itself – it's empty in the rendered html! (That's when using filter tag, haven't tried HTML.) I found this in theme_img_assist_inline():

<?php
  $node->title = strip_tags($caption); // change the node title because img_assist_display() uses the node title for alt and title
  $img_tag = img_assist_display($node, $size);
?>

So... the problem is: $caption is used for the alt attribute, but it's also printed beneath the image. So instead of altering how $caption is constructed (which the patch does) I guess we need to change the first line in the code above so that it does $node->title = check_plain($attributes['title']) or similar.

But then we're actually altering (a small part of) the behavior of the module. Would that be a problem? An alternative approach would be to have the checkbox decide if the whole $caption (which is the title + the description) should be printed or not, and leave the alt attribute as it is now. I think I'd prefer that actually.

Also, I noticed that your changes from back when you were fixing the original images are included in this patch, could you make a new one?

Hey, good work!

moonray’s picture

StatusFileSize
new9.62 KB

Thanks for catching that. I could have sworn it was working properly.

New patch attached. Removed "original image" code (oops!), and fixed the alt attribute being empty.
Make sure you clear your cache after applying the patch.
DELETE FROM cache; DELETE FROM cache_filter; DELETE FROM cache_page;

moonray’s picture

Version: 6.x-3.x-dev » 5.x-1.x-dev

Actually, this patch is against 5.1-1.x-dev

jaredwiltshire’s picture

Good idea. But I just tested the patch and the title doesnt appear for me when the "Alt only" box is not ticked.

moonray’s picture

What does your image tag look like? And did you clear all your cache after applying the patch?

sun’s picture

Status: Needs review » Needs work

Patch needs to be re-rolled against latest development.

sun’s picture

Status: Needs work » Closed (duplicate)

Marking as duplicate of http://drupal.org/node/68661

adzio’s picture

Version: 5.x-1.x-dev » 6.x-1.x-dev
StatusFileSize
new8.36 KB

Ported the patch to 6.2, fixed a typo.

perfectmatch’s picture

Hi,

Am just applying the patch and am getting the following error :

Parse error: syntax error, unexpected T_STRING in ......... /public_html/x/modules/img_assist/img_assist.module on line 1646

elseif ($attributes['title']) {
- $caption = ''. $attributes['title'] .'';
+ $title = $attributes['title'];
+ if ($attributes['alt'] == FALSE) {
+ $caption = ''. $attributes['title'] .'';

Any ideas?

Thanks