summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorParis Liakos2012-12-26 17:51:38 (GMT)
committer Paris Liakos2012-12-26 17:51:38 (GMT)
commitd3a749470aa4c3b61af7e3e4d720276049e3ef20 (patch)
treec0e134ac8beb9113b0e6edae44fe6d41a8dc2fe1
parentfbd2569d4faf084ea5b44667f7b491d66714c04f (diff)
Issue #1307054 by idflood, Daniel Korte, mfer, redndahead, mgifford, jpstrikesback: Media browser missing image alt and title fields
-rw-r--r--includes/media.filter.inc24
-rw-r--r--js/wysiwyg-media.js3
2 files changed, 26 insertions, 1 deletions
diff --git a/includes/media.filter.inc b/includes/media.filter.inc
index 4e9d64c..aacd189 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 003ed88..66ef30b 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),