I suppose the main purpose of the Description field is to be used as a caption or description for the image being uploaded.
Only after I wrote my node-xxx.tpl.php with $node->field_image[0]['data']['description'] everywhere and created several nodes with it, I realized there was a limit to description's length.

Often, 128 characters is not enough for a good description. It may be ok for alt and title, but one should be able to store longer strings in descriptions.

Is there an easy fix (or hack) for this, or should I created another cck textfield just to handle descriptions? I tried to find any clue on where this length is set in the module, without success.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

drewish’s picture

extect’s picture

Project: ImageField » FileField
Version: 6.x-3.0-alpha2 » 6.x-3.0-alpha5
Status: Active » Needs review

I also think the description field should allow more characters than just 128. However, the description field seems to be controlled by the Filefield module and not by ImageField.
You will find a patch attached that will set the maxlength to 300 characters. I think that should be enough in most cases.

extect’s picture

FileSize
393 bytes

Ooops! Forgot the patch!

dtabach’s picture

Thanks for the patch. It should be applied to filefield_widget.inc, which is part of Filefield module, shouldn't it? I don't have it installed; do I have to enable Filefield to be able to use your patch?

extect’s picture

Correct me, if I'm wrong, but ImageField depends on FileField. So, to use ImageField you will have to install and enable FileField anyway.

dtabach’s picture

You are right. As I don't use FileField, I did not realize it was enabled, just for Imagefield to work. Sorry.

dtabach’s picture

Testing your patch, which by the way worked fine, I found out an unexpected drawback using longer descriptions: they are not indexable/searchable.

extect’s picture

But the indexing problem is not related to my patch, right? As far as I know descriptions don't get indexed at all, no matter how long they are.
However, I agree we should work towards indexing of the description field, but I think we should deal with that in another issue.

dtabach’s picture

Right, the problem is not related to your patch. But now that I know descriptions are not indexed, I'm not sure it is a good idea to make them longer. Unless there is a way to make them indexed.

jpetso’s picture

@dtabach: You could manually store a copy ("searchable cache") of the description in a custom table (e.g. {filefield_descriptions}), by implementing hook_file() in an extension module (e.g. "filefield_searchable_descriptions"). What you're going to do with it depends on your specific use case, but stuff like Views integration should definitely be possible, probably even Drupal's search mechanism has a way to get plugged into those.

dtabach’s picture

@jpetso: That would be great, but I'm afraid writing such a module is beyond my programming skills. Thanks anyway for the suggestion, I learned a lot just from knowing how it can be done. I don't need more Views integration than the default module already gives me, but having descriptions show up in the search results would definitely be a must.

dopry’s picture

umm... this should maybe be a config option? Those are stored in a text column now iirc... so they can be pretty long if desired.

Tony Sharpe’s picture

Subscribe

GuillaumeDuveau’s picture

Project: FileField » ImageField
Version: 6.x-3.0-alpha5 » 6.x-3.0-alpha4
Status: Needs review » Active

I don't think that adding options is a good solution. If you set a large text size for the "description" field for ImageField, then the "description" field for FileField will allow large text too because the "description" fields are both the same : the "description" field provided by FileField. But a file (.doc, .pdf, ... something you have to view outside the website) description can't be long because it's basically on this text that we have the link to the file. Then if your users don't pay attention, they could put a very large text for the file description and you would have the link to the file on a whole paragraph.

What we need to make everybody happy is :
- FileField
-- a short description
- ImageField
-- a short description
-- a short text for the "alt" attribute
-- a short text for the "title" attribute
-- a longer text for detailled information about the image

What we have now is :
- in FileField
-- the "description" field, max 128 : used for the text of the link to the file
- in ImageField
-- the "description" field, max 128, provided by FileField : used to print basic information about the image
-- the "alt" field, max 128 : used for the alternative description ("alt" attribute)
-- the "title" field, max 128 : used for the mouseover on the image ("title" attribute)

We just need a new field :
- in ImageField
-- the "long_description" field, textarea, no size limit : used to print detailled information

What do you think of this ?

extect’s picture

