Here are my specs:

CCK: 6.x-1.x-dev (2010-Apr-20)
ImageField 6.x-3.3
Permissions (Drupal / Apache default)
Public download

I have a simple imagefield in a node to display a logo and I checked the box to make one logo required for each node. I also have Custom Alt and Title text enabled as well.

The required field function works fine for the logo image itself but what I have found is that a logo is uploaded and the custom alt and title text can be left blank.

It seems to me that good practices dictate that these should be required as well. (see my screen capture)

Comments

quicksketch’s picture

One of these modules may help with this request:

http://drupal.org/project/imagefield_extended
http://drupal.org/project/filefield_uiextras

ImageField does not include this functionality. Since ImageField has been moved into Drupal 7 core (as Image module), we can't add new features to ImageField in Drupal 6, so it will need to be provided by an add-on module either way.

quicksketch’s picture

Status: Active » Closed (fixed)
jenlampton’s picture

Title: Custom Alt and Title should be required if imagefield itself is a required field » Accessability: Custom Alt text should provide an option to be required
Project: ImageField » Drupal core
Version: 6.x-3.3 » 7.x-dev
Component: User interface » image system
Status: Closed (fixed) » Active
Issue tags: +Accessibility
StatusFileSize
new46.13 KB
new46.3 KB
new30.06 KB

Government and Educational institutions, in particular, care a lot about accessibility. They continue to request a way to make the custom ALT text field required so that content creators can not submit a node form without ALT text for all images.

Neither of the two modules recommended above will solve that exact problem. My suggestion so far has been to create a custom module that alters the node forms that contain image fields, and force the field to be required. But I haven't yet found a solution that doesn't require custom code.

What I'd prefer to see:
1) an additional checkbox on the edit field settings page for "Require ALT text" (see image_alt_field.png)
and if the box is checked...
2a) if an image is selected and a user hits "Upload" the ALT text field that appears is now required (see img_alt_required.png)
2b) if an image is selected and a user hits "Save" instead of "Upload" the image is uploaded, but the form fails validation, and requires that the ALT text be added (see img_alt_req_fail.png)

damien tournoud’s picture

Version: 7.x-dev » 8.x-dev
Category: support » feature

I'd definitely support this, but it is a feature request.

For Drupal 7, it's would be fairly easy to provide this as a contribution module.

mgifford’s picture

StatusFileSize
new27.78 KB
new27.78 KB
new49.17 KB

I agree that this needs help. It's great that images support is in core, but it could be done a lot better for accessibility.

I've added some screenshots for how it is in D7. Hopefully we can use hooks in core to implement a best case solution with the help of the http://drupal.org/project/accessible module.

EDIT: Worth also looking at this thread from the ImageField module's issue queue.

Also worth noting that putting in just anything into an alt text should produce an error. An alt text should never be the same as a file name. Spaces should be considered the same as empty. There should be room for acceptable tags for placeholders like 'spacer' or 'blank' as often images are used just to manage positioning.

Use of identical title & alt attributes can also cause problems [520704] - some screen readers read out both.

quicksketch’s picture

For Drupal 7, it's would be fairly easy to provide this as a contribution module.

As in the ImageField queue, I think we need to balance the accessibility-friendly with usability-friendly options. If you start giving users errors that their ALT text is required, and then another error that the alt text isn't "good enough", people aren't going to like creating content in Drupal. IMO, such frustrations should be kept to contrib, even in Drupal 8.

mgifford’s picture

Might make sense to leave it in contrib. Possibly that level of validation could be done through jQuery so that the user could be better guided to provide a good alt tag. In many ways it's really not all that easy though. Content creators can benefit from being prompted about what makes a good alt tag for an image. A government or university department may need for there to be stricter policies.

But yes, certainly all things to consider and implement as resources & inspiration allows.

jenlampton’s picture

What about a "require alt text" option, that is by off default?

mgifford’s picture

why off by default?

jenlampton’s picture

So people keep enjoying creating content in Drupal :)

Everett Zufelt’s picture

I do think that when creating an image field that there should be an option for requiring alt text, however, I do agree that it should be off by default.

