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.
I was asked for this by a client after migrating her site from a custom CMS where images had quite long descriptive text attached. Newly uploaded images had to have very short descriptions. After verifying that there was no limitation in the DB or additional form validation I managed, using hook_form_alter and an #after_build function, to alter the description field to be a textarea, which now seems to be working fine.
This is not the ideal way to handle the problem: it would be great if the module made it easier, perfect if there were a switch in the admin form for the field.
Comment | File | Size | Author |
---|---|---|---|
#6 | filefield_description_type.patch | 777 bytes | quicksketch |
#2 | filefield_description_length.patch | 620 bytes | quicksketch |
Comments
Comment #1
quicksketchThis issue in the ImageField queue might also be of interest: #331713: Increase maximum length of title and alt attributes.
Comment #2
quicksketchThis patch simply makes the description length a variable and sets it to the current default of 128 characters. I'd probably discourage using the description field for extensive text though, since the description defaults to being used as the link text when using the "Generic files" formatter. Instead (if you're uploading images), you should use the "Title" field provided by ImageField, which is currently set to support up to 500 characters and can easily be converted into a textarea.
Comment #3
drewish CreditAttribution: drewish commentedhrm... can we do it here or should i open a followup to allow longer descriptions to be edited in a textarea rather than a textfield?
Comment #4
drewish CreditAttribution: drewish commentedmayhaps?
Comment #5
quicksketchUsing this ticket is fine. In #331713: Increase maximum length of title and alt attributes we discussed a little bit about the intended purposes for title and alt. I don't think description should really support longer strings, because the intended use of the description field matches the way that upload.module works. That is, the description is the text of the link when using the Generic Files formatter. If it had been up to me, I wouldn't have included the description field at all as an option for ImageFields, but it's there now and it's too late to change it now.
So, even though I'd like to discourage the use of the description field for really long text, I'd be fine with implementing a variable_get() to change the type, but I don't want this to have a configuration option like we've done for the title field.
Comment #6
quicksketchFixed with attached patch. Drewish, let me know if you think any changes are necessary.