diff --git a/file_entity.module b/file_entity.module
index 8989699..4643076 100644
--- a/file_entity.module
+++ b/file_entity.module
@@ -562,7 +562,11 @@ function file_entity_file_formatter_info() {
if (module_exists('image')) {
$formatters['file_image'] = array(
'label' => t('Image'),
- 'default settings' => array('image_style' => ''),
+ 'default settings' => array(
+ 'image_style' => '',
+ 'alt' => ,
+ 'title' => ,
+ ),
'view callback' => 'file_entity_file_formatter_file_image_view',
'settings callback' => 'file_entity_file_formatter_file_image_settings',
);
@@ -666,6 +670,9 @@ function file_entity_file_formatter_file_image_view($file, $display, $langcode)
}
if (file_entity_file_is_local($file) && isset($file->image_dimensions)) {
+ $replace_options = array(
+ 'clear' => 1,
+ );
if (!empty($display['settings']['image_style'])) {
$element = array(
'#theme' => 'image_style',
@@ -673,6 +680,8 @@ function file_entity_file_formatter_file_image_view($file, $display, $langcode)
'#path' => $file->uri,
'#width' => $file->image_dimensions['width'],
'#height' => $file->image_dimensions['height'],
+ '#alt' => token_replace($display['settings']['alt'], array('file' => $file), $replace_options),
+ '#title' => token_replace($display['settings']['title'], array('file' => $file), $replace_options),
);
}
else {
@@ -681,6 +690,8 @@ function file_entity_file_formatter_file_image_view($file, $display, $langcode)
'#path' => $file->uri,
'#width' => $file->image_dimensions['width'],
'#height' => $file->image_dimensions['height'],
+ '#alt' => token_replace($display['settings']['alt'], array('file' => $file), $replace_options),
+ '#title' => token_replace($display['settings']['title'], array('file' => $file), $replace_options),
);
}
return $element;
@@ -701,6 +712,32 @@ function file_entity_file_formatter_file_image_settings($form, &$form_state, $se
'#default_value' => $settings['image_style'],
'#empty_option' => t('None (original image)'),
);
+
+ // For image files we allow the alt attribute (required in HTML).
+ $element['alt'] = array(
+ '#title' => t('Alt attribute'),
+ '#description' => t('The text to use as value for the img tag alt attribute.'),
+ '#type' => 'textfield',
+ '#default_value' => $settings['alt'],
+ );
+
+ // Allow the setting of the title attribute.
+ $element['title'] = array(
+ '#title' => t('Title attribute'),
+ '#description' => t('The text to use as value for the img tag title attribute.'),
+ '#type' => 'textfield',
+ '#default_value' => $settings['title'],
+ );
+
+ if (module_exists('token')) {
+ $element['alt']['#description'] .= t('This field supports tokens.');
+ $element['title']['#description'] .= t('This field supports tokens.');
+ $element['tokens'] = array(
+ '#theme' => 'token_tree',
+ '#token_types' => array('file'),
+ '#dialog' => TRUE,
+ );
+ }
return $element;
}