diff options
Diffstat (limited to 'modules/image')
-rw-r--r-- | modules/image/image.field.inc | 7 | ||||
-rw-r--r-- | modules/image/image.test | 17 |
2 files changed, 23 insertions, 1 deletions
diff --git a/modules/image/image.field.inc b/modules/image/image.field.inc index 3692ee2e8..e56e0cf49 100644 --- a/modules/image/image.field.inc +++ b/modules/image/image.field.inc @@ -568,7 +568,8 @@ function image_field_formatter_view($entity_type, $entity, $field, $instance, $l * * @param $variables * An associative array containing: - * - item: An array of image data. + * - item: Associative array of image data, which may include "uri", "alt", + * "width", "height", "title" and "attributes". * - image_style: An optional image style. * - path: An array containing the link 'path' and link 'options'. * @@ -581,6 +582,10 @@ function theme_image_formatter($variables) { 'alt' => $item['alt'], ); + if (isset($item['attributes'])) { + $image['attributes'] = $item['attributes']; + } + if (isset($item['width']) && isset($item['height'])) { $image['width'] = $item['width']; $image['height'] = $item['height']; diff --git a/modules/image/image.test b/modules/image/image.test index 3b7f3e7d7..8ec77587b 100644 --- a/modules/image/image.test +++ b/modules/image/image.test @@ -808,6 +808,23 @@ class ImageFieldDisplayTestCase extends ImageFieldTestCase { } /** + * Test passing attributes into the image field formatters. + */ + function testImageFieldFormatterAttributes() { + $image = theme('image_formatter', array( + 'item' => array( + 'uri' => 'http://example.com/example.png', + 'attributes' => array( + 'data-image-field-formatter' => 'testFound', + ), + 'alt' => t('Image field formatter attribute test.'), + 'title' => t('Image field formatter'), + ), + )); + $this->assertTrue(stripos($image, 'testFound') > 0, t('Image field formatters can have attributes.')); + } + + /** * Test use of a default image with an image field. */ function testImageFieldDefaultImage() { |