Commit d3a74947 authored by Paris Liakos's avatar Paris Liakos

Issue #1307054 by idflood, Daniel Korte, mfer, redndahead, mgifford,...

Issue #1307054 by idflood, Daniel Korte, mfer, redndahead, mgifford, jpstrikesback: Media browser missing image alt and title fields
parent fbd2569d
......@@ -180,6 +180,14 @@ function media_token_to_markup($match, $wysiwyg = FALSE) {
// Display the field elements.
$element = array();
$element['content']['file'] = media_get_file_without_label($file, $tag_info['view_mode'], $settings);
// Overwrite or set the file #alt attribute if it has been set in this instance.
if (!empty($element['content']['file']['#attributes']['alt'])) {
$element['content']['file']['#alt'] = $element['content']['file']['#attributes']['alt'];
}
// Overwrite or set the file #title attribute if it has been set in this instance.
if (!empty($element['content']['file']['#attributes']['title'])) {
$element['content']['file']['#title'] = $element['content']['file']['#attributes']['title'];
}
field_attach_prepare_view('file', array($file->fid => $file), $tag_info['view_mode']);
entity_prepare_view('file', array($file->fid => $file));
$element['content'] += field_attach_view('file', $file, $tag_info['view_mode']);
......@@ -380,6 +388,22 @@ function media_format_form($form, $form_state, $file) {
'#default_value' => $default_view_mode
);
if ($file->type === 'image') {
$form['options']['alt'] = array(
'#type' => 'textfield',
'#title' => t('Alternate text'),
'#description' => t('This text will be used by screen readers, search engines, or when the image cannot be loaded.'),
'#default_value' => isset($file->field_file_image_alt_text['und'][0]['safe_value']) ? $file->field_file_image_alt_text['und'][0]['safe_value'] : '',
);
$form['options']['title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#description' => t('The title is used as a tool tip when the user hovers the mouse over the image.'),
'#default_value' => isset($file->field_file_image_title_text['und'][0]['safe_value']) ? $file->field_file_image_title_text['und'][0]['safe_value'] : '',
);
}
// Similar to a form_alter, but we want this to run first so that media.types.inc
// can add the fields specific to a given type (like alt tags on media).
// If implemented as an alter, this might not happen, making other alters not
......
......@@ -171,7 +171,8 @@ InsertMedia.prototype = {
insert: function (formatted_media) {
var element = create_element(formatted_media.html, {
fid: this.mediaFile.fid,
view_mode: formatted_media.type
view_mode: formatted_media.type,
attributes: formatted_media.options
});
var markup = outerHTML(element),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment