Skip to content

Commit fc87003

Browse files
committed
sync with v13 branch
1 parent d4de050 commit fc87003

File tree

12 files changed

+126
-116
lines changed

12 files changed

+126
-116
lines changed

Classes/Controller/GalleryController.php

Lines changed: 19 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,14 @@
22

33
namespace WapplerSystems\FilecollectionGallery\Controller;
44

5-
/*
6-
* This file is part of the TYPO3 CMS project.
7-
*
8-
* It is free software; you can redistribute it and/or modify it under
9-
* the terms of the GNU General Public License, either version 2
10-
* of the License, or any later version.
11-
*
12-
* For the full copyright and license information, please read the
13-
* LICENSE.txt file that was distributed with this source code.
14-
*
15-
* The TYPO3 project - inspiring people to share!
16-
*/
175

186
use Psr\Http\Message\ResponseInterface;
197
use TYPO3\CMS\Core\Resource\Collection\AbstractFileCollection;
8+
use TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException;
209
use TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException;
2110
use TYPO3\CMS\Core\Resource\FileCollectionRepository;
11+
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
2212
use TYPO3\CMS\Extbase\Mvc\View\ViewResolverInterface;
23-
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
24-
use TYPO3Fluid\Fluid\View\AbstractTemplateView;
2513
use WapplerSystems\FilecollectionGallery\Service\FileCollectionService;
2614
use WapplerSystems\FilecollectionGallery\Service\FolderService;
2715

