Hi,

Been playing around a bit with the media module and am so far very impressed about how it works. While I do understand that it is still in very early state and an alpha is still some time away, I would like to ask a few support related questions about thing I haven't managed to find out myself.

How do I get alt and title attributes populated for media files, especially images?

When I upload a new media file, there is a Description field, but I haven't found out what it is used for, nor does it seem to be saved in the database. Is that just an empty form field in the upload UI or does it actually fill a purpose?

CommentFileSizeAuthor
#10 945354_wysiwyg_alt.patch412 byteszoo33
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lifepillar’s picture

This is coming a bit late, but maybe it still helps. I do it by manually editing the generated tag. For example, after an image has been inserted using the Media browser, you may switch to source view (by clicking “Disable rich-text” at the bottom of the body field). There, you will see that the generated tag contains something similar to the following:

attributes":{"class":"media-image","typeof":"foaf:Image","wysiwyg":"1"}

You may add other attributes, such as alt, title or style, e.g.,

attributes":{"class":"media-image","typeof":"foaf:Image","wysiwyg":"1","alt":"my image","title":"a title","style":"vertical-align:middle;float:right;"}

Currently, I do not think that it is possible to achieve the same through the interface, but I am confident (!) that such a feature is planned, since under the hood it works. By the way, I have no idea why the module does not generate (x)html code (media tags may be recognised by a class attribute). That would be more portable (in case you disable the module or want to export your web site).

tsvenson’s picture

Been using that "hack" way as well. Unfortunately, as reported in #1018606: Attribute for embedded images not in output, some attributes, such as the default class is not making it to the output in the latest dev version.

bryancasler’s picture

subscribe

tomgf’s picture

subscribe

tomgf’s picture

I am working on a patch to provide access and visibility to the custom fields added to the different media types, with the main goal of having ALT, Title and captions for images. I would be glad to hear comments.

See it here: #1106444: Showing custom fields – i.e. captions

cartagena’s picture

Thanks, druido--but I don't have a "disable rich-text" option at the bottom of the body field. Can you tell me how to get it? Also, by Media browser do you mean media module? thanks

lifepillar’s picture

@cartagena: the “disable rich-text” appears automatically when you are using a wysiwyg editor: maybe you are editing in plain text?
And yes, by “Media browser” I mean the file browser provided by the Media module.

cartagena’s picture

Thanks for the answer, druido...you are correct, I am not using wysisyg editor, sticking with css. Thanks again for all your work!

zoo33’s picture

Status: Active » Needs review
FileSize
412 bytes

If you just want to use the description field as alt attribute in wysiwyg-inserted images, you can use the really tiny attached patch. No guarantees that this won't screw up something else, but it worked for me.

For Media developers: I'm having a hard time trying to understand the k === "attr" thing, seems like a mistake? Isn't k supposed to be the name of the attribute? Not sure if my patch is how it was meant to work though.

tsvenson’s picture

zoo33: There already exists such field as std in Core. Just go to the image field settings, scroll down and you find check boxes for both Alt and Title that let you add custom text for them for individual images. The Media module then uses that when you embed the objects.

I don't see it as a good thing to add your patch as it will add confusion about this.

bryancasler’s picture

tsvenson, can we get some screenshots or step by step instructions on how to do this. I haven't been able to figure it out.

tsvenson’s picture

@animelion: Just go to the content type and edit the image field. Then scroll down and tick the check boxes for Alt and Title.

Its some time since I tested it with the media module, but back then you couldn't add those strings if you uploaded new images using the CKeditor button. You had to add the Media Asset field to the content type and upload the files using the same method as the std image field.

I will play around with the Media module shortly to update myself on it, will get back with more info here unless you get it working.

yareckon’s picture

when the field is a media asset field rather than an image field (which I believe is not the norm with the media module), the normal image options appear not to be present.

tlangston’s picture

subscribing

David D’s picture

subscribe

mlncn’s picture

re #13, for a Multimedia asset field using the Media file selector widget, there is not alt or title checkboxes.

mlncn’s picture

I gave up on Media including this necessary property by default and added an ALT textarea field to images using the Field UI, at admin/config/media/file-types/manage/image/fields

arthurf’s picture

Status: Needs review » Closed (works as designed)

In 1.x the media browser widget does not support alt/title on image fields. The preferred solution is fields on files which are editable once the file has been added via the browser. 2.x may offer a better UI to this.

tsvenson’s picture

@arthurf: The Alt/Title I know of, but what about the Description field when embedding an image. When looking at the code for it, it seems it is supposed to fill in the Alt attribute, but in reality it is never used.

Either the field needs to be removed, to avoid confusion, or made to work with a better description about what it does.

Probably better to move that discussion to #1251468: Hide Confusing Field 'Description' When Embedding Media though.

jonathanmd’s picture

subscribing

David D’s picture

No need to create a post to subscribe anymore, @jonathanmd. Use the Follow button at the top of the issue page.

DigitalFix’s picture

@arthurf:

I would suggest that the 1.x design is wrong in not supporting the alt attribute for images as it is required by the XHTML specification (see the XHTML Transitional img definition here). Because of that I would recommend that you reopen this issue.

I'd also like to draw your attention to this comment by BarisW who changed the status to critical on a similar issue with the Media module. His reasoning was that it

...rules out using Media on all governmental websites as alt tags are mandatory.

Unfortunately, I do not feel I am in a position to alter the priority or status of this issue as I am not a contributor to this Module, nor have I lurked enough here. Perhaps somebody else will be so bold?

arthurf’s picture

@DigitalFix this is not going to be done for the 1.x branch. 2.x does offer a solution for it.

jonathanmd’s picture

Thanks David D.

I wrote up a way to add the alt and title tags to images through the media module. Not sure if its the best way but it works. Just thought it might be useful to people following this thread.

http://drupal.org/node/1343022

tsvenson’s picture

@DigitalFix: As @arthurf pointed out, no new features will be added to the 1.x branch. If your using for example the CKEditor and embedding images, then you can use its feature to add/edit both the alt and title attributes. Just doubleclick on the image after embedding it.

If your working on a new site, I recommend that you try out the 2.x branch instead as it is the active branch and where all new features are added. It is very likely it will work for you and it will also prevent any issues you otherwise might have to face when upgrading from 1.x to 2.x.