‪TYPO3CMS  10.4
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
59  $fileCollector = GeneralUtility::makeInstance(FileCollector::class);
60 
61  // references / relations
62  if (
63  (isset($processorConfiguration['references']) && $processorConfiguration['references'])
64  || (isset($processorConfiguration['references.']) && $processorConfiguration['references.'])
65  ) {
66  $referencesUidList = $cObj->‪stdWrapValue('references', $processorConfiguration);
67  $referencesUids = ‪GeneralUtility::intExplode(',', $referencesUidList, true);
68  $fileCollector->addFileReferences($referencesUids);
69 
70  if (!empty($processorConfiguration['references.'])) {
71  $referenceConfiguration = $processorConfiguration['references.'];
72  $relationField = $cObj->‪stdWrapValue('fieldName', $referenceConfiguration);
73 
74  // If no reference fieldName is set, there's nothing to do
75  if (!empty($relationField)) {
76  // Fetch the references of the default element
77  $relationTable = $cObj->‪stdWrapValue('table', $referenceConfiguration, $cObj->‪getCurrentTable());
78  if (!empty($relationTable)) {
79  $fileCollector->addFilesFromRelation($relationTable, $relationField, $cObj->data);
80  }
81  }
82  }
83  }
84 
85  // files
86  $files = $cObj->‪stdWrapValue('files', $processorConfiguration);
87  if ($files) {
88  $files = ‪GeneralUtility::intExplode(',', (string)$files, true);
89  $fileCollector->addFiles($files);
90  }
91 
92  // collections
93  $collections = $cObj->‪stdWrapValue('collections', $processorConfiguration);
94  if (!empty($collections)) {
95  $collections = ‪GeneralUtility::trimExplode(',', (string)$collections, true);
96  $fileCollector->addFilesFromFileCollections($collections);
97  }
98 
99  // folders
100  $folders = $cObj->‪stdWrapValue('folders', $processorConfiguration);
101  if (!empty($folders)) {
102  $folders = ‪GeneralUtility::trimExplode(',', (string)$folders, true);
103  $fileCollector->addFilesFromFolders($folders, !empty($processorConfiguration['folders.']['recursive']));
104  }
105 
106  // make sure to sort the files
107  $sortingProperty = $cObj->‪stdWrapValue('sorting', $processorConfiguration);
108  if ($sortingProperty) {
109  $sortingDirection = $cObj->‪stdWrapValue(
110  'direction',
111  $processorConfiguration['sorting.'] ?? [],
112  'ascending'
113  );
114 
115  $fileCollector->sort($sortingProperty, $sortingDirection);
116  }
117 
118  // set the files into a variable, default "files"
119  $targetVariableName = $cObj->‪stdWrapValue('as', $processorConfiguration, 'files');
120  $processedData[$targetVariableName] = $fileCollector->getFiles();
121 
122  return $processedData;
123  }
124 }
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\getCurrentTable
‪string getCurrentTable()
Definition: ContentObjectRenderer.php:567
‪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:41
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static string[] trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:1059
‪TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface
Definition: DataProcessorInterface.php:23
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\stdWrapValue
‪string stdWrapValue($key, array $config, $defaultValue='')
Definition: ContentObjectRenderer.php:1685
‪TYPO3\CMS\Core\Utility\GeneralUtility\intExplode
‪static int[] intExplode($delimiter, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:988
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:97
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\checkIf
‪bool checkIf($conf)
Definition: ContentObjectRenderer.php:3074
‪TYPO3\CMS\Frontend\DataProcessing\FilesProcessor\process
‪array process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData)
Definition: FilesProcessor.php:51