TYPO3 CMS  TYPO3_7-6
FileStorageIndexingAdditionalFieldProvider.php
Go to the documentation of this file.
1 <?php
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 
21 {
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 
46  protected function getAllStoragesField(FileStorageIndexingTask $task = null)
47  {
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 
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  } elseif (\TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getStorageObject($submittedData['scheduler_fileStorageIndexing_storage']) !== null) {
85  return true;
86  }
87  return false;
88  }
89 
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 }
validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
getAdditionalFields(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task)