[BUGFIX] IMAGE param stdWrap-function not working 96/29796/6
authorOliver Hader <oliver@typo3.org>
Sat, 3 May 2014 09:51:55 +0000 (11:51 +0200)
committerOliver Hader <oliver.hader@typo3.org>
Sat, 3 May 2014 12:27:55 +0000 (14:27 +0200)
Images in TypoScript are rendered using method cImage() of
the ContentObjectRender. This method has the possibility to
modify the HTML parameters to be set.

However, the parameters are not recognized, if those are only
rendered using stdWrap functions, e.g. using params.dataWrap

This change moves method stdWrapValue() from the FILES cObject
to the parent ContentObjectRenderer and delegates the call to
the new location of that method.
Besides that, a superfluous space has been removed from the
template markers definition.

Resolves: #58420
Releases: 6.2
Change-Id: I56229ef5aa5133205114c6ee945a68983ef3f52e
Reviewed-on: https://review.typo3.org/29796
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
Reviewed-by: Jan Runte
Tested-by: Jan Runte
Reviewed-by: Wouter Wolters
Reviewed-by: Oliver Hader
Tested-by: Oliver Hader
typo3/sysext/css_styled_content/static/setup.txt
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
typo3/sysext/frontend/Classes/ContentObject/FilesContentObject.php