Well, sometimes it's already difficult to tell customers the difference between alt, title and description. So, I don't think having another text field for detailed information about an image is a good idea. However, I agree that it isn't optimal to have the same length for the description for imagefields and filefields. So maybe we just need a setting for the length of imagefields and another one for the length of filefields?

GuillaumeDuveau’s picture

So maybe we just need a setting for the length of imagefields and another one for the length of filefields?ATM I don't think it's possible since they share the same "description" field, and I suspect the field can't have different options when used in different situations. But maybe yes ?

I agree with you, adding a text field adds complexity, but like the "alt" and "title" fields you could disable it in a given Imagefield field.

A large textarea makes sense because it could fill a lot of needs like : large description, copyright, credits, ...

OR ! Let's dream : an Imagefield could have EXIF and IPTC tags, automatically extracted from the picture. Image module had it at least in D5 I think, maybe some code can be reused. But it's sure a lot of work !!

Tony Sharpe’s picture

A current problem with the description being longer than the title occurs if you just have description and title enabled or description and alt. The description gets inserted into the non-enabled attribute so the description would presumably get truncated. I want to use short alt text and longer description but I want the non-enabled title tag to pick up the alt text, not the description.

quicksketch’s picture

Status: Active » Closed (won't fix)

I don't think adding more information to ImageField is really necessary or desirable in the long run. Like dtabach brought up, descriptions/alt/title texts are not indexed or searchable, so that's definitely one drawback that would prevent use from wanting to add something like "caption" as yet another field.

The extra fields that are currently available are there because they make up part of the actual output. For example the "alt" and "title" texts are both part of the single piece of HTML that is output. The "description" field is a little more debatable, but again, it's used as the text of the file link or as the title attribute for the link to the file.

Adding something like "caption" or "long_description" doesn't fit with this grouping of data necessary to output the image (or file). It's essentially a separate thing entirely, since it's not needed to generate the IMG tag.

So, in response to all of this, I think we should just sit back and wait for #119102: Combo field - group different fields into one, which looks like it's going to be in the next version of CCK. Then you can add any extra fields you want to a Multigroup and they'll be searchable and completely customizable. FileField/ImageField are both ready to support multigroups thanks to #367267: Compatibility issues with Content Multigroup.

As for EXIF/IPTC, I want to support those also, but that's a different issue. I'm marking this one won't fix and we can just wait for CCK to provide a better solution for us.

GuillaumeDuveau’s picture

Makes sense, even I hate writing this because I'd SO like a quick fix for a site that is in production ;)
But I guess going Combo field with CCK is indeed best in the long run, so I'll try to help a little in that, although I'm afraid it goes beyond my capabilities.
For IPTC, maybe it's not as different, depends if you plan to add read only from IPTC or read/write from/to IPTC. In the second case, a longer description could be provided by an IPTC description field like 2#120.

DamienMcKenna’s picture

Version: 6.x-3.0-alpha4 » 6.x-3.0-beta3

Ok, if a) some people want to limit the fields to reasonable lengths, but b) others have a need to have longer strings for various reasons, how about using variables to define the lengths, default them to the "reasonable" values so that out of the box (or zip file) it works The One True Way but still allowing others to override them?

DamienMcKenna’s picture

