17 use Psr\Log\LoggerAwareInterface;
18 use Psr\Log\LoggerAwareTrait;
75 public function addFiles(array $fileUids = [])
77 if (!empty($fileUids)) {
78 foreach ($fileUids as $fileUid) {
82 $this->logger->warning(
83 'The file with uid "' . $fileUid
84 .
'" could not be found and won\'t be included in frontend output',
102 $fileReferences = $this->
getFileReferences($relationTable, $relationField, $referenceRecord);
107 if (!empty($fileReferences)) {
119 foreach ($fileReferenceUids as $fileReferenceUid) {
132 foreach ($fileCollectionUids as $fileCollectionUid) {
144 if (!empty($fileCollectionUid)) {
148 if ($fileCollection instanceof \
TYPO3\CMS\Core\Resource\Collection\AbstractFileCollection) {
149 $fileCollection->loadContents();
150 $files = $fileCollection->getItems();
155 $this->logger->warning(
156 'The file-collection with uid "' . $fileCollectionUid
157 .
'" could not be found or contents could not be loaded and won\'t be included in frontend output.',
172 foreach ($folderIdentifiers as $folderIdentifier) {
185 if ($folderIdentifier) {
187 if (strpos($folderIdentifier,
't3://folder') === 0) {
189 $linkService = GeneralUtility::makeInstance(LinkService::class);
190 $data = $linkService->resolveByStringRepresentation($folderIdentifier);
191 $folder = $data[
'folder'];
195 if ($folder instanceof
Folder) {
200 $this->logger->warning(
201 'The folder with identifier "' . $folderIdentifier
202 .
'" could not be found and won\'t be included in frontend output',
215 public function sort($sortingProperty =
'', $sortingOrder =
'ascending')
217 if ($sortingProperty !==
'' &&
count($this->files) > 1) {
223 ) use ($sortingProperty) {
225 return strnatcasecmp($a->getProperty($sortingProperty), $b->getProperty($sortingProperty));
231 switch (strtolower($sortingOrder)) {
234 $this->files = array_reverse($this->files);
238 shuffle($this->files);
251 $this->files[] = $file;
261 $this->files = array_merge($this->files,
$files);
279 return count($this->files);
294 $currentId = !empty($element[
'uid']) ? $element[
'uid'] : 0;
299 }
catch (FileDoesNotExistException $e) {
305 }
catch (\InvalidArgumentException $e) {
310 $logMessage = $e->getMessage() .
' (table: "' . $tableName .
'", fieldName: "' . $fieldName .
'", currentId: ' . $currentId .
')';
311 $this->logger->error($logMessage, [
'exception' => $e]);
316 if (isset($element[
'_LOCALIZED_UID'])) {
317 $localizedId = $element[
'_LOCALIZED_UID'];
318 } elseif (isset($element[
'_PAGES_OVERLAY_UID'])) {
319 $localizedId = $element[
'_PAGES_OVERLAY_UID'];
322 $isTableLocalizable = (
323 !empty(
$GLOBALS[
'TCA'][$tableName][
'ctrl'][
'languageField'])
324 && !empty(
$GLOBALS[
'TCA'][$tableName][
'ctrl'][
'transOrigPointerField'])
326 if ($isTableLocalizable && $localizedId !==
null) {
328 $references = $localizedReferences;
339 if ($this->resourceFactory ===
null) {
340 $this->resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
350 if ($this->fileCollectionRepository ===
null) {
351 $this->fileCollectionRepository = GeneralUtility::makeInstance(FileCollectionRepository::class);
361 if ($this->fileRepository ===
null) {
362 $this->fileRepository = GeneralUtility::makeInstance(FileRepository::class);