1. Administrators might not understand the option, in which case off is the best choice for them (when they begin to experience problems they won't understand why.
2. Administrators that know that they want the option can turn it on

mgifford’s picture

Perhaps could we strive to have a message pop up to warn folks that they've added an image without an alt tag by default? Not a error that would stop them from uploading the page, but something which clearly lets them know that it is an issue.

Maybe this warning message would probably need to be configured to be turned off too. I'm just afraid that with the status quo, we're not going to change content administrator's behaviors.

Everett Zufelt’s picture

Perhpas we need better description / help text for the image field widget?

mgifford’s picture

Ties into documentation here - http://drupal.org/documentation/modules/image

quiptime’s picture

Drupal 7:
To make required the Alt field of a image field it is possible to use the EIM module.

mgifford’s picture

Neat. Will have to look at that and add it to the docs! Thanks Quiptime.

jenlampton’s picture

@mgifford I don't think an error message is necessary (and in fact, I think it would be overkill for most drupal sites) If the alt field is enabled, people will be encouraged to use it. If the field is required - then an error message will appear to content creators when it is left empty. I think site builders will mostly want to leave the field optional - except when accessibility is a requirement.

I've also been toying with the idea of an accessibility module that would set a bunch of important defaults for you - things like this - it could strongarm into place so that they can't be overlooked by site builders.

mgifford’s picture

@jenlampton - What I'm interested in is how to gently alter people's behaviour. A reminder that they've added an image without an alt tag may be all that's required. I agree that you would want to have an admin setting or additional module that steps this up so that you could actually force users to insert a meaningful alt text (not - "image" or "file123.jpg"), but I think much of the time users just need a gentle reminder. It's really the low hanging fruit of accessibility in many ways, but alt tags are still commonly missing from Drupal 7 sites. How can we change the initial config so that with Drupal 8 content admins find it easier to include this additional information?

I do like the idea of your module for those folks who need to meet higher accessibility guidelines. Could even fold it into an existing module like: http://drupal.org/project/accessible

Let us know how we can help & what elements you're interested in including in this module.

jenlampton’s picture

@mgifford

What I'm interested in is how to gently alter people's behaviour. A reminder that they've added an image without an alt tag may be all that's required.

Yes, that's how a "required" field behaves :) Right now we don't even have the *ability* to make this field required without custom code - that needs to change. But I certainly think it should not be enabled by default.

mgifford’s picture

I see required fields as stopping the process. So you can't finish with the image unless you've added the alt text. It's the big red warning in the form process that means you can't complete the submission.

I would like to see that even without alt tags being a required field that users are gently reminded by a nice reminder message that the quality of their post would be improved if they added alt text to their images. Nothing that stops workflow, but simply provides a yellow reminder that something was missed. Something easy enough to ignore if it's not deemed important.

Something that could be disabled if no reminder was desired.

But yes, the lack of an ability to do this in core is something we need to fix in D8. We got images in which was no small feat, but....

jenlampton’s picture

Hm. A warning is an interesting idea. I'm not *sure* that needs to live in core, but if we'd be adding the option to make a field required, we might as well allow 'alerted' (we'll need to come up with a new name for that state!) as well.

xano’s picture

Title: Accessability: Custom Alt text should provide an option to be required » Accessibility: Custom Alt text should provide an option to be required
mgifford’s picture

Ok, what do we need to see this move forward?

1) Screenshots indicating the best & worse case for alternative text usage with images
2) Feedback from UX folks
3) A patch & agreement around the patch
4) Someone to RTBC it.

Am I missing something?

So can someone summarize the best case senario in a series of pretty screen shots?

quicksketch’s picture

I'd still like to vote for leaving this out of core. Let contrib handle it (in fact it already has):

http://drupal.org/project/accessible (and #887424: Make alt text required on imagefields)
http://drupal.org/project/eim

If your site is going to require 100% compliance with accessibility standards, you MUST train your end-users. Forcing them to enter alt text isn't going to mean that they're going to actually use the Alt field correctly. If you want to force this upon your end-users, you can use a contrib solution.

Everett Zufelt’s picture

Component: image system » image.module

@mgifford

I think the first step is a strong rationale to support the proposed change to Core, that persuades a number of people that this is the right direction to go. I'm personally opposed to making this enabled by default, so it would be best as an Image field setting, defaulted to off.

I also don't rank this very high in my D8 accessibility priority list, so although I will support anyone working on the issue, I will not be working on it myself.

mgifford’s picture

Alt tags are the low hanging fruit of web accessibility. We have done lots of work on improving accessibility of Drupal 7, but because the extra work that's required to incorporate alt tags in Core's image handling it generally isn't done by default. If the best we can agree on is ship core so that you can enable required alt text by default, fine. However, alt text should be listed as an option by default and there should be no additional work