Status: Closed (won't fix) » Needs review
FileSize
1.45 KB

Hows about this, based on comment #20?

quicksketch’s picture

This seems acceptable to me. Thanks for bringing up a new alternative we hadn't considered Damien. What does everyone else think?

dtabach’s picture

But patch #21 does not make the field indexable/searchable, does it?
If someone wants longer descriptions, he will eventually want these strings to be searchable. So, IMHO, this is still a partial solution, and the Combo Field still looks like the way to go.
But the patch does not prevent the use of Combo Field, so it wouldn't hurt.

quicksketch’s picture

Yeah this definitely does not solve the searchable problem It's sort of a "well, if you know what you're doing..." solution.

DamienMcKenna’s picture

The searchability is IMHO a completely different issue and shouldn't be lumped into a need by some users/clients to have longer title or alt strings. Once CCK has combo fields I think several modules should be upgraded to use it, inc FileField and ImageField. But that's a different story.

quicksketch’s picture

Title: Description field should be longer » Increase maximum length of title and alt attributes
Status: Needs review » Fixed
FileSize
1.37 KB

Thanks Damien I've committed #21 with the small difference that I set the maxlength of the title field to 500 instead of 128. Any xkcd reader can appreciate the power of long title attributes. However, as noted in the code comments, ALT is left at 80 by default since accessibility standards recommend this be the maximum length for alt texts.

GuillaumeDuveau’s picture

Damien and Quicksketch, thanks so much !

For those wondering how to modify the max length for title (or alt), at the moment there's no GUI settings for it, you need to set the variable imagefield_title_length (or imagefield_alt_length) for example in your site settings.php :

$conf = array(
  'imagefield_title_length' => 2000,
);

One last question however : would it be as easy to allow a textarea instead of the textfield, using a variable defaulting as a textfield ?

GuillaumeDuveau’s picture

Status: Fixed » Needs review
FileSize
751 bytes

Re-opening this to submit a patch allowing to use a textarea instead of a textfield.
I used the same method as Damien with variable_get defaulting to textfield.
So for instance if you want to have a textarea of 2000 characters for the Imagefield title, put this in your settings.php :

$conf = array(
  'imagefield_title_length' => 2000,
  'imagefield_title_type' => 'textarea',
);

I'm crossing my fingers for this patch to be accepted for the stable release !!!
And thanks for the awesome work on Imagefield/Filefield :)

GuillaumeDuveau’s picture

Version: 6.x-3.0-beta3 » 6.x-3.0-rc1
quicksketch’s picture

Version: 6.x-3.0-rc1 » 6.x-3.0-beta3

Hey guix, I almost committed something extremely similar when I accepted DamienMcKenna's patch, only I made it an option for ALT text too. But then I realized, I didn't really want users to be able to make textareas for ALT text, since it's really encourage bad practices. Title fields are different and I'm glad to see that your patch doesn't affect the ALT text at all. Now that the default length is 500 characters I doubt length will be a problem, but I agree it might be good to be able to make title a text area instead.

Rather than making this a universal (and hidden) feature, I think I'd really prefer to make it a configuration option. Do you think you could make this into a select list on the field configuration form?

GuillaumeDuveau’s picture

Version: 6.x-3.0-beta3 » 6.x-3.0-rc1
FileSize
4.26 KB

Hi Quicksketch,

How about that one (against RC1 & head) ?

I added two configuration options for an ImageField :
- a title length value, defaulting to 500 (maybe the default could be reduced as it is very easily configurable with that patch)
- a selection of the title input type, with the options textfield and textarea, defaulting to textfield

I totally agree with you on the ALT text. In fact in that patch I disabled the variable_get for the ALT and it is now fixed again to 80. I did this because in that issue, and users in general I think, only need ONE big field where they can put all their blabla :D. But I can put it back again if you want.

GuillaumeDuveau’s picture

FileSize
4.26 KB

Ooops that one was broken, here's the fixed patch.

quicksketch’s picture

Thanks guix! A couple things to look out for, we need to check that $field['widget']['title_type'] has a value, for users upgrading this would be NULL and cause them some trouble when #type = NULL. Also I'm not sure if we want to make maxlength a configurable option. We could of course (you already did the legwork after all), but #maxlength doesn't affect textareas since a textfield only HTML property.

GuillaumeDuveau’s picture

FileSize
3.36 KB

Another one then :)

I removed the configuration of the maxlength but left the possibility to tweak it with a variable in the settings.php.
For title_type, isn't

'#default_value' => !empty($widget['title_type']) ? $widget['title_type'] : 'textfield',

OK to put textfield as the default value even for upgrading users ? If $widget['title_type'] is empty it defaults to textfield, doesn't it ?

See you
Guix

GuillaumeDuveau’s picture

FileSize
3.44 KB

Mmm OK I've just understood what you meant.
Implementation is not very nice, but here it is.

quicksketch’s picture

