[CLEANUP] The correct case must be used for standard PHP types in phpdoc
[Packages/TYPO3.CMS.git] / typo3 / sysext / scheduler / Classes / Task / FileStorageIndexingAdditionalFieldProvider.php
1 <?php
2 namespace TYPO3\CMS\Scheduler\Task;
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
17 /**
18 * Additional BE fields for tasks which indexes files in a storage
19 */
20 class FileStorageIndexingAdditionalFieldProvider implements \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface
21 {
22 /**
23 * Add additional fields
24 *
25 * @param array $taskInfo Reference to the array containing the info used in the add/edit form
26 * @param AbstractTask|null $task When editing, reference to the current task. NULL when adding.
27 * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject Reference to the calling object (Scheduler's BE module)
28 * @return array Array containing all the information pertaining to the additional fields
29 * @throws \InvalidArgumentException
30 */
31 public function getAdditionalFields(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
32 {
33 if ($task !== null && !$task instanceof FileStorageIndexingTask) {
34 throw new \InvalidArgumentException('Task not of type FileStorageExtractionTask', 1384275696);
35 }
36 $additionalFields['scheduler_fileStorageIndexing_storage'] = $this->getAllStoragesField($task);
37 return $additionalFields;
38 }
39
40 /**
41 * Add a select field of available storages.
42 *
43 * @param FileStorageIndexingTask $task When editing, reference to the current task object. NULL when adding.
44 * @return array Array containing all the information pertaining to the additional fields
45 */
46 protected function getAllStoragesField(FileStorageIndexingTask $task = null)
47 {
48 /** @var \TYPO3\CMS\Core\Resource\ResourceStorage[] $storages */
49 $storages = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class)->findAll();
50 $options = [];
51 foreach ($storages as $storage) {
52 if ($task != null && $task->storageUid === $storage->getUid()) {
53 $options[] = '<option value="' . $storage->getUid() . '" selected="selected">' . $storage->getName() . '</option>';
54 } else {
55 $options[] = '<option value="' . $storage->getUid() . '">' . $storage->getName() . '</option>';
56 }
57 }
58
59 $fieldName = 'tx_scheduler[scheduler_fileStorageIndexing_storage]';
60 $fieldId = 'scheduler_fileStorageIndexing_storage';
61 $fieldHtml = '<select class="form-control" name="' . $fieldName . '" id="' . $fieldId . '">' . implode("\n", $options) . '</select>';
62
63 $fieldConfiguration = [
64 'code' => $fieldHtml,
65 'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.fileStorageIndexing.storage',
66 'cshKey' => '_MOD_system_txschedulerM1',
67 'cshLabel' => $fieldId
68 ];
69 return $fieldConfiguration;
70 }
71
72 /**
73 * Validate additional fields
74 *
75 * @param array $submittedData Reference to the array containing the data submitted by the user
76 * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject Reference to the calling object (Scheduler's BE module)
77 * @return bool True if validation was ok (or selected class is not relevant), false otherwise
78 */
79 public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
80 {
81 $value = $submittedData['scheduler_fileStorageIndexing_storage'];
82 if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($value)) {
83 return false;
84 }
85 if (\TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getStorageObject($submittedData['scheduler_fileStorageIndexing_storage']) !== null) {
86 return true;
87 }
88 return false;
89 }
90
91 /**
92 * Save additional field in task
93 *
94 * @param array $submittedData Contains data submitted by the user
95 * @param \TYPO3\CMS\Scheduler\Task\AbstractTask $task Reference to the current task object
96 * @throws \InvalidArgumentException
97 */
98 public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task)
99 {
100 if (!$task instanceof FileStorageIndexingTask) {
101 throw new \InvalidArgumentException('Task not of type FileStorageExtractionTask', 1384275697);
102 }
103 $task->storageUid = (int)$submittedData['scheduler_fileStorageIndexing_storage'];
104 }
105 }