diff --git a/core/includes/theme.inc b/core/includes/theme.inc
index c276c57..abfc9ac 100644
--- a/core/includes/theme.inc
+++ b/core/includes/theme.inc
@@ -978,7 +978,7 @@ function theme($hook, $variables = array()) {
$variables = array();
if (isset($info['variables'])) {
foreach (array_keys($info['variables']) as $name) {
- if (isset($element["#$name"])) {
+ if (array_key_exists("#$name", $element)) {
$variables[$name] = $element["#$name"];
}
}
diff --git a/core/modules/image/image.field.inc b/core/modules/image/image.field.inc
index 1f0e87b..cc7cc99 100644
--- a/core/modules/image/image.field.inc
+++ b/core/modules/image/image.field.inc
@@ -441,7 +441,7 @@ function theme_image_formatter($variables) {
}
foreach (array('width', 'height', 'alt', 'attributes') as $key) {
- if (isset($item[$key])) {
+ if (array_key_exists($key, $item)) {
$image["#$key"] = $item[$key];
}
}
diff --git a/core/modules/image/image.module b/core/modules/image/image.module
index c1918eb..9e12ab1 100644
--- a/core/modules/image/image.module
+++ b/core/modules/image/image.module
@@ -150,6 +150,18 @@ function image_theme() {
return array(
// Theme functions in image.module.
'image_style' => array(
+ // HTML 4 and XHTML 1.0 always require an alt attribute. The HTML 5 draft
+ // allows the alt attribute to be omitted in some cases. Therefore,
+ // default the alt attribute to an empty string, but allow code calling
+ // theme('image_style') to pass explicit NULL for it to be omitted.
+ // Usually, neither omission nor an empty string satisfies accessibility
+ // requirements, so it is strongly encouraged for code calling
+ // theme('image_style') to pass a meaningful value for the alt variable.
+ // - http://www.w3.org/TR/REC-html40/struct/objects.html#h-13.8
+ // - http://www.w3.org/TR/xhtml1/dtds.html
+ // - http://dev.w3.org/html5/spec/Overview.html#alt
+ // The title attribute is optional in all cases, so it is omitted by
+ // default.
'variables' => array(
'style_name' => NULL,
'uri' => NULL,
@@ -362,7 +374,16 @@ function image_style_options($include_empty = TRUE) {
* 'public://images/image.jpg'.
* - width: The width of the source image (if known).
* - height: The height of the source image (if known).
- * - alt: The alternative text for text-based browsers.
+ * - alt: The alternative text for text-based browsers. HTML 4 and XHTML 1.0
+ * always require an alt attribute. The HTML 5 draft allows the alt
+ * attribute to be omitted in some cases. Therefore, this variable defaults
+ * to an empty string, but can be set to NULL for the attribute to be
+ * omitted. Usually, neither omission nor an empty string satisfies
+ * accessibility requirements, so it is strongly encouraged for code calling
+ * theme('image_style') to pass a meaningful value for this variable.
+ * - http://www.w3.org/TR/REC-html40/struct/objects.html#h-13.8
+ * - http://www.w3.org/TR/xhtml1/dtds.html
+ * - http://dev.w3.org/html5/spec/Overview.html#alt
* - title: The title text is displayed when the image is hovered in some
* popular browsers.
* - attributes: Associative array of attributes to be placed in the img tag.
@@ -393,10 +414,10 @@ function theme_image_style($variables) {
'#uri' => $style->buildUrl($variables['uri']),
);
- if (isset($variables['alt'])) {
+ if (array_key_exists('alt', $variables)) {
$image['#alt'] = $variables['alt'];
}
- if (isset($variables['title'])) {
+ if (array_key_exists('title', $variables)) {
$image['#title'] = $variables['title'];
}
diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageThemeFunctionTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageThemeFunctionTest.php
index f0d540f..1f00c21 100644
--- a/core/modules/image/lib/Drupal/image/Tests/ImageThemeFunctionTest.php
+++ b/core/modules/image/lib/Drupal/image/Tests/ImageThemeFunctionTest.php
@@ -43,20 +43,27 @@ function testImageFormatterTheme() {
$style->save();
$url = $style->buildUrl($original_uri);
- // Test using theme_image_formatter() without an image title, alt text, or
- // link options.
+ // Test using theme_image_formatter() with a NULL value for the alt option.
$path = $this->randomName();
$element = array(
'#theme' => 'image_formatter',
'#image_style' => 'test',
'#item' => array(
'uri' => $original_uri,
+ 'alt' => NULL,
),
'#path' => array(
'path' => $path,
),
);
$rendered_element = render($element);
+ $expected_result = '';
+ $this->assertEqual($expected_result, $rendered_element, 'theme_image_formatter() correctly renders with a NULL value for the alt option.');
+
+ // Test using theme_image_formatter() without an image title, alt text, or
+ // link options.
+ unset($element['#item']['alt']);
+ $rendered_element = render($element);
$expected_result = '';
$this->assertEqual($expected_result, $rendered_element, 'theme_image_formatter() correctly renders without title, alt, or path options.');
@@ -95,6 +102,12 @@ function testImageStyleTheme() {
$rendered_element = render($element);
$expected_result = '';
$this->assertEqual($expected_result, $rendered_element, 'theme_image_style() renders an image correctly.');
+
+ // Test using theme_image_style() with a NULL value for the alt option.
+ $element['#alt'] = NULL;
+ $rendered_element = render($element);
+ $expected_result = '';
+ $this->assertEqual($expected_result, $rendered_element, 'theme_image_style() renders an image correctly with a NULL value for the alt option.');
}
}