Thanks guix, I'll review it shortly.

thePanz’s picture

I notice in the code the "title_type" textarea/textfield description and WYSIWYG warning.

Starting from D7 (and some WYSIWYG modules implements that earlier) you can tell if a textarea will use WYSIWYG features. Just add, in $element['data']['title'] form item the item:

['#wysiwyg'] => FALSE,

Regards

mgifford’s picture

Issue tags: +Accessibility

Webaim has some good suggestions on this issue here - http://www.webaim.org/techniques/images/longdesc.php

geerlingguy’s picture

Okay, so if I want to allow 500 or so characters in the 'alt' field, as per instructions in #27/28, how would I do that? Open settings.php in my sites/default folder, and paste in those lines, replacing 'title' with 'alt', like so?

$conf = array(
  'imagefield_alt_length' => 2000,
);
GuillaumeDuveau’s picture

Geerlingguy, in the latest patches (#31, #34, #35) I disabled the possibility to customize the alt length, the max stays 80.
If you need to custom the alt length now, just use the patch in #26 or #28.
For the long term support, let's see what Quicksketch wants to do with this.

@thePanz: Thanks, nice feature for D7 !

geerlingguy’s picture

@ guix - thanks - will do.

My 2¢: I would like to use the Alt field for a photo caption for a newspaper website I'm working on... most captions are under 100 words, but sometimes they use two sentances, and it confuses people when they can't type anymore, especially if there isn't a warning that pops up and says you've reached your limit. Maybe you could at least put a little note under the field that says "limit 80 characters" or something along those lines?

thePanz’s picture

@guix: you can use that FAPI starting from now in D6, IFAIK some modules (FCKEditor) implement that feature in D6 version and don't show WYSIWYG controls on those text-areas
My 2¢

quicksketch’s picture

Status: Needs review » Fixed

I've committed the guix's patch from #35. I left in the configurable alt text length, and I omitted the WYSIWYG warning. This isn't really the appropriate place for such a warning, especially since "good" wysiwygs won't cause this problem at all to begin with. CCK doesn't provide warning like this for select list options or for default value code.

GuillaumeDuveau’s picture

Thanks a lot Quicksketch :))

Status: Fixed » Closed (fixed)

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

Trunkhorn’s picture

I just tested this and didn't see any place to change the description from a textfield to a textarea. I see it for the title but not for description.

Trunkhorn’s picture

I just tested this and didn't see any place to change the description from a textfield to a textarea. I see it for the title but not for description.

GuillaumeDuveau’s picture

Trunkhorn, my idea was to allow this for ONE field only (title), in order to force users to give a short description as well. The short text can be used for views for instance and the longer in the node body.

GuillaumeDuveau’s picture

Version: 6.x-3.0-rc1 » 6.x-3.0
Status: Closed (fixed) » Active

The more I think about it, the more I find that we (I...) should have allowed the textarea and to customize the max_length for the description field and not the title. Obviously nobody wants a big title since browser are (without extensions) limited in the title length ; whereas a big description with a textarea could be usefull on websites like ours, in which the images have a lot of caption and copyright text. Moreover the field that is usually displayed in div, p or span in the nodes/views/... is description, not title... Using title like I use it is a bit hacky I'm afraid (and we have to theme everything to invert title/description).

I chose to use title because I did not see any way to change the description field inherited from filefield. But maybe it's possible ? To add a max_length option and a textfield/textarea option ? If possible, do you think we can go back (bad, bad, I'm very sorry for this) ?

Another approach may be to add a new widget, maybe in an independent module.

I'm willing to fix this, in order to have a better solution until we have Combo fields, which approach would you advise ?

quicksketch’s picture

You can increase the size and field type of the description field if it's truly necessary by setting some variables. For example you could execute this code in the devel "Execute PHP" block:

variable_set('filefield_description_type', 'textarea');
variable_set('filefield_description_length', 1024);

However the reason why there are not options for this in the UI is because the description field was never intended to be used with ImageFields. It was an unfortunate side-effect that was never corrected and now impossible to change because thousands of websites are using it.