@@ -30,11 +18,15 @@
3018
*
3119
* @author Sven Wappler <typo3@wappler.systems>
3220
*/
33-
class GalleryController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
21+
class GalleryController extends ActionController
3422
{
3523

3624

37-
public function __construct(readonly FileCollectionService $fileCollectionService, readonly FileCollectionRepository $fileCollectionRepository, readonly FolderService $folderService, readonly ViewResolverInterface $viewResolver)
25+
public function __construct(
26+
readonly FileCollectionService $fileCollectionService,
27+
readonly FileCollectionRepository $fileCollectionRepository,
28+
readonly FolderService $folderService,
29+
readonly ViewResolverInterface $viewResolver)
3830
{
3931

4032
}
@@ -59,11 +51,10 @@ protected function initializeView($view)
5951
* @return ResponseInterface
6052
* @throws ResourceDoesNotExistException
6153
*/
62-
public function listAction($offset = 0): ResponseInterface
54+
public function listAction(int $offset = 0): ResponseInterface
6355
{
64-
65-
$collectionUids = (trim($this->settings['fileCollection']) !== '') ? explode(',', $this->settings['fileCollection']) : [];
66-
if (isset($this->settings['inlineFileCollection'])) {
56+
$collectionUids = (trim($this->settings['fileCollection'] ?? '') !== '') ? explode(',', $this->settings['fileCollection']) : [];
57+
if (($this->settings['inlineFileCollection'] ?? '') !== '') {
6758
$collectionUids = array_merge($collectionUids, explode(',', $this->settings['inlineFileCollection']));
6859
}
6960
$cObj = $this->request->getAttribute('currentContentObject');
@@ -80,11 +71,11 @@ public function listAction($offset = 0): ResponseInterface
8071

8172
if ($this->request->hasArgument('galleryUID')) {
8273
$gallery = [$this->request->getArgument('galleryUID')];
83-
$mediaItems = $this->fileCollectionService->getFileObjectsFromCollection($gallery);
74+
$mediaItems = $this->fileCollectionService->getFileObjectsFromCollection($gallery, $this->settings['order'] ?? 'asc');
8475
$collection = $this->fileCollectionRepository->findByUid($this->request->getArgument('galleryUID'));
8576
$showBackToGallerySelectionLink = true;
8677
} else {
87-
$mediaItems = $this->fileCollectionService->getFileObjectsFromCollection($collectionUids);
78+
$mediaItems = $this->fileCollectionService->getFileObjectsFromCollection($collectionUids, $this->settings['order'] ?? 'asc');
8879
}
8980

9081
if ($collection === null && count($collectionUids) === 1) {
@@ -112,6 +103,7 @@ public function listAction($offset = 0): ResponseInterface
112103
* @param int $offset The offset
113104
*
114105
* @return ResponseInterface
106+
* @throws ResourceDoesNotExistException|InsufficientFolderAccessPermissionsException
115107
*/
116108
public function listFromFolderAction($offset = 0): ResponseInterface
117109
{
@@ -153,7 +145,7 @@ public function listFromFolderAction($offset = 0): ResponseInterface
153145
*
154146
* @param int $offset The offset
155147
*
156-
* @return void
148+
* @return ResponseInterface
157149
*/
158150
public function nestedAction($offset = 0): ResponseInterface
159151
{
@@ -185,7 +177,7 @@ public function nestedAction($offset = 0): ResponseInterface
185177
*
186178
* @param int $offset The offset
187179
*
188-
* @return void
180+
* @return ResponseInterface
189181
*/
190182
public function nestedFromFolderAction($offset = 0): ResponseInterface
191183
{
@@ -213,30 +205,14 @@ public function nestedFromFolderAction($offset = 0): ResponseInterface
213205
}
214206

215207

216-
217208
protected function htmlErrorResponse(?string $errorLabel = null): ResponseInterface
218209
{
219-
$view = $this->viewResolver->resolve(
220-
$this->request->getControllerObjectName(),
221-
$this->request->getControllerActionName(),
222-
$this->request->getFormat()
223-
);
224-
$this->setViewConfiguration($view);
225-
if ($view instanceof AbstractTemplateView) {
226-
$renderingContext = $view->getRenderingContext();
227-
if ($renderingContext instanceof RenderingContext) {
228-
$renderingContext->setRequest($this->request);
229-
}
230-
$renderingContext->setControllerAction('error');
231-
$templatePaths = $view->getRenderingContext()->getTemplatePaths();
232-
$templatePaths->fillDefaultsByPackageName($this->request->getControllerExtensionKey());
233-
$templatePaths->setFormat($this->request->getFormat());
234-
}
235-
$view->assign('errorLabel', $errorLabel);
210+
$this->view->setTemplatePathAndFilename('EXT:filecollection_gallery/Resources/Private/Templates/Gallery/Error.html');
211+
$this->view->assign('errorLabel', $errorLabel);
236212

237213
return $this->responseFactory->createResponse()
238214
->withHeader('Content-Type', 'text/html; charset=utf-8')
239215
->withStatus(500)
240-
->withBody($this->streamFactory->createStream($view->render()));
216+
->withBody($this->streamFactory->createStream($this->view->render()));
241217
}
242218
}

Classes/Hooks/DataHandlerHooks.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
<?php
22
namespace WapplerSystems\FilecollectionGallery\Hooks;
33

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-
*/
164

175
use TYPO3\CMS\Core\Utility\GeneralUtility;
186

Classes/Service/FileCollectionService.php

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,9 @@
22

33
namespace WapplerSystems\FilecollectionGallery\Service;
44

5-
/*
6-
* This file is part of the TYPO3 CMS project.
7-
*
8-
* It is free software; you can redistribute it and/or modify it under
9-
* the terms of the GNU General Public License, either version 2
10-
* of the License, or any later version.
11-
*
12-
* For the full copyright and license information, please read the
13-
* LICENSE.txt file that was distributed with this source code.
14-
*
15-
* The TYPO3 project - inspiring people to share!
16-
*/
175

186
use TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException;
7+
use TYPO3\CMS\Core\Resource\File;
198
use TYPO3\CMS\Core\Resource\FileCollectionRepository;
209
use TYPO3\CMS\Core\Resource\FileReference;
2110
use TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager;
@@ -28,20 +17,24 @@
2817
class FileCollectionService
2918
{
3019

31-
public function __construct(readonly FileCollectionRepository $fileCollectionRepository, readonly FrontendConfigurationManager $frontendConfigurationManager)
20+
21+
public function __construct(
22+
readonly FileCollectionRepository $fileCollectionRepository,
23+
readonly FrontendConfigurationManager $frontendConfigurationManager)
3224
{
3325

3426
}
3527

28+
3629
/**
3730
* Returns an array of file objects for the given UIDs of fileCollections
3831
*
3932
* @param array $collectionUids The uids
40-
*
33+
* @param string $sortingDirection
4134
* @return array
4235
* @throws ResourceDoesNotExistException
4336
*/
44-
public function getFileObjectsFromCollection(array $collectionUids)
37+
public function getFileObjectsFromCollection(array $collectionUids, string $sortingDirection = 'asc'): array
4538
{
4639
$imageItems = [];
4740
foreach ($collectionUids as $collectionUid) {
@@ -59,7 +52,7 @@ public function getFileObjectsFromCollection(array $collectionUids)
5952
'title' => $collection->getTitle(),
6053
'description' => $collection->getDescription()
6154
];
62-
if ($item instanceof \TYPO3\CMS\Core\Resource\FileReference) {
55+
if ($item instanceof FileReference) {
6356
$file = $this->getFileObjectFromFileReference($item);
6457
$file->updateProperties(['collection' => $collectionProperties]);
6558
$imageItems[] = $file;
@@ -69,7 +62,7 @@ public function getFileObjectsFromCollection(array $collectionUids)
6962
}
7063
}
7164
}
72-
return $this->sortFileObjects($imageItems);
65+
return $this->sortFileObjects($imageItems, $sortingDirection);
7366
}
7467

7568

@@ -79,29 +72,34 @@ public function getFileObjectsFromCollection(array $collectionUids)
7972
*
8073
* @param $collectionUids
8174
* @param $galleryFolderHash
75+
* @param string $sortingDirection
8276
* @return array
77+
* @throws ResourceDoesNotExistException
8378
*/
84-
public function getGalleryItemsByFolderHash($collectionUids, $galleryFolderHash)
79+
public function getGalleryItemsByFolderHash($collectionUids, $galleryFolderHash, string $sortingDirection = 'asc'): array
8580
{
8681
$imageItems = [];
8782

8883
// Load all images from collection
8984
foreach ($collectionUids as $collectionUid) {
9085
$collection = $this->fileCollectionRepository->findByUid($collectionUid);
86+
if ($collection === null) {
87+
continue;
88+
}
9189
$collection->loadContents();
9290
$allItems = [];
9391

9492
// Load all image and sort them by folder_hash
9593
foreach ($collection->getItems() as $item) {
9694
if ($item->getProperty('folder_hash') === $galleryFolderHash) {
97-
if (get_class($item) === 'TYPO3\CMS\Core\Resource\FileReference') {
98-
array_push($allItems, $this->getFileObjectFromFileReference($item));
95+
if ($item instanceof FileReference) {
96+
$allItems[] = $this->getFileObjectFromFileReference($item);
9997
} else {
100-
array_push($allItems, $item);
98+
$allItems[] = $item;
10199
}
102100
}
103101
}
104-
$imageItems = $this->sortFileObjects($allItems);
102+
$imageItems = $this->sortFileObjects($allItems, $sortingDirection);
105103
}
106104
return $imageItems;
107105
}
@@ -112,7 +110,7 @@ public function getGalleryItemsByFolderHash($collectionUids, $galleryFolderHash)
112110
* @param array $settings The current settings
113111
* @return array
114112
*/
115-
public function buildPaginationArray($settings)
113+
public function buildPaginationArray($settings): array
116114
{
117115
$paginationArray = [];
118116
if (!empty($settings)) {
@@ -132,7 +130,7 @@ public function buildPaginationArray($settings)
132130
* @param array $settings The current settings
133131
* @return array
134132
*/
135-
public function buildPaginationArrayForNested($settings)
133+
public function buildPaginationArrayForNested(array $settings): array
136134
{
137135
$paginationArray = [];
138136
if (!empty($settings)) {
@@ -147,7 +145,7 @@ public function buildPaginationArrayForNested($settings)
147145
}
148146

149147

150-
protected function sortFileObjectsByName($items, int $direction)
148+
protected function sortFileObjectsByName($items, int $direction): void
151149
{
152150
$lowercaseNames = array_map(function ($n) {
153151
return strtolower($n->getName());
@@ -156,7 +154,7 @@ protected function sortFileObjectsByName($items, int $direction)
156154
array_multisort($lowercaseNames, $direction, SORT_STRING, $items);
157155
}
158156

159-
protected function sortFileObjectsByDate($items, int $direction)
157+
protected function sortFileObjectsByDate($items, int $direction): void
160158
{
161159
$dates = array_map(function ($n) {
162160
return strtolower($n->getCreationTime());
@@ -165,7 +163,7 @@ protected function sortFileObjectsByDate($items, int $direction)
165163
array_multisort($dates, $direction, SORT_NUMERIC, $items);
166164
}
167165

168-
protected function sortFileObjectsByFolderHash(&$items, int $direction)
166+
protected function sortFileObjectsByFolderHash(&$items, int $direction): void
169167
{
170168
$folderhashes = array_map(function ($n) {
171169
return strtolower($n->getProperty('folder_hash'));
@@ -181,10 +179,9 @@ protected function sortFileObjectsByFolderHash(&$items, int $direction)
181179
*
182180
* @return array
183181
*/
184-
protected function sortFileObjects($imageItems)
182+
protected function sortFileObjects(array $imageItems, string $sortingDirection = 'asc'): array
185183
{
186-
$configuration = $this->frontendConfigurationManager->getConfiguration();
187-
switch ($configuration['settings']['order'] ?? '') {
184+
switch ($sortingDirection) {
188185
case 'desc':
189186
$this->sortFileObjectsByName($imageItems, SORT_DESC);
190187
break;
@@ -208,12 +205,12 @@ protected function sortFileObjects($imageItems)
208205
* Returns an FileObject from a given FileReference
209206
*
210207
*/
211-
protected function getFileObjectFromFileReference(FileReference $item): \TYPO3\CMS\Core\Resource\File
208+
protected function getFileObjectFromFileReference(FileReference $item): File
212209
{
213210
/**
214211
* The item to return
215212
*
216-
* @var \TYPO3\CMS\Core\Resource\File $returnItem
213+
* @var File $returnItem
217214
*/
218215
$returnItem = $item->getOriginalFile();
219216
$returnItem->updateProperties($item->getProperties());

Classes/Service/FolderService.php

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
<?php
22
namespace WapplerSystems\FilecollectionGallery\Service;
33

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-
*/
4+
5+
use TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException;
6+
use TYPO3\CMS\Core\Resource\File;
7+
use TYPO3\CMS\Core\Resource\Folder;
8+
use TYPO3\CMS\Core\Resource\InaccessibleFolder;
169

1710
/**
1811
* FolderService
@@ -24,13 +17,12 @@ class FolderService
2417

2518
/**
2619
*
27-
* @return \TYPO3\CMS\Core\Resource\Folder|\TYPO3\CMS\Core\Resource\InaccessibleFolder
28-
*
29-
* @param \TYPO3\CMS\Core\Resource\File $file
20+
* @param File $file
21+
* @return Folder|InaccessibleFolder
22+
* @throws InsufficientFolderAccessPermissionsException
3023
*/
31-
public function getFolderByFile($file)
24+
public function getFolderByFile($file): Folder|InaccessibleFolder
3225
{
33-
/** @var \TYPO3\CMS\Core\Resource\ResourceStorage $storage */
3426
$storage = $file->getStorage();
3527
$folderIdentifier = $storage->getFolderIdentifierFromFileIdentifier($file->getIdentifier());
3628
return $storage->getFolder($folderIdentifier);

Classes/Updates/MigrateSfToWsGalleryUpdateWizard.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace WapplerSystems\FilecollectionGallery\Updates;
66

7+
use Doctrine\DBAL\Exception;
78
use TYPO3\CMS\Core\Database\ConnectionPool;
89
use TYPO3\CMS\Core\Utility\GeneralUtility;
910
use TYPO3\CMS\Install\Attribute\UpgradeWizard;
@@ -48,6 +49,7 @@ public function getTitle(): string
4849
* Checks if an update is needed
4950
*
5051
* @return bool Whether an update is needed (true) or not (false)
52+
* @throws Exception
5153
*/
5254
public function updateNecessary(): bool
5355
{

0 commit comments

Comments
 (0)