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