The purpose of the description field is to replace the title of the file link when FileField displays content. As you're probably aware, ImageField doesn't even output the description at all (because it was never intended to be used with ImageField).

So there is no UI option for increasing the size of the description field because the purpose of the description field (when used with a FileField) does not require a textarea, because you would want to display a link that is multiple lines long linking to the file.

GuillaumeDuveau’s picture

Status: Active » Fixed

Thanks a lot for the support Quicksketch. I didn't even look at filefield_widget.inc, indeed I can use those variables to achieve what I need. I'll do like that until we have Combo fields.

geerlingguy’s picture

@ quicksketch - I've been using the alt field, mostly because the caption usually *is* the description of the picture, whereas the title would be a 'short' caption, with maybe just the names of the people in the picture. The alt captions are usually between 60-100 characters, whereas titles are usually 30-60 characters.

Just for consideration, you might want to make it (alt/title caption options and text area vs. field) more configurable via admin interface, as some people just want a quick way to add a caption inside the field, and might not have the knowledge to make a template file for this purpose.

GuillaumeDuveau’s picture

I don't know, since these fields are NOT for those kind of uses, I think it's fine if it requires a minimum of knowledge to use them like this (set a variable... not so difficult !). Otherwise when we do have a clean solution like Combo fields, those users could ask for an upgrade path and complain ?

geerlingguy’s picture

Ah well, just thinking out loud really. I'm okay with doing the changes manually, but hopefully someday there's an easy solution to adding captions to photos, as news-style websites rely on this functionality.

Status: Fixed » Closed (fixed)

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

Stephane Bouillet’s picture

Really thanks for the #3 !!
I've search a long time where to correct the maximum lenght of the fied description in image field and other.
So it is just in the "filefield_widget.inc" file
I've alo changed "textfield" into "textarea", and as for me changed "128" by "1000"

Thank you !!!

pacome’s picture

Hi all,

thanks a lot for all this work, it's a great feature !

But do you think there is a way to insert basic html tags, like Filtered HTML ?
It would be great to be able -at least- to break lines..

Best
-P-

AdrianB’s picture

Regarding #50: That seems like a decent temporary solution while waiting for the combo field to reach stable versions. But, and this may be a newbie question; Is that a safe operation to do? Will it be persistent through updates etc?

livingegg’s picture

Status: Closed (fixed) » Active

So where is this at?

Currently it seems the only way to have a per-image text field with unrestricted length, is to hack/patch the module. Is this correct or did I miss something?

The "content multigroup" route suggested by the maintainer (#18) it seems will not be available until CCK3 and so is not possible to use at this time.

IMO it would have made sense just to add a new text-area form field to ImageField and name it something like "caption" or "long description" - it may not be idealogically ideal, but isn't it a better alternative than just leaving it up to the user to hack the module just to include this obvious feature?

Not that there's anything wrong with hacking the module, and not that I'm unwilling to do that, its just kind of a pain in the rear to continually upgrade/patch multiple modules everytime theres a security update - its difficult to track all that for 10 different sites and it kind of disrupts the idealogical drupal workflow, know what I mean?

Regards,

-g

---------edit----------

It looks like this module [http://drupal.org/project/imagefield_extended] might solve the problem right now in the "legitimate" way. Not clear if it is safe to use for a production site or not.

livingegg’s picture

Status: Active » Closed (fixed)

Closing the issue again as it seems that http://drupal.org/project/imagefield_extended is the official stop-gap measure in place until the more abstract multifield support is solidified in CCK3 and D7.

Daniel Wentsch’s picture

Is anybody aware of a solution to increase maxlength of alt attributes in Drupal 7?
Imagefield Extended doesn't exist for D7.

ph0enix’s picture

Attached D7 patch extending alt and title to 512 bytes. You should also update manually *_alt and *_title column length in database for all image field tables (example how it look on attached screenshot). This patch also fixes PDOException issue when you are trying to upgrade D6 image fields with increased size to D7 using content_migrate module from cck.

UPD:

Drupal 7.12 increased alt length to 512 and title length to 1024.