Commit d4fba77f authored by alexpott's avatar alexpott

Issue #2010126 follow-up by Eric_A: Replace theme() with drupal_render() in...

Issue #2010126 follow-up by Eric_A: Replace theme() with drupal_render() in image module for theme_image_formatter().
parent 4e0d7b51
......@@ -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 (isset($element["#$name"]) || array_key_exists("#$name", $element)) {
$variables[$name] = $element["#$name"];
}
}
......
......@@ -441,7 +441,7 @@ function theme_image_formatter($variables) {
}
foreach (array('width', 'height', 'alt', 'attributes') as $key) {
if (isset($item[$key])) {
if (isset($item[$key]) || array_key_exists($key, $item)) {
$image["#$key"] = $item[$key];
}
}
......
......@@ -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 (isset($variables['alt']) || array_key_exists('alt', $variables)) {
$image['#alt'] = $variables['alt'];
}
if (isset($variables['title'])) {
if (isset($variables['title']) || array_key_exists('title', $variables)) {
$image['#title'] = $variables['title'];
}
......
......@@ -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 = '<a href="' . base_path() . $path . '"><img class="image-style-test" src="' . $url . '" /></a>';
$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 = '<a href="' . base_path() . $path . '"><img class="image-style-test" src="' . $url . '" alt="" /></a>';
$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 = '<img class="image-style-image-test" src="' . $url . '" alt="" />';
$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 = '<img class="image-style-image-test" src="' . $url . '" />';
$this->assertEqual($expected_result, $rendered_element, 'theme_image_style() renders an image correctly with a NULL value for the alt option.');
}
}
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