diff --git a/includes/media.filter.inc b/includes/media.filter.inc index 4e9d64c91df58ee1ed96b0763b5bfccf710dc777..aacd189a9400a063b1944b57c8e9fed16cc5e0df 100644 --- a/includes/media.filter.inc +++ b/includes/media.filter.inc @@ -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 diff --git a/js/wysiwyg-media.js b/js/wysiwyg-media.js index 003ed88c096e8d7f500914e681eceedae6f6974c..66ef30b8d395b37251e06db4e56cf6b57e8033ba 100644 --- a/js/wysiwyg-media.js +++ b/js/wysiwyg-media.js @@ -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),