If the "Enable alt field" is checked by default that's a good start http://drupal.org/files/issues/Editing_Image_Field.png

Making a similar option to have it be a required field would be a good addition.

quicksketch’s picture

If the "Enable alt field" is checked by default that's a good start http://drupal.org/files/issues/Editing_Image_Field.png

The Alt field is enabled on new installs of D7 and D8 for the "field_image" field that is added by the default install profile (the title field is not enabled on it).

The Alt field is not enabled by default when adding new image fields.

mgifford’s picture

Thanks for the clarification. Been too long since I set up a default vanilla install.

mgifford’s picture

Status: Active » Postponed

I'm going to mark this postponed until we get a stronger argument for why it needs to be in core.

danny englander’s picture

I am the original person who opened this issue, little did I know this would develop into an interesting conversation that has spanned the last 18 months and three versions of Drupal. That being said, as I have been using Drupal for some time now, one thing my site users and editors always ask for is good SEO. That usually comes up in initial rounds of conversation of what the client wants out of their new web site. What I have discovered is that no matter how much training I have provided to my end users, when it comes down to it, they simply will not input info into a field unless it's required some of the time.

Though this issue has been geared more toward good accessibility, I think SEO is worth mentioning too. (i.e. an image with a title and alt tag probably will look better to a search engine, that's kind of web 101). It looks like the EIM module (mentioned here above) provides for required alt and title text and I am going to test that out.

So in a way, there's two good arguments for core, Accessibility and SEO but for now It looks like EIM will do the job.

mgifford’s picture

Status: Postponed » Active
Issue tags: +SEO, +Drupal SEO, +image SEO optimisation

I've re-opened this issue and added some SEO tags. EIM will work for D7, but would be good if this functionality could be brought into D8.

Thanks @highrockmedia

Everett Zufelt’s picture

I haven't read back through the comments. But, would it be acceptable for the default image field widget to have an toggle to require alt text, that defaults to off? If we can build consensus on this by May 4 I will roll the patch on May 4.

danny englander’s picture

@Everett Zufelt -- You mention alt text in #32 above but I think it would also be nice to have the Title text as a possible required item as well.

leenwebb’s picture

Title: Accessibility: Custom Alt text should provide an option to be required » Imagefields should have the option to require Custom Alt text
Priority: Normal » Minor

While contrib modules are a great solution in the meantime, moving the ability to require alt tags into core will enhance the base product and make it easier for the average administrator to build accessible sites.

(via Montreal Accessibility Sprint)

Bojhan’s picture

Lets do #32.

mgifford’s picture

Who is going to write up a patch that gives us the functionality specified in #32?

lundj’s picture

Would also like to see #32 implemented... Maybe also for D7?

eiriksm’s picture

Status: Active » Needs review
StatusFileSize
new2.56 KB

I have also found myself writing this in a custom module several times, so I would also like to see this in core. Although the contrib module does not have to be advanced to add the functionality, it would be a nice accessibility feature to have in core.

So here is a patch adding the functionality. Obviously extremely simple. I included the option on both the title field and the alt field. I can write up some tests when (and if) we think we are heading the right direction.

Status: Needs review » Needs work

The last submitted patch, drupal-alt-field-required-815144-38.patch, failed testing.

eiriksm’s picture

Status: Needs work » Needs review

Should probably put this back to needs review? Can't imagine that those errors had anything to do with this patch.

mgifford’s picture

Issue tags: -SEO, -Accessibility, -Drupal SEO, -image SEO optimisation

Status: Needs review » Needs work

The last submitted patch, drupal-alt-field-required-815144-38.patch, failed testing.

mgifford’s picture

Status: Needs work » Needs review
mgifford’s picture

Issue tags: +SEO, +Accessibility, +Drupal SEO, +image SEO optimisation
mgifford’s picture

Issue tags: +a11ySprint

Nice to be able to force a standard.

falcon03’s picture

Priority: Minor » Normal
Status: Needs review » Needs work
Issue tags: +Needs tests

IMO this is not a minor feature. so changing status.

I applied the patch and it works nicely, except that when clicking the "upload" button next to an image field it shows the errors to inform that alternate field or title field are required (when they are set to be required). This is a problem, because users cannot enter values for alt or title before clicking the "upload" button!

Also tagging for tests; I hope that we get this in before feature freeze!

mgifford’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests, -SEO, -Accessibility, -Drupal SEO, -image SEO optimisation, -a11ySprint

Status: Needs review » Needs work
Issue tags: +Needs tests, +SEO, +Accessibility, +Drupal SEO, +image SEO optimisation, +a11ySprint

The last submitted patch, drupal-alt-field-required-815144-38.patch, failed testing.

danny englander’s picture

I tried applying the patch but got an error:

error: patch failed: core/modules/image/image.field.inc:419
error: core/modules/image/image.field.inc: patch does not apply

I have the patch in my root drupal 8 directory and type:

git apply drupal-alt-field-required-815144-38.patch

I then grabbed the code from:
http://drupalcode.org/project/drupal.git/blob_plain/efa195acbdc13fb69635...

... and applied the patch and it worked fine.

That being said, now that I have tested it, I am having the same issue as #46 above. The required verification should probably happen on node save as with any other required fields, not at the time of upload. I think this would be a better UX.

danny englander’s picture

Status: Needs review » Needs work

One other issue I just ran into with this is if there are eixsting images for a given field that did not have any alt and or title text and then you decide to impose required alt or title, when you go to remove an existing image that did not have the text, you get an error that the fields are required. I think that might be related to:

Delete button triggers form validation - change to Delete link for entities with URI

eiriksm’s picture

Status: Needs work » Needs review
StatusFileSize
new5.28 KB

Finally got some time to rewrite and clean up this one. Attached patch addresses the following:

1 Now applies cleanly again.
2 Does not complain about required when uploading.
3 Does not complain about deleting fields when alt/title is empty.
4 Has a test to ensure that fields with required alt/title can not be saved.

I had to do a "workaround" to avoid issues 2 and 3, because #required in form api triggers validation in these kinds of processed fields. So instead I added a element_validate function that does not get run if the triggering element has "file_managed_file_submit" as one of the submit callbacks (this applies to both delete and upload buttons).

Does that sound reasonable? Please review, so we can try to get this in (only days to go!).

danny englander’s picture

Status: Needs work » Needs review

I just tested the latest patch in #51 and the only issue now seems to be with:

Does not complain about deleting fields when alt/title is empty

To test this:

  1. Don't require alt and title in the field settings for an image
  2. Upload an image in a node (I am using the default article imagefield) and don't fill in either alt or title
  3. Now go back and set alt and title to be required in manage fields for the given imagefield
  4. Go back to the node where you just uploaded the image and try to remove the image
  5. The image is removed without any error
  6. Save the node and now I get at the top:
    The field Alternate text is required
    The field Title is required
  7. However the image is gone so the only way out of this is to either not save it or fill in some temporary alt or title text, save and then go back in and remove and save.

That's probably an extreme edge case so I am not sure about the relevancy of it but at any rate the main functionality is working.

eiriksm’s picture

StatusFileSize
new5.71 KB

Ah, what a miss. Sorry about that. And it was not an edge case, it applied to all nodes with an empty image field :)

New patch attached. Same functionality, including fixing your edge case.

One case it would seem strange is the following:
- The user has a bunch of nodes and turns on alt field required
- The user tries to edit the title of an old node with no alt on the image.
- The user can not save his changes before he fills in alt field.

Could be confusing for some, but should be expected behaviour IMO.

danny englander’s picture

@eiriksm - yes that's great, just tested again and it's all good this time. Thanks!

mgifford’s picture

Good enough to mark RTBC? If so, please do so.

danny englander’s picture

@mgifford - who would usually set to RTBC the author of the patch or those who have tested like me? Thanks :)

mgifford’s picture

It's almost always the person who tested it like you @highrockmedia

It's very rare that the person who posted the patch is actually allowed to make the patch RTBC. It happens occasionally, particularly if it's already been marked RTBC a few times by others. Sometimes things go back/forth.

danny englander’s picture

Status: Needs review » Reviewed & tested by the community

Ok, then make it so. Thank you to all who helped out with this!

cb’s picture

Nice work on this guys!

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Awesome!

Committed and pushed to 8.x. Thanks!

Status: Fixed » Closed (fixed)
Issue tags: -Needs tests, -SEO, -Accessibility, -Drupal SEO, -image SEO optimisation, -a11ySprint

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

anybody’s picture

Issue summary: View changes

Thanks a lot for your work here.

A simple question: What do you think about a separate permission to allow / disallow to enter values into the ALT / TITLE text fields for roles?

New issue?

mgifford’s picture

Yup, this would be a new issue. Make sure to link to this one though as a related issue.