index a6026ce..ec5db76 100644 (file)
@@ -673,7 +673,7 @@ tt_content.image.20 {
                layoutKey = {$styles.content.imgtext.layoutKey}
                layout {
                        default {
-                               element = <img src="###SRC###" width="###WIDTH###" height="###HEIGHT###" ###PARAMS######ALTPARAMS######BORDER######SELFCLOSINGTAGSLASH###>
+                               element = <img src="###SRC###" width="###WIDTH###" height="###HEIGHT###"###PARAMS######ALTPARAMS######BORDER######SELFCLOSINGTAGSLASH###>
                        }
                        srcset {
                                element = <img src="###SRC###" srcset="###SOURCECOLLECTION###"###PARAMS######ALTPARAMS######SELFCLOSINGTAGSLASH###>
index fddde98..1ef57d7 100644 (file)
@@ -1277,11 +1277,9 @@ class ContentObjectRenderer {
                        // This array is used to collect the image-refs on the page...
                        $GLOBALS['TSFE']->imagesOnPage[] = $source;
                        $altParam = $this->getAltParam($conf);
-                       $params = '';
-                       if ($conf['params'] && !isset($conf['params.'])) {
-                               $params = ' ' . $conf['params'];
-                       } elseif ($conf['params'] && is_array($conf['params.'])) {
-                               $params = ' ' . $this->stdWrap($conf['params'], $conf['params.']);
+                       $params = $this->stdWrapValue('params', $conf);
+                       if ($params !== '' && $params{0} !== ' ') {
+                               $params = ' ' . $params;
                        }
 
                        $imageTagValues = array(
@@ -2106,6 +2104,28 @@ class ContentObjectRenderer {
        }
 
        /**
+        * Gets a configuration value by passing them through stdWrap first and taking a default value if stdWrap doesn't yield a result.
+        *
+        * @param string $key The config variable key (from TS array).
+        * @param array $config The TypoScript array.
+        * @param string $defaultValue Optional default value.
+        * @return string Value of the config variable
+        */
+       public function stdWrapValue($key, array $config, $defaultValue = '') {
+               if (isset($config[$key])) {
+                       if (!isset($config[$key . '.'])) {
+                               return $config[$key];
+                       }
+               } elseif (isset($config[$key . '.'])) {
+                       $config[$key] = '';
+               } else {
+                       return $defaultValue;
+               }
+               $stdWrapped = $this->stdWrap($config[$key], $config[$key . '.']);
+               return $stdWrapped ?: $defaultValue;
+       }
+
+       /**
         * stdWrap pre process hook
         * can be used by extensions authors to modify the behaviour of stdWrap functions to their needs
         * this hook will execute functions before any other stdWrap function can modify anything
index c04d796..5ee572f 100644 (file)
@@ -71,7 +71,7 @@ class FilesContentObject extends \TYPO3\CMS\Frontend\ContentObject\AbstractConte
                        }# or: sys_file_references with uid 27:
                        references = 27
                         */
-                       $referencesUid = $this->stdWrapValue('references', $conf);
+                       $referencesUid = $this->cObj->stdWrapValue('references', $conf);
                        $referencesUidArray = GeneralUtility::intExplode(',', $referencesUid, TRUE);
                        foreach ($referencesUidArray as $referenceUid) {
                                try {
@@ -88,14 +88,14 @@ class FilesContentObject extends \TYPO3\CMS\Frontend\ContentObject\AbstractConte
 
                        // It's important that this always stays "fieldName" and not be renamed to "field" as it would otherwise collide with the stdWrap key of that name
                        if (!empty($conf['references.'])) {
-                               $referencesFieldName = $this->stdWrapValue('fieldName', $conf['references.']);
+                               $referencesFieldName = $this->cObj->stdWrapValue('fieldName', $conf['references.']);
                                if ($referencesFieldName) {
                                        $table = $this->cObj->getCurrentTable();
                                        if ($table === 'pages' && isset($this->cObj->data['_LOCALIZED_UID']) && (int)$this->cObj->data['sys_language_uid'] > 0) {
                                                $table = 'pages_language_overlay';
                                        }
-                                       $referencesForeignTable = $this->stdWrapValue('table', $conf['references.'], $table);
-                                       $referencesForeignUid = $this->stdWrapValue('uid', $conf['references.'], isset($this->cObj->data['_LOCALIZED_UID']) ? $this->cObj->data['_LOCALIZED_UID'] : $this->cObj->data['uid']);
+                                       $referencesForeignTable = $this->cObj->stdWrapValue('table', $conf['references.'], $table);
+                                       $referencesForeignUid = $this->cObj->stdWrapValue('uid', $conf['references.'], isset($this->cObj->data['_LOCALIZED_UID']) ? $this->cObj->data['_LOCALIZED_UID'] : $this->cObj->data['uid']);
                                        $this->addToArray($this->getFileRepository()->findByRelation($referencesForeignTable, $referencesFieldName, $referencesForeignUid), $fileObjects);
                                }
                        }
@@ -107,7 +107,7 @@ class FilesContentObject extends \TYPO3\CMS\Frontend\ContentObject\AbstractConte
                        files = 12,14,15# using stdWrap:
                        files.field = some_field
                         */
-                       $fileUids = GeneralUtility::intExplode(',', $this->stdWrapValue('files', $conf), TRUE);
+                       $fileUids = GeneralUtility::intExplode(',', $this->cObj->stdWrapValue('files', $conf), TRUE);
                        foreach ($fileUids as $fileUid) {
                                try {
                                        $this->addToArray($this->getFileFactory()->getFileObject($fileUid), $fileObjects);
@@ -119,7 +119,7 @@ class FilesContentObject extends \TYPO3\CMS\Frontend\ContentObject\AbstractConte
                        }
                }
                if ($conf['collections'] || $conf['collections.']) {
-                       $collectionUids = GeneralUtility::intExplode(',', $this->stdWrapValue('collections', $conf), TRUE);
+                       $collectionUids = GeneralUtility::intExplode(',', $this->cObj->stdWrapValue('collections', $conf), TRUE);
                        foreach ($collectionUids as $collectionUid) {
                                try {
                                        $fileCollection = $this->getCollectionRepository()->findByUid($collectionUid);
@@ -135,7 +135,7 @@ class FilesContentObject extends \TYPO3\CMS\Frontend\ContentObject\AbstractConte
                        }
                }
                if ($conf['folders'] || $conf['folders.']) {
-                       $folderIdentifiers = GeneralUtility::trimExplode(',', $this->stdWrapValue('folders', $conf));
+                       $folderIdentifiers = GeneralUtility::trimExplode(',', $this->cObj->stdWrapValue('folders', $conf));
                        foreach ($folderIdentifiers as $folderIdentifier) {
                                if ($folderIdentifier) {
                                        try {
@@ -159,7 +159,7 @@ class FilesContentObject extends \TYPO3\CMS\Frontend\ContentObject\AbstractConte
                // Enable sorting for multiple fileObjects
                $sortingProperty = '';
                if ($conf['sorting'] || $conf['sorting.']) {
-                       $sortingProperty = $this->stdWrapValue('sorting', $conf);
+                       $sortingProperty = $this->cObj->stdWrapValue('sorting', $conf);
                }
                if ($sortingProperty !== '' && count($fileObjects) > 1) {
                        @usort($fileObjects, function(\TYPO3\CMS\Core\Resource\FileInterface $a, \TYPO3\CMS\Core\Resource\FileInterface $b) use($sortingProperty) {
@@ -301,21 +301,10 @@ class FilesContentObject extends \TYPO3\CMS\Frontend\ContentObject\AbstractConte
         * @param array $config The TypoScript array.
         * @param string $defaultValue Optional default value.
         * @return string Value of the config variable
+        * @deprecated since TYPO3 CMS 6.2, use ContentObjectRenderer::stdWrapValue() instead. Will be removed two versions later.
         */
        protected function stdWrapValue($key, array $config, $defaultValue = '') {
-               if (isset($config[$key])) {
-                       if (!isset($config[$key . '.'])) {
-                               return $config[$key];
-                       }
-               } else {
-                       if (isset($config[$key . '.'])) {
-                               $config[$key] = '';
-                       } else {
-                               return $defaultValue;
-                       }
-               }
-               $stdWrapped = $this->cObj->stdWrap($config[$key], $config[$key . '.']);
-               return $stdWrapped ? $stdWrapped : $defaultValue;
+               return $this->cObj->stdWrapValue($key, $config, $defaultValue);
        }
 
 }