[CLEANUP] Improve the @param/@return/@var 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 if ($task !== NULL && !$task instanceof FileStorageIndexingTask) {
33 throw new \InvalidArgumentException('Task not of type FileStorageExtractionTask', 1384275696);
34 }
35 $additionalFields['scheduler_fileStorageIndexing_storage'] = $this->getAllStoragesField($task);
36 return $additionalFields;
37 }
38
39 /**
40 * Add a select field of available storages.
41 *
42 * @param FileStorageIndexingTask $task When editing, reference to the current task object. NULL when adding.
43 * @return array Array containing all the information pertaining to the additional fields
44 */
45 protected function getAllStoragesField(FileStorageIndexingTask $task = NULL) {
46 /** @var \TYPO3\CMS\Core\Resource\ResourceStorage[] $storages */
47 $storages = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class)->findAll();
48 $options = array();
49 foreach ($storages as $storage) {
50 if ($task != NULL && $task->storageUid === $storage->getUid()) {
51 $options[] = '<option value="' . $storage->getUid() . '" selected="selected">' . $storage->getName() . '</option>';
52 } else {
53 $options[] = '<option value="' . $storage->getUid() . '">' . $storage->getName() . '</option>';
54 }
55 }
56
57 $fieldName = 'tx_scheduler[scheduler_fileStorageIndexing_storage]';
58 $fieldId = 'scheduler_fileStorageIndexing_storage';
59 $fieldHtml = '<select name="' . $fieldName . '" id="' . $fieldId . '">' . implode("\n", $options) . '</select>';
60
61 $fieldConfiguration = array(
62 'code' => $fieldHtml,
63 'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.fileStorageIndexing.storage',
64 'cshKey' => '_MOD_system_txschedulerM1',
65 'cshLabel' => $fieldId
66 );
67 return $fieldConfiguration;
68 }
69
70 /**
71 * Validate additional fields
72 *
73 * @param array $submittedData Reference to the array containing the data submitted by the user
74 * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject Reference to the calling object (Scheduler's BE module)
75 * @return bool True if validation was ok (or selected class is not relevant), false otherwise
76 */
77 public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject) {
78 $value = $submittedData['scheduler_fileStorageIndexing_storage'];
79 if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($value)) {
80 return FALSE;
81 } elseif(\TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getStorageObject($submittedData['scheduler_fileStorageIndexing_storage']) !== NULL) {
82 return TRUE;
83 }
84 return FALSE;
85 }
86
87 /**
88 * Save additional field in task
89 *
90 * @param array $submittedData Contains data submitted by the user
91 * @param \TYPO3\CMS\Scheduler\Task\AbstractTask $task Reference to the current task object
92 * @return void
93 * @throws \InvalidArgumentException
94 */
95 public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task) {
96 if (!$task instanceof FileStorageIndexingTask) {
97 throw new \InvalidArgumentException('Task not of type FileStorageExtractionTask', 1384275697);
98 }
99 $task->storageUid = (int)$submittedData['scheduler_fileStorageIndexing_storage'];
100 }
101
102 }