[BUGFIX] Don't use FAL based ImageViewHelper in extension manager 19/42119/6
authorFrans Saris <franssaris@gmail.com>
Wed, 29 Jul 2015 20:13:07 +0000 (22:13 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Thu, 30 Jul 2015 10:49:55 +0000 (12:49 +0200)
Resolves: #68636
Releases: master, 6.2
Change-Id: I15c48447d0226518f0bdf8459295a82e49864306
Reviewed-on: http://review.typo3.org/42119
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/extensionmanager/Classes/ViewHelpers/ImageViewHelper.php
typo3/sysext/extensionmanager/Resources/Private/Partials/List/Distribution.html
typo3/sysext/extensionmanager/Resources/Private/Templates/Distribution/Show.html

index de82775..edd2e22 100644 (file)
@@ -13,68 +13,95 @@ namespace TYPO3\CMS\Extensionmanager\ViewHelpers;
  *
  * The TYPO3 project - inspiring people to share!
  */
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 
 /**
- * Resizes a given image (if required) and renders the respective img tag
- * In general just calls the parent image view helper but catches
- * the "file does not exist" exception thrown by the file abstraction layer
+ * Render an img tag for given image src. If $src doesn't exist and
+ * $fallbackImage is given check if that file exists and render img tag.
+ *
+ * If no existing file is found no tag is rendered.
  *
  * = Examples =
  *
  * <code title="Default">
- * <f:image src="EXT:myext/Resources/Public/typo3_logo.png" alt="alt text" />
+ *     <em:image src="EXT:myext/Resources/Public/typo3_logo.png" alt="alt text" />
  * </code>
  * <output>
- * <img alt="alt text" src="typo3conf/ext/myext/Resources/Public/typo3_logo.png" width="396" height="375" />
- * or (in BE mode):
- * <img alt="alt text" src="../typo3conf/ext/viewhelpertest/Resources/Public/typo3_logo.png" width="396" height="375" />
- * </output>
- *
- * <code title="Inline notation">
- * {f:image(src: 'EXT:viewhelpertest/Resources/Public/typo3_logo.png', alt: 'alt text', minWidth: 30, maxWidth: 40)}
- * </code>
- * <output>
- * <img alt="alt text" src="../typo3temp/pics/f13d79a526.png" width="40" height="38" />
- * (depending on your TYPO3s encryption key)
+ *     <img alt="alt text" src="../typo3conf/ext/myext/Resources/Public/typo3_logo.png" />
  * </output>
  *
  * <code title="non existing image">
- * <f:image src="NonExistingImage.png" alt="foo" />
+ *     <f:image src="NonExistingImage.png" alt="foo" />
  * </code>
  * <output>
- * Could not get image resource for "NonExistingImage.png".
  * </output>
  *
  * @internal
  */
-class ImageViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\ImageViewHelper {
+class ImageViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper {
+
+       /**
+        * @var string
+        */
+       protected $tagName = 'img';
+
+       /**
+        * Initialize arguments.
+        *
+        * @return void
+        */
+       public function initializeArguments() {
+               parent::initializeArguments();
+               $this->registerUniversalTagAttributes();
+               $this->registerTagAttribute('alt', 'string', 'Specifies an alternate text for an image', FALSE);
+       }
 
        /**
         * Resizes a given image (if required) and renders the respective img tag
         *
         * @param string $src
-        * @param string $width width of the image. This can be a numeric value representing the fixed width of the image in pixels. But you can also perform simple calculations by adding "m" or "c" to the value. See imgResource.width for possible options.
-        * @param string $height height of the image. This can be a numeric value representing the fixed height of the image in pixels. But you can also perform simple calculations by adding "m" or "c" to the value. See imgResource.width for possible options.
-        * @param int $minWidth minimum width of the image
-        * @param int $minHeight minimum height of the image
-        * @param int $maxWidth maximum width of the image
-        * @param int $maxHeight maximum height of the image
+        * @param int $width width of the image
+        * @param int $height height of the image
         * @param string $fallbackImage an optional fallback image if the $src image cannot be loaded
         * @return string rendered tag.
         */
-       public function render($src, $width = NULL, $height = NULL, $minWidth = NULL, $minHeight = NULL, $maxWidth = NULL, $maxHeight = NULL, $fallbackImage = '') {
-               $image = '';
-               try {
-                       $image = parent::render($src, $width, $height, $minWidth, $minHeight, $maxWidth, $maxHeight);
-               } catch (\Exception $e) {
-                       if ($fallbackImage !== '') {
-                               $image = static::render($fallbackImage, $width, $height, $minWidth, $minHeight, $maxWidth, $maxHeight);
+       public function render($src, $width = NULL, $height = NULL, $fallbackImage = '') {
+               $content = '';
+               $uri = $this->getImageUri($src);
+
+               if (empty($uri) && $fallbackImage !== '') {
+                       $uri = $this->getImageUri($fallbackImage);
+               }
+
+               if (!empty($uri)) {
+                       if ($width) {
+                               $this->tag->addAttribute('width', (int)$width);
                        }
-                       /** @var \TYPO3\CMS\Core\Log\Logger $logger */
-                       $logger = $this->objectManager->get(\TYPO3\CMS\Core\Log\LogManager::class)->getLogger(__CLASS__);
-                       $logger->log(\TYPO3\CMS\Core\Log\LogLevel::WARNING, $e->getMessage());
+                       if ($height) {
+                               $this->tag->addAttribute('height', (int)$height);
+                       }
+                       $this->tag->addAttribute('src', $uri);
+                       $content = $this->tag->render();
                }
-               return $image;
+
+               return $content;
        }
 
+       /**
+        * Get image uri
+        *
+        * @param string $src
+        * @return string
+        */
+       protected function getImageUri($src) {
+               $uri = GeneralUtility::getFileAbsFileName($src);
+               if ($uri !== '' && !file_exists($uri)) {
+                       $uri = '';
+               }
+               if ($uri !== '') {
+                       $uri = '../' . PathUtility::stripPathSitePrefix($uri);
+               }
+               return $uri;
+       }
 }
index 32db7cf..70db92a 100644 (file)
@@ -9,8 +9,8 @@
                <em:image
                                src="EXT:{distribution.extensionKey}/Resources/Public/Images/Distribution.png" alt="{distribution.title}"
                                fallbackImage="EXT:extensionmanager/Resources/Public/Images/Distribution.png"
-                               height="225px"
-                               width="300px"
+                               height="225"
+                               width="300"
                        />
                <div class="distribution-hover">
                        <div class="distribution-hover-inner">
index d393f7f..536d0a1 100644 (file)
        <div class="distribution-detail">
                <div class="distribution-detail-previewpane">
                        <em:image
-                               src="EXT:{extension.extensionKey}/Resources/Public/Images/DistributionWelcome.png" alt="{distribution.title}"
+                               src="EXT:{extension.extensionKey}/Resources/Public/Images/DistributionWelcome.png"
+                               fallbackImage="EXT:extensionmanager/Resources/Public/Images/Distribution.png"
+                               alt="{distribution.title}"
                                class="distribution-detail-preview"
-                               />
+                               width="300"
+                       />
                </div>
                <div class="distribution-detail-body">
                        <div class="distribution-detail-header">