‪TYPO3CMS  10.4
RecyclerGarbageCollectionAdditionalFieldProvider.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
23 
32 {
38  protected ‪$defaultNumberOfDays = 30;
39 
49  public function ‪getAdditionalFields(array &$taskInfo, $task, ‪SchedulerModuleController $schedulerModule)
50  {
51  $currentSchedulerModuleAction = $schedulerModule->‪getCurrentAction();
52 
53  // Initialize selected fields
54  if (!isset($taskInfo['scheduler_recyclerGarbageCollection_numberOfDays'])) {
55  $taskInfo['scheduler_recyclerGarbageCollection_numberOfDays'] = ‪$this->defaultNumberOfDays;
56  if ($currentSchedulerModuleAction->equals(‪Action::EDIT)) {
57  $taskInfo['scheduler_recyclerGarbageCollection_numberOfDays'] = $task->numberOfDays;
58  }
59  }
60  $fieldName = 'tx_scheduler[scheduler_recyclerGarbageCollection_numberOfDays]';
61  $fieldId = 'task_recyclerGarbageCollection_numberOfDays';
62  $fieldValue = (string)(int)$taskInfo['scheduler_recyclerGarbageCollection_numberOfDays'];
63  $fieldHtml = '<input class="form-control" type="text" name="' . $fieldName . '" id="' . $fieldId . '" value="' . htmlspecialchars($fieldValue) . '">';
64  $additionalFields = [];
65  $additionalFields[$fieldId] = [
66  'code' => $fieldHtml,
67  'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.recyclerGarbageCollection.numberOfDays',
68  'cshKey' => '_MOD_system_txschedulerM1',
69  'cshLabel' => $fieldId
70  ];
71  return $additionalFields;
72  }
73 
81  public function ‪validateAdditionalFields(array &$submittedData, ‪SchedulerModuleController $schedulerModule)
82  {
83  $result = true;
84  // Check if number of days is indeed a number and greater or equals to 0
85  // If not, fail validation and issue error message
86  if (!is_numeric($submittedData['scheduler_recyclerGarbageCollection_numberOfDays']) || (int)$submittedData['scheduler_recyclerGarbageCollection_numberOfDays'] < 0) {
87  $result = false;
88  $this->‪addMessage($this->‪getLanguageService()->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.invalidNumberOfDays'), ‪FlashMessage::ERROR);
89  }
90  return $result;
91  }
92 
99  public function ‪saveAdditionalFields(array $submittedData, ‪AbstractTask $task)
100  {
101  $task->numberOfDays = (int)$submittedData['scheduler_recyclerGarbageCollection_numberOfDays'];
102  }
103 
107  protected function ‪getLanguageService(): ?‪LanguageService
108  {
109  return ‪$GLOBALS['LANG'] ?? null;
110  }
111 }
‪TYPO3\CMS\Scheduler\Task\RecyclerGarbageCollectionAdditionalFieldProvider
Definition: RecyclerGarbageCollectionAdditionalFieldProvider.php:32
‪TYPO3\CMS\Scheduler\Task
Definition: AbstractTask.php:16
‪TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider
Definition: AbstractAdditionalFieldProvider.php:28
‪TYPO3\CMS\Scheduler\Task\RecyclerGarbageCollectionAdditionalFieldProvider\getAdditionalFields
‪array getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule)
Definition: RecyclerGarbageCollectionAdditionalFieldProvider.php:48
‪TYPO3\CMS\Scheduler\Task\RecyclerGarbageCollectionAdditionalFieldProvider\validateAdditionalFields
‪bool validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule)
Definition: RecyclerGarbageCollectionAdditionalFieldProvider.php:80
‪TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider\addMessage
‪addMessage(string $message, int $severity=FlashMessage::OK)
Definition: AbstractAdditionalFieldProvider.php:35
‪TYPO3\CMS\Scheduler\Task\RecyclerGarbageCollectionAdditionalFieldProvider\$defaultNumberOfDays
‪int $defaultNumberOfDays
Definition: RecyclerGarbageCollectionAdditionalFieldProvider.php:37
‪TYPO3\CMS\Scheduler\Task\AbstractTask
Definition: AbstractTask.php:35
‪TYPO3\CMS\Scheduler\Task\RecyclerGarbageCollectionAdditionalFieldProvider\getLanguageService
‪LanguageService null getLanguageService()
Definition: RecyclerGarbageCollectionAdditionalFieldProvider.php:106
‪TYPO3\CMS\Scheduler\Controller\SchedulerModuleController
Definition: SchedulerModuleController.php:56
‪TYPO3\CMS\Scheduler\Task\Enumeration\Action\EDIT
‪const EDIT
Definition: Action.php:30
‪TYPO3\CMS\Scheduler\Controller\SchedulerModuleController\getCurrentAction
‪Action getCurrentAction()
Definition: SchedulerModuleController.php:181
‪TYPO3\CMS\Scheduler\Task\RecyclerGarbageCollectionAdditionalFieldProvider\saveAdditionalFields
‪saveAdditionalFields(array $submittedData, AbstractTask $task)
Definition: RecyclerGarbageCollectionAdditionalFieldProvider.php:98
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:24
‪TYPO3\CMS\Scheduler\Task\Enumeration\Action
Definition: Action.php:26
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:31