[BUGFIX] Sorting of file links CE is broken 49/19649/2
authorNicole Cordes <typo3@cordes.co>
Sat, 6 Apr 2013 01:17:18 +0000 (03:17 +0200)
committerSteffen Ritter <info@rs-websystems.de>
Sat, 6 Apr 2013 09:21:37 +0000 (11:21 +0200)
On editing a content element of CType "uploads" ("File Links") you can
define fields for sorting and target of the files. Those fields are not
evaluated during the frontend rendering process.

Change-Id: I3d59f3088e7600b5c4c57c5187f288b600adaf16
Fixes: #46444
Releases: 6.1, 6.0
Reviewed-on: https://review.typo3.org/19649
Reviewed-by: Steffen Ritter
Tested-by: Steffen Ritter
typo3/sysext/css_styled_content/static/setup.txt
typo3/sysext/frontend/Classes/ContentObject/FilesContentObject.php

index cc1b371..2975708 100644 (file)
@@ -1190,6 +1190,8 @@ tt_content.uploads {
                # get from path (backwards compatibility, contains strings like "fileadmin/user_uploads/")
                folders.field = select_key
 
+               sorting.field = filelink_sorting
+
                # render the files
                renderObj = COA
                renderObj {
@@ -1204,9 +1206,10 @@ tt_content.uploads {
                                        typolink {
                                                parameter.data = file:current:originalUid // file:current:uid
                                                parameter.wrap = file:|
-                                               target < lib.parseTarget
-                                               target =
-                                               target.override = {$styles.content.uploads.target}
+                                               fileTarget < lib.parseTarget
+                                               fileTarget =
+                                               fileTarget.override = {$styles.content.uploads.target}
+                                               fileTarget.override.override.field = target
                                                removePrependedNumbers = 1
 
                                                /*
index b4a7376..473d6d9 100644 (file)
@@ -137,6 +137,20 @@ class FilesContentObject extends \TYPO3\CMS\Frontend\ContentObject\AbstractConte
                $content = '';
                // optionSplit applied to conf to allow differnt settings per file
                $splitConf = $GLOBALS['TSFE']->tmpl->splitConfArray($conf, count($fileObjects));
+               // Enable sorting for multiple fileObjects
+               $sortingProperty = '';
+               if ($conf['sorting'] || $conf['sorting.']) {
+                       $sortingProperty = $this->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) {
+                               if ($a->hasProperty($sortingProperty) && $b->hasProperty($sortingProperty)) {
+                                       return strnatcasecmp($a->getProperty($sortingProperty), $b->getProperty($sortingProperty));
+                               } else {
+                                       return 0;
+                               }
+                       });
+               }
                foreach ($fileObjects as $key => $fileObject) {
                        $this->cObj->setCurrentFile($fileObject);
                        $content .= $this->cObj->cObjGetSingle($splitConf[$key]['renderObj'], $splitConf[$key]['renderObj.']);