Browse Source

fix the carousel occasional bug

Olivier Massot 5 years ago
parent
commit
1111a4e206

+ 56 - 0
ot_templating/Classes/ViewHelpers/ImagePViewHelper.php

@@ -0,0 +1,56 @@
+<?php
+
+namespace Opentalent\OtTemplating\ViewHelpers;
+
+
+use Closure;
+use Opentalent\OtTemplating\Page\OtPageRepository;
+use Opentalent\OtTemplating\ViewHelpers\RootPage\GetIdViewHelper;
+use TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Fluid\ViewHelpers\ImageViewHelper;
+use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
+
+/**
+ * -- Wrapper for the TYPO3\CMS\Fluid\ViewHelpers\ImageViewHelper --
+ * Display the image like the original viewhelper does, but does not
+ * throw an error if the file is not an image or if the
+ * image can not be displayed.
+ *
+ *     {namespace ot=Opentalent\OtTemplating\ViewHelpers}
+ *
+ *     {ot:imageP()}
+ *
+ * @package Opentalent\OtTemplating\ViewHelpers
+ */
+class ImagePViewHelper extends ImageViewHelper
+{
+
+    /**
+     * -- This method is expected by Fluid --
+     * Declares the viewhelper's parameters
+     */
+    public function initializeArguments()
+    {
+        parent::initializeArguments();
+    }
+
+    /**
+     * -- This method is expected by Fluid --
+     * Renders the content as html
+     *
+     * @return string Rendered tag
+     */
+    public function render() {
+        try {
+            return parent::render();
+        } catch (ResourceDoesNotExistException |
+                \UnexpectedValueException |
+                \RuntimeException |
+                \InvalidArgumentException
+                $e) {
+            return "";
+        }
+    }
+
+}

+ 2 - 1
ot_templating/Resources/Private/Partials/Classic/Carousel.html

@@ -1,4 +1,5 @@
 {namespace v=FluidTYPO3\Vhs\ViewHelpers}
+{namespace ot=Opentalent\OtTemplating\ViewHelpers}
 
 <f:comment><!--
     -- Resources.fal ViewHelper --
@@ -17,7 +18,7 @@
         <f:for each="{images}" as="image">
             <f:if condition="{v:variable.pregMatch(pattern: '/.*(?:jpe?g|gif|png)$/', subject: image.url)}">
                 <div>
-                    <f:image src="{image.url}"
+                    <ot:imageP src="{image.url}"
                              alt="{image.alternative}"
                              title="{image.title}"
                              class="carousel-img"

+ 1 - 1
ot_templating/Resources/Private/Partials/Modern/Carousel.html

@@ -60,7 +60,7 @@
                                 data-param10=""
                                 data-description="">
 
-                                <f:image src="{image.url}"
+                                <ot:imageP src="{image.url}"
                                      alt="{image.alternative}"
                                      class="rev-slidebg"
                                      height="500c"