[BUGFIX] Always add the "alt" attribute for images
authordkd-egerer Sascha Egerer <sascha.egerer@dkd.de>
Fri, 13 Apr 2012 14:32:17 +0000 (16:32 +0200)
committerAlexander Schnitzler <typo3@alexanderschnitzler.de>
Mon, 5 Nov 2012 10:36:25 +0000 (11:36 +0100)
The ImageViewHelper does not add the alt-attribute to the
image tag if it is not set. This patch renders always the
alt attribute to the img-tag even if it is empty.

Change-Id: I2d69e9cdba428771659f4afc8814ec8eb02d6090
Fixes: #9151
Releases: 6.0, 4.7, 1.3
Reviewed-on: http://review.typo3.org/10426
Reviewed-by: Tilo Baller
Tested-by: Tilo Baller
Reviewed-by: Mattias Nilsson
Tested-by: Mattias Nilsson
Reviewed-by: Ingo Pfennigstorf
Tested-by: Ingo Pfennigstorf
Reviewed-by: Alexander Schnitzler
Tested-by: Alexander Schnitzler
typo3/sysext/fluid/Classes/ViewHelpers/ImageViewHelper.php

index ae2e302..15b65d1 100644 (file)
@@ -135,7 +135,11 @@ class ImageViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedV
                $this->tag->addAttribute('src', $imageSource);
                $this->tag->addAttribute('width', $imageInfo[0]);
                $this->tag->addAttribute('height', $imageInfo[1]);
-               if ($this->arguments['title'] === '') {
+               //the alt-attribute is mandatory to have valid html-code, therefore add it even if it is empty
+               if (empty($this->arguments['alt'])) {
+                       $this->tag->addAttribute('alt', '');
+               }
+               if (empty($this->arguments['title']) && !empty($this->arguments['alt'])) {
                        $this->tag->addAttribute('title', $this->arguments['alt']);
                }
                return $this->tag->render();
@@ -176,5 +180,4 @@ class ImageViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedV
 
 }
 
-
 ?>
\ No newline at end of file