‪TYPO3CMS  10.4
SleepTaskAdditionalFieldProvider.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 
24 
30 {
40  public function ‪getAdditionalFields(array &$taskInfo, $task, ‪SchedulerModuleController $schedulerModule)
41  {
42  $currentSchedulerModuleAction = $schedulerModule->‪getCurrentAction();
43 
44  // Initialize extra field value
45  if (empty($taskInfo['sleepTime'])) {
46  if ($currentSchedulerModuleAction->equals(‪Action::ADD)) {
47  // In case of new task and if field is empty, set default sleep time
48  $taskInfo['sleepTime'] = 30;
49  } elseif ($currentSchedulerModuleAction->equals(‪Action::EDIT)) {
50  // In case of edit, set to internal value if no data was submitted already
51  $taskInfo['sleepTime'] = $task->sleepTime;
52  } else {
53  // Otherwise set an empty value, as it will not be used anyway
54  $taskInfo['sleepTime'] = '';
55  }
56  }
57  // Write the code for the field
58  $fieldID = 'task_sleepTime';
59  $fieldCode = '<input type="text" class="form-control" name="tx_scheduler[sleepTime]" id="' . $fieldID . '" value="' . $taskInfo['sleepTime'] . '" size="10">';
60  $additionalFields = [];
61  $additionalFields[$fieldID] = [
62  'code' => $fieldCode,
63  'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.sleepTime',
64  'cshKey' => '_MOD_system_txschedulerM1',
65  'cshLabel' => $fieldID
66  ];
67  return $additionalFields;
68  }
69 
78  public function ‪validateAdditionalFields(array &$submittedData, ‪SchedulerModuleController $schedulerModule)
79  {
80  $submittedData['sleepTime'] = (int)$submittedData['sleepTime'];
81  if ($submittedData['sleepTime'] < 0) {
82  $this->‪addMessage($this->‪getLanguageService()->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.invalidSleepTime'), ‪FlashMessage::ERROR);
83  $result = false;
84  } else {
85  $result = true;
86  }
87  return $result;
88  }
89 
97  public function ‪saveAdditionalFields(array $submittedData, ‪AbstractTask $task)
98  {
99  $task->sleepTime = $submittedData['sleepTime'];
100  }
101 
106  {
107  return ‪$GLOBALS['LANG'] ?? null;
108  }
109 }
‪TYPO3\CMS\Scheduler\Example\SleepTaskAdditionalFieldProvider\getAdditionalFields
‪array getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule)
Definition: SleepTaskAdditionalFieldProvider.php:40
‪TYPO3\CMS\Scheduler\Task\Enumeration\Action\ADD
‪const ADD
Definition: Action.php:28
‪TYPO3\CMS\Scheduler\Example
Definition: SleepTask.php:16
‪TYPO3\CMS\Scheduler\Example\SleepTaskAdditionalFieldProvider
Definition: SleepTaskAdditionalFieldProvider.php:30
‪TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider
Definition: AbstractAdditionalFieldProvider.php:28
‪TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider\addMessage
‪addMessage(string $message, int $severity=FlashMessage::OK)
Definition: AbstractAdditionalFieldProvider.php:35
‪TYPO3\CMS\Scheduler\Task\AbstractTask
Definition: AbstractTask.php:35
‪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\Example\SleepTaskAdditionalFieldProvider\saveAdditionalFields
‪saveAdditionalFields(array $submittedData, AbstractTask $task)
Definition: SleepTaskAdditionalFieldProvider.php:97
‪TYPO3\CMS\Scheduler\Controller\SchedulerModuleController\getCurrentAction
‪Action getCurrentAction()
Definition: SchedulerModuleController.php:181
‪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\Scheduler\Example\SleepTaskAdditionalFieldProvider\validateAdditionalFields
‪bool validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule)
Definition: SleepTaskAdditionalFieldProvider.php:78
‪TYPO3\CMS\Scheduler\Example\SleepTaskAdditionalFieldProvider\getLanguageService
‪LanguageService null getLanguageService()
Definition: SleepTaskAdditionalFieldProvider.php:105
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:31