[FEATURE] SVG content object support EXT: syntax 11/53711/2
authorFrank Naegler <frank.naegler@typo3.org>
Wed, 16 Aug 2017 09:15:16 +0000 (11:15 +0200)
committerAndreas Fernandez <typo3@scripting-base.de>
Wed, 16 Aug 2017 09:59:01 +0000 (11:59 +0200)
The SVG Content Object property „src“ now supports EXT:
syntax to reference files from extensions.

Resolves: #82108
Releases: master
Change-Id: Iadc3d94973a0254b1785c8068ea2e104eff8bfe3
Reviewed-on: https://review.typo3.org/53711
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Joerg Boesche <typo3@joergboesche.de>
Tested-by: Joerg Boesche <typo3@joergboesche.de>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
typo3/sysext/core/Documentation/Changelog/master/Feature-82108-SupportEXTSyntaxAsSourceInSVGContentObject.rst [new file with mode: 0644]
typo3/sysext/frontend/Classes/ContentObject/ScalableVectorGraphicsContentObject.php

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-82108-SupportEXTSyntaxAsSourceInSVGContentObject.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-82108-SupportEXTSyntaxAsSourceInSVGContentObject.rst
new file mode 100644 (file)
index 0000000..92f91d3
--- /dev/null
@@ -0,0 +1,26 @@
+.. include:: ../../Includes.txt
+
+=====================================================================
+Feature: #82108 - Support EXT: syntax as source in SVG content object
+=====================================================================
+
+See :issue:`82108`
+
+Description
+===========
+
+The SVG Content Object property :typoscript:``src`` now supports EXT: syntax to reference files from extensions.
+
+.. code-block:: typoscript
+
+   page.10 = SVG
+   page.10 {
+      src = EXT:my_extesion/Resources/Public/Icons/foo.svg
+   }
+
+Impact
+======
+
+A SVG file can now be references by EXT: syntax.
+
+.. index:: Frontend, TypoScript
index 720eb6d..28dde77 100644 (file)
@@ -14,6 +14,9 @@ namespace TYPO3\CMS\Frontend\ContentObject;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
+
 /**
  * Contains RESTORE_REGISTER class object.
  */
@@ -45,7 +48,7 @@ class ScalableVectorGraphicsContentObject extends AbstractContentObject
      */
     protected function renderInline(array $conf) : string
     {
-        $src = isset($conf['src.']) ? $this->cObj->stdWrap($conf['src'], $conf['src.']) : $conf['src'];
+        $src = $this->resolveAbsoluteSourcePath($conf);
 
         if (!file_exists($src)) {
             return '';
@@ -79,10 +82,8 @@ class ScalableVectorGraphicsContentObject extends AbstractContentObject
         if (!$height) {
             $height = 400;
         }
-        $src = isset($conf['src.']) ? $this->cObj->stdWrap($conf['src'], $conf['src.']) : $conf['src'];
-        if (!$src) {
-            $src = null;
-        }
+        $src = $this->resolveAbsoluteSourcePath($conf);
+        $src = $src === '' ? null : PathUtility::getAbsoluteWebPath($src);
 
         $value = isset($conf['value.']) ? $this->cObj->stdWrap($conf['value'], $conf['value.']) : $conf['value'];
         $noscript = isset($conf['noscript.']) ? $this->cObj->stdWrap($conf['noscript'], $conf['noscript.']) : $conf['noscript'];
@@ -113,4 +114,15 @@ class ScalableVectorGraphicsContentObject extends AbstractContentObject
         }
         return $content;
     }
+
+    /**
+     * @param array $conf
+     *
+     * @return string
+     */
+    protected function resolveAbsoluteSourcePath(array $conf) : string
+    {
+        $src = isset($conf['src.']) ? $this->cObj->stdWrap($conf['src'], $conf['src.']) : $conf['src'];
+        return GeneralUtility::getFileAbsFileName($src);
+    }
 }