TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
FilesProcessor.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Frontend\DataProcessing;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 
40 {
50  public function process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData)
51  {
52  if (isset($processorConfiguration['if.']) && !$cObj->checkIf($processorConfiguration['if.'])) {
53  return $processedData;
54  }
55 
56  // gather data
58  $fileCollector = GeneralUtility::makeInstance(FileCollector::class);
59 
60  // references / relations
61  if (!empty($processorConfiguration['references.'])) {
62  $referenceConfiguration = $processorConfiguration['references.'];
63  $relationField = $cObj->stdWrapValue('fieldName', $referenceConfiguration);
64 
65  // If no reference fieldName is set, there's nothing to do
66  if (!empty($relationField)) {
67  // Fetch the references of the default element
68  $relationTable = $cObj->stdWrapValue('table', $referenceConfiguration, $cObj->getCurrentTable());
69  if (!empty($relationTable)) {
70  $fileCollector->addFilesFromRelation($relationTable, $relationField, $cObj->data);
71  }
72  }
73  }
74 
75  // files
76  $files = $cObj->stdWrapValue('files', $processorConfiguration);
77  if ($files) {
78  $files = GeneralUtility::intExplode(',', $files, true);
79  $fileCollector->addFiles($files);
80  }
81 
82  // collections
83  $collections = $cObj->stdWrapValue('collections', $processorConfiguration);
84  if (!empty($collections)) {
85  $collections = GeneralUtility::trimExplode(',', $collections, true);
86  $fileCollector->addFilesFromFileCollections($collections);
87  }
88 
89  // folders
90  $folders = $cObj->stdWrapValue('folders', $processorConfiguration);
91  if (!empty($folders)) {
92  $folders = GeneralUtility::trimExplode(',', $folders, true);
93  $fileCollector->addFilesFromFolders($folders, !empty($processorConfiguration['folders.']['recursive']));
94  }
95 
96  // make sure to sort the files
97  $sortingProperty = $cObj->stdWrapValue('sorting', $processorConfiguration);
98  if ($sortingProperty) {
99  $sortingDirection = $cObj->stdWrapValue(
100  'direction',
101  isset($processorConfiguration['sorting.']) ? $processorConfiguration['sorting.'] : [],
102  'ascending'
103  );
104 
105  $fileCollector->sort($sortingProperty, $sortingDirection);
106  }
107 
108  // set the files into a variable, default "files"
109  $targetVariableName = $cObj->stdWrapValue('as', $processorConfiguration, 'files');
110  $processedData[$targetVariableName] = $fileCollector->getFiles();
111 
112  return $processedData;
113  }
114 }
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
static makeInstance($className,...$constructorArguments)
process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData)
static intExplode($delimiter, $string, $removeEmptyValues=false, $limit=0)