‪TYPO3CMS  10.4
TestTaskAdditionalFieldProvider.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['email'])) {
46  if ($currentSchedulerModuleAction->equals(‪Action::ADD)) {
47  // In case of new task and if field is empty, set default email address
48  $taskInfo['email'] = ‪$GLOBALS['BE_USER']->user['email'];
49  } elseif ($currentSchedulerModuleAction->equals(‪Action::EDIT)) {
50  // In case of edit, and editing a test task, set to internal value if not data was submitted already
51  $taskInfo['email'] = $task->email;
52  } else {
53  // Otherwise set an empty value, as it will not be used anyway
54  $taskInfo['email'] = '';
55  }
56  }
57  // Write the code for the field
58  $fieldID = 'task_email';
59  $fieldCode = '<input type="text" class="form-control" name="tx_scheduler[email]" id="' . $fieldID . '" value="' . htmlspecialchars($taskInfo['email']) . '" size="30">';
60  $additionalFields = [];
61  $additionalFields[$fieldID] = [
62  'code' => $fieldCode,
63  'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.email',
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['email'] = trim($submittedData['email']);
81  if (empty($submittedData['email'])) {
82  $this->‪addMessage(
83  $this->‪getLanguageService()->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.noEmail'),
85  );
86  $result = false;
87  } else {
88  $result = true;
89  }
90  return $result;
91  }
92 
100  public function ‪saveAdditionalFields(array $submittedData, ‪AbstractTask $task)
101  {
102  $task->email = $submittedData['email'];
103  }
104 
109  {
110  return ‪$GLOBALS['LANG'] ?? null;
111  }
112 }
‪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\TestTaskAdditionalFieldProvider\validateAdditionalFields
‪bool validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule)
Definition: TestTaskAdditionalFieldProvider.php:78
‪TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider
Definition: AbstractAdditionalFieldProvider.php:28
‪TYPO3\CMS\Scheduler\Example\TestTaskAdditionalFieldProvider\saveAdditionalFields
‪saveAdditionalFields(array $submittedData, AbstractTask $task)
Definition: TestTaskAdditionalFieldProvider.php:100
‪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\Example\TestTaskAdditionalFieldProvider
Definition: TestTaskAdditionalFieldProvider.php:30
‪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\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\TestTaskAdditionalFieldProvider\getAdditionalFields
‪array getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule)
Definition: TestTaskAdditionalFieldProvider.php:40
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:31
‪TYPO3\CMS\Scheduler\Example\TestTaskAdditionalFieldProvider\getLanguageService
‪LanguageService null getLanguageService()
Definition: TestTaskAdditionalFieldProvider.php:108