Download & Extend

Add Description text for image fields

Project:Drupal core
Version:8.x-dev
Component:image.module
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs review
Issue tags:adding description, D7 upgrade path, drupal 7 image field, html5, needs backport to D7

Issue Summary

There used to be a "description" field to go with uploaded images using the ImageField CCK module. This particular field made the ImageField module very useful as clients often provide copy to accompany multiple uploaded images within a single node. In Drupal 7, however, this "description" field is missing.

I have tried commenting the following line in the image.field.inc file in the function image_field_instance_settings_form($field, $instance):

// Remove the description option.
unset($form['description_field']);

Surprisingly, this seemed to work. However, I am concerned about the long-term ramifications of this solution, particularly when I apply updates to Drupal. I am wondering why this vital functionality was removed in the first place and what official workarounds there are for its absence.

Comments

#1

We need this field lots of times as well (comes in handy when using Views Galleriffic).

Thanks for this contribution, because that's exactly what we're looking for.

#2

i kinda missed this feature as well, i dont wanna go back to d6 :(
subscribing...

#3

I am concerned about the long-term ramifications of this solution, particularly when I apply updates to Drupal.

Does it save the content of the description field properly?

#4

I suggest instead of removing the unset(), you put a dpm($form['description_field']) in there to find out how the form element looks like, then implement a hook_form_alter() that reimplements the form element (with a condition to see if it doesn't exists) in a custom module. This way you don't have to patch core, which is really bad practice.

#5

I'm trying to add this back too. It would nice if it was just enabled and then we can enable it if we choose to like the alt/title. In D6 I used the description field for image captions that were longer than the 80 char limit of alts.

I took a crack at trying to add the field via hook_form_alter() which I've used for other things. But this seems like it might have twist with the new function image_field_instance_settings_form(). I'm not sure how to go about this, it's a bit over my head.

Thanks for reading,
-Tim

#6

Title:Description field missing in Drupal 7.» Description text for CCK image fields missing in Drupal 7.

Just renaming the issue title to mention "image field".

#7

subscribing...

#8

The dev-version of CCK 6.x-3x is now shipped with multiple fieldgroups, so I think that's the easiest way to get the job done.

I wonder if this was being ported to D7.

#9

Going into core and commenting the line of code that "unsets" the description field worked only partly for me. The filed now appears next to the image I have uploaded: so far so good. However I encounter two problems: number one, the text that I enter does not seem to save: field is blank whenever I navigate back to the add content form. Number two: I cannot find a description-data field to add into a view, like I used to in Drupal 6, so that even if I did get a description field in, how would I get to see and develop it? Anyone have any thoughts on this to get descriptions actually working in D7 this way?
Thanks.

#10

After much trouble and much forum reading of clever solutions that I could not get to work, I was able to get the image title to display in the following way. I used the image title option and a little php in a views template.

Enable image title in image field of a content type
add in a title when uploading an image
go to views-view--field.tpl.php template, reformat to
views-view-field--field-image.tpl.php, save in theme folder.

past in the follwing php after

<?php
print $output;
add:

$newoutput = split ('"', $output);
?>

<?php
print $newoutput [7];
?>

[7] was the number of my title field, I am guessing this number would vary.
hope it helps someone!

#11

Note: while the above code does pull the title out, Drupa doesn't seem to like it too much. There's an error message that I can't make go away, so maybe this is not the solution...still looking 8-I

#12

Title:Description text for CCK image fields missing in Drupal 7.» add Description text for image fields
Version:7.0» 8.x-dev
Category:support request» feature request

don't mind I change it into feature request.. we need it back in D8

#13

Priority:normal» major
Status:active» needs review

first patch :)

- Needs maintainer comments to make sure it will be back in D8
- Needs comment on how to display description

AttachmentSizeStatusTest resultOperations
img_desp.patch1.22 KBIdlePASSED: [[SimpleTest]]: [MySQL] 33,536 pass(es).View details | Re-test

#14

Just want to make a module for D7 but unluckily ..... no way to alter DB
#691932: No hook_field_schema_alter()

#15

After applying the 7.7 update and re-applying the above patch the image descriptions are no longer exposed in Views "REPLACEMENT PATTERNS", they worked previously.

#16

subscribing

#17

It doesn't solve the issue, but I found another solution to "link" a txt area with an image field, I described it here : http://drupal.org/node/974888#comment-5039486

I used field-collection module, created a field-collection with an image-field and a long text field.
The field collection items (image + txt) can be then used in Views, like images+description : the field-collection is reacting like any other field.

It works as well with views-slideshow, and can be extended with more fields related to the image.

hope it can help

P.

#18

pacome, that's a good solution for new sites/adding-to-an-existing-site but I have a need to migrate from D6 to D7 and the description field was something we were relying on. It's "sorta" there it would appear. Recreating the feature totally seems like a work around instead of a fix.

Any news on progress with this fix? Is droplet's patch something that Webchick will bless?

Related:

Deep in CCK's content_migrate module, changes will have to be made to "content_migrate.filefield.inc" It *might* be as simple as adding

$record[$field['field_name'] . '_description'] = $data['description'];

...within...

    case 'image':
      // Map D6 imagefield field columns to D7 image field columns.
      if (!empty($record[$field['field_name'] . '_data']) && ($data = unserialize($record[$field['field_name'] . '_data']))) {
        $record[$field['field_name'] . '_alt'] = $data['alt'];
        $record[$field['field_name'] . '_title'] = $data['title'];
      }
      else {
        unset($record[$field['field_name'] . '_alt']);
        unset($record[$field['field_name'] . '_title']);
      }
...

...am I right?

EDIT: I think so - successfully migrated description content from D6 to D7 with droplet's patch and the following additions to "content_migrate.filefield.inc":

    case 'image':
      // Map D6 imagefield field columns to D7 image field columns.
      if (!empty($record[$field['field_name'] . '_data']) && ($data = unserialize($record[$field['field_name'] . '_data']))) {
        $record[$field['field_name'] . '_alt'] = $data['alt'];
        $record[$field['field_name'] . '_title'] = $data['title'];
        $record[$field['field_name'] . '_description'] = $data['description']; //-- NEW
      }
      else {
        unset($record[$field['field_name'] . '_alt']);
        unset($record[$field['field_name'] . '_title']);
        unset($record[$field['field_name'] . '_description']); //-- NEW
      }

... I SO have to spend the 10 minutes it would take to learn to make diff patch files myself :\

#19

Status:needs review» needs work

Based on comments, this is NW.

#20

In the meantime, you might be able to use Field Collection and Field Slideshow. At least Field Slideshow says you can create image captions and such using the Field Collection module (I haven't tried it myself, but my search brought me to this page and to the following pages).

http://drupal.org/project/field_slideshow

http://drupal.org/project/field_collection

#21

For new sites, or new content that would use slideshow modules, that would work, ergophobe. But that's not the problem here. The problem is that for those of us migrating a D6 site to the D7 schema, data is lost. The Description attribute of an image field isn't migrated in any form.

Ultimately, the message from Core devs is "Going forward, don't depend on this field". OK, I can roll with that going forward - but in the meantime I have to hack the core to support the description attribute until I have a field migration plan to something that will be supported going forward.

Migrating from D6 to D7 for anything more than a hobby-site can be a big Big BIG job!

#22

I know it's not by default, but the File Entity module is going to allows files to be fieldable. This seems like a more robust solution.

http://drupal.org/project/file_entity

#23

Ultimately, the message from Core devs is "Going forward, don't depend on this field". OK, I can roll with that going forward - but in the meantime I have to hack the core to support the description attribute until I have a field migration plan to something that will be supported going forward.

Wow, holy shit, really? That's sad.

#24

Yeah, I realize that. More than you might guess. I'm nearing the end of a D6 => D7 migration with several complex data types. Little if anything came through the way I expected. I ended up having to create a new structure in D7 and then write SQL queries, run scripts and do tons of hand editing to get everything from D6 to D7. Sometimes I misunderstood how things were done in D7, borked everything and had to roll back to the last stable state and start over.

So yes, I know how hard this can be and I know those modules won't help everyone in this case (most notably, they don't get *me* where I want to be). But I figured I'd mention them. I also experimented with trying to move everything into using the Media suite of modules, but that really didn't fit my needs.

I'm going to check out the File Entity module mentioned in #22, but I'm in that same position of not wanting to hack/patch core and not necessarily wanting to throw out the Description field.

#25

Category:feature request» bug report
Issue tags:+D7 upgrade path, +needs backport to D7

I think it wouldn't backport to D7. I'm tagging it and looking for Webchick comment.

Image in D7 is also miss "Enable Display field & Files displayed by default".

#26

I am having the same problem migrating a website from WordPress to Drupal. WordPress has by default title, alt and two description fields for every uploaded image. I can live without one of them but I can not drop them all…

I know that one of the Drupal drawbacks is still a lack of a more advance image handling method (particularly for non-tech users) but there must be a way of overcoming this issue without waiting for Drupal 8, right…?

#27

Would it be feasible to "clone" the image field in contrib space, creating a complete copy of it, and then adding custom description text fields? This would also require a clone and edit of the image widget to enable input into those new fields, and possibly other cloning work as well.

Unfortunately, I wouldn't know where to start, since the file field isn't defined as a class, so I have no idea if the concept of inheritance could even apply (I'm an OO programmer at heart).

#28

Contrib modules can already alter the existing image field using the field API, e.g. hook_field_info_alter(). Seems like it wouldn't be to difficult to create a contrib module that simply adds these properties to the core field.

#29

But what about storing these new properties in the DB? I'm not an expert module writer; is there a way to get around #691932: No hook_field_schema_alter() ?

#30

Well, it should be possible to store this properties in the DB, even on another table if as it appears there's no possibility of altering the original schema.

The complex thing, as far as I see it not being an expert on module development, could be how to add this extra input fields to the proper widget, how to store the content on the DB on submit and – in my particular case – how this data interact with the Insert module when adding images to the content text area.

#31

Title:add Description text for image fields» Add Description text for image fields
Issue tags:+html5

I think having a description makes sense (for Drupal 8), and it would also make it possible to use <figure> with <figcaption> HTML5 elements for appropriate images, such as images in article nodes. Tagging to track this in the HTML5 Initiative.

#32

Category:bug report» feature request

This is a feature request, not a bug. However, it seems like the kind of feature request that has a shot at being backported to Drupal 7 (especially if the appearance of the description in the UI is "opt in" like it is for File fields)?

I was curious why there's no description currently, so I looked through the Git history a bit. From the issue that originally added image fields to core, #560780-51: Add Image Field to image.module says the description was removed because it was never printed out anywhere in the default theming, so it would therefore be confusing to collect it. (And #560780-104: Add Image Field to image.module suggests the same thing was true for ImageField in D6...)

If we add it to the UI for core we probably have to add it to the default theming also?

#33

@jschrab (#21):

The problem is that for those of us migrating a D6 site to the D7 schema, data is lost. The Description attribute of an image field isn't migrated in any form.

Ultimately, the message from Core devs is "Going forward, don't depend on this field".

Not really sure how that follows. Unless I'm mistaken, Drupal core is not providing an upgrade path from D6 ImageField at all. According to http://drupal.org/project/imagefield, the Drupal 7 CCK package is doing that....

So if there's a bug where data is getting lost on upgrade, it should be filed against CCK. It's not an issue for core to handle.

#34

Component:image system» image.module

#35

@David Rothstein, hey thanks for doing that research.

If we add it to the UI for core we probably have to add it to the default theming also?

It doesn't fit every use case, so I'm not sure how we should do it. The figure/figcaption example is definitely not something that should be a default for images, and I'm not sure how much we really want to complicate output of image fields. But, for field_image inside nodes, it would make sense there as a default and we could use theme hook suggestions for it.

Another thing to consider is that this would be a useful "widget" or "combo" field in general. To expand on the figure/figcaption use, it's not just images that would benefit. Illustrations, diagrams, photos, code listings, etc, are all valid use cases from the spec. Accomplishing this now requires manually rendering only the content of 2 fields a node template, or using a contrib module like field_group to wrap them together (and that markup is really verbose and crappy when done that way).

It think it would be pretty cool and useful functionality to have in core, personally.

#36

@David Rothstein (#33)

So if there's a bug where data is getting lost on upgrade, it should be filed against CCK. It's not an issue for core to handle.

CCK ImageField provides the migration, that's very true. However, the target of the migration is the D7 core field-type of "Image". The core Image module does not have support in its schema for the "description" ( re: image_field_schema() ).

The CCK ImageField may be responsible for migrating the description data (and is not) but D7 core Image field type has no place for "description" to go in its schema for the CCK ImageField migration to use.

It seems to me to be a shared problem between CCK migration AND D7 core. Core needs a schema extension in Image and CCK ImageField migration needs to be aware of it. The patches in this thread are what I have been using to make that possible until I have the time to revise my code dependencies away from "description".

You are right though - Team CCK should also be made aware of this.

#37

Status:needs work» needs review

I think my #13 patch still validated. How to embed it into Drupal can be a separated issue. We should backport immediately.

#1353030: Increase length of "alt" and "title" text for images make into CORE because #691932: No hook_field_schema_alter() (Created in January 22, 2010 at 5:02am, 2 years ago) . we can do once more.

Only description is not enough:
Caption
--- IMG (ALT) (TITLE) ---
Description

AttachmentSizeStatusTest resultOperations
1067620-field_description-36.patch1.33 KBIdleFAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1067620-field_description-36.patch. Unable to apply patch. See the log in the details link for more information.View details | Re-test

#38

jschrab

I have the same issue,can you tell more details of hacking Drupal7 core to solution this,Thanks

#39

@lionheartbf

Everything I know is pretty much all in this thread/issue.

#40

#37: 1067620-field_description-36.patch queued for re-testing.

#41

Status:needs review» needs work

The last submitted patch, 1067620-field_description-36.patch, failed testing.

#42

Issue tags:+Novice

Thanks all. I just tried to apply the patch locally and noticed it needs to be rerolled. Tagging Novice to do a simple reroll / rebase.

#43

Status:needs work» needs review

#37: 1067620-field_description-36.patch queued for re-testing.

#44

Status:needs review» needs work

The last submitted patch, 1067620-field_description-36.patch, failed testing.

#45

Status:needs work» needs review

Quick & Simple patch. anyone review it. Either discard this idea or move forward

AttachmentSizeStatusTest resultOperations
1067620-image-desp-37.patch1.35 KBIdleFAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1067620-image-desp-37.patch. Unable to apply patch. See the log in the details link for more information.View details | Re-test

#46

Issue tags:-Novice

Thanks @droplet, the reroll looks good. Now we probably have to create the upgrade path. That seams to be blocked on #937442: Field type modules cannot maintain their field schema. Given that, I am not sure if this is really backportable. Whether we backport it or not is also important for the name of the update hook, isn't it?

#47

#45 working well for me.

#48

Priority:major» normal

Is this really major? As much as I'd love to see it in Drupal 8, I don't think that it's major. If you disagree feel free to explain and change this.

#49

Count me amongst those who think this should be high priority.
Definitely missed from imagefield in D6...
Did anyone ever find an explanation about why this feature got "unset" in the first place? Seems bizarre taking useful, optional functionality and disabling it completely.

It's gonna get annoying having to apply this patch every time we update D7 core.

Perhaps we're supposed to be using "image" just for images and that's it - alt and title being actually part of the <img> and we should be looking towards field_collection or other such modules for associating other content with the images?

I guess what I'm getting at is that if this issue is going to get downgraded or dropped, some guidance on the best-practice alternative would be appreciated. Alt and Title are not always what I want to use as a caption.

#50

Hi just ran into this thread. We extensively use the description field for image captions and we cannot have the data disappear when we upgrade from drupal 6 to drupal 7. From a user perspective this is a bug in the drupal 7 upgrade procedure and should be committed back to the drupal 7 core. Please let me know if there is anything we can help out with to make this happen.

#51

I needed to add an image caption to display under images in articles. So I added a field called Image Caption with type Text field. I used CSS to position the caption under the Image in the article. This worked for me to display image captions in full nodes.

Note: the image caption module didn't work for me. The image caption filter did help to display the image title attribute as a tool tip.

#52

katy5289, could you elaborate? I'm only in the early-intermediate Drupal stage, but image captions (not just title / alt) are one of the main things I need for my site, for both standalone images and galleries. It's been holding me up for weeks.

I've had some success with field collection and flexslider, but am still trying to get things to align nicely. I also used one of the caption formatter modules, but would prefer to just have it be part of the image field.

Need this for article (ck-placed) as well as drupal - placed images in nodes, and if possible, something that would also work insdie image galleries.

#53

@muranod - I've being using the JCaption module which simply grabs the title or alt text of your image and renders it as a themable caption. The module has a lot of settings most of which I turn off but it works great. You can also specify which type / classes of images you want to have captions in the module's UI.

#54

@highrockmedia - Thanks. I'll have a look at that this weekend, though I was hoping to have an actual long text field rather than using the title / alt fields, if possible.

#55

I'm only 11 months into Drupal, but I find this an essential function, to have a long text field to associate with an image for use as a caption. Title and Alt just don't cut it for me.

A lot of people are telling stories visually - it just makes sense to be able to add paragraphs of text, if needed, to individual images which can then go into a gallery. Yes, it can be done with field collection, but it's not always a smooth process (depending on the gallery module or formatter used).

I have spent more time trying to achieve this than I have on any other part of my site, which is already live, minus any photo galleries. As good as Drupal is, I find the image handling to be rather anemic, especially because of the lack of a long text caption field. and what is available seems quite convoluted at times.

It looks as if this is changing, but progress in that direction seems very slow. If I had the skills ...

#56

Is something happening about this issue? I´m waiting and hoping that there will be a solution soon.

#57

If you don't have legacy content, then the solution I mentioned above would work, as would the Media Module as would File Entities.

On the latter method, quicksketch did a presentation at BADCamp and has posted his slides:
http://quicksketch.org/node/5744

#58

But how do you do this ? "Enable image title in image field of a content type" in drupal 7 ?

#59

Another option for this though it might be a little excessive would be to use the Field Collection Module, then you would have true one to one text field per image and any amount you want within one node. The theming possibilities are endless. I've used that module quite a bit for projects and it solves a lot of these types of issues.

@dianacastillo - yes you have to enable image title but that doesn't really get you all the way there. To use the title as caption, you'd have to use a Jquery caption module or simple code as illustrated below that grabs the title and makes it a text caption. For example you could do this in your theme's custom js file. (Or you would need to create one.)

(function ($) {
// Add drupal 7 code.
  Drupal.behaviors.miscfunctions = {
    attach:function (context, settings) {
// End drupal calls.

// Set image captions for image field.
  $(".field-type-image img").each(function (i, ele) {
    var title = this.title;
      if ($("img-caption").length == 0) {
        $(this).closest(".field-type-image .field-item").append("<span " +
          "class='img-caption'>" + this.title + "</span>");
        }
        else {
          $(this).closest(".field-type-image .field-item").append("");
        }
  });
  }}})
(jQuery);

#60

That doesn't answer my question . '"HOW" do you enabled the image title?' is what I need to know. Where is there that option?

#61

No way, that's why we create this issue. (I meant desp)

@dianacastillo,

edit your image field and scroll down
" Enable Title field "

#62

After applying patch #45 to Drupal 7 and adding node with image where is Image description field I'm getting error:

PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'field_image_description' in 'field list': INSERT INTO {field_data_field_image} (entity_type, entity_id, revision_id, bundle, delta, language, field_image_fid, field_image_alt, field_image_description, field_image_title, field_image_width, field_image_height) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11); Array ( [:db_insert_placeholder_0] => node [:db_insert_placeholder_1] => 39 [:db_insert_placeholder_2] => 39 [:db_insert_placeholder_3] => referenssi [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => 45 [:db_insert_placeholder_7] => [:db_insert_placeholder_8] => This is image [:db_insert_placeholder_9] => [:db_insert_placeholder_10] => 1632 [:db_insert_placeholder_11] => 1224 ) in field_sql_storage_field_storage_write() (line 448 of /home/xx/modules/field/modules/field_sql_storage/field_sql_storage.module).

#63

THANK YOU!! I had been waiting for three days for that answer. I went to manager my content type, edited the image and saw
admin/structure/types/manage/slider-content/fields/field_image

Enable Title field.

#64

In order for this patch to work on existing sites, you will have to manually add a couple fields to a couple tables in the database. You can do with with 2 simple MySQL commands or with a tool like phpMyAdmin (assuming you are using MySQL), if you prefer clicking (like I do sometimes).

Like your error says: 'field_image_description' column (or field) is not found in your 'field_data_field_image' table... so, fire up mysql and add the missing column like this:

ALTER TABLE  `field_data_field_image` ADD  `field_image_description` TEXT NULL

At this point if you try to upload an image a save the node it will give you a similar error but for a different table. So, run this mysql command:

ALTER TABLE  `field_revision_field_image` ADD  `field_image_description` TEXT NULL

Now the patch should work as expected. Don't forget to configure your image fields to include the description on the form.

The reason you can just add this patch and have it add the tables for you is because the patch modifies the .install file of the image module. .install files are only executed when a module is enabled. So, in theory another way might be to disable the image module (be sure to uninstall as well) and re-enable it to have these table recreated for you; But, I have not tested this approach.

#65

This issue inspired this module for D7:

http://drupal.org/project/image_field_caption

#66

Thank you so much for this!!! It makes using ad_gallery module on drupal 7 so much better!

#67

#45: 1067620-image-desp-37.patch queued for re-testing.

#68

Status:needs review» needs work

The last submitted patch, 1067620-image-desp-37.patch, failed testing.

#69

Status:needs work» needs review

Just posting a related issue here about longdesc - #1971222: Incorporate longdesc into image support

Also, it's really worth looking more at Jacine's comment in #31 & #35. She disagreed with the default use of figcaption, but it could be a nice optional checbox to use figcaption for added descriptions:
http://www.w3.org/wiki/HTML/Elements/figcaption
http://caniuse.com/#search=figcaption
http://html5doctor.com/the-figure-figcaption-elements/
http://www.techrepublic.com/blog/webmaster/html5-figure-and-figure-capti...

#70

Title:Add Description text for image fields» How to add text in image field in content type
Version:8.x-dev» 7.20
Category:feature request» support request

Hi,

How to add text in image field in content type.

I need to add multiple banners with different images with different text in basic page i.e after adding image field in basic page content type ...how to add text in images.

Thanks in advance.

Thanks,
Vin

#71

Title:How to add text in image field in content type» Add Description text for image fields
Version:7.20» 8.x-dev
Category:support request» feature request

@vinod.honey,

This is not a support issue thread, Please open a new one for your problem, Thanks.

#72

Related issue #1971222: Incorporate longdesc into image support

figcaption has great browser support. I think we should make it available.