‪TYPO3CMS  9.5
TestTaskAdditionalFieldProvider.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 
22 
28 {
38  public function ‪getAdditionalFields(array &$taskInfo, $task, ‪SchedulerModuleController $schedulerModule)
39  {
40  $currentSchedulerModuleAction = $schedulerModule->‪getCurrentAction();
41 
42  // Initialize extra field value
43  if (empty($taskInfo['email'])) {
44  if ($currentSchedulerModuleAction->equals(‪Action::ADD)) {
45  // In case of new task and if field is empty, set default email address
46  $taskInfo['email'] = ‪$GLOBALS['BE_USER']->user['email'];
47  } elseif ($currentSchedulerModuleAction->equals(‪Action::EDIT)) {
48  // In case of edit, and editing a test task, set to internal value if not data was submitted already
49  $taskInfo['email'] = $task->email;
50  } else {
51  // Otherwise set an empty value, as it will not be used anyway
52  $taskInfo['email'] = '';
53  }
54  }
55  // Write the code for the field
56  $fieldID = 'task_email';
57  $fieldCode = '<input type="text" class="form-control" name="tx_scheduler[email]" id="' . $fieldID . '" value="' . htmlspecialchars($taskInfo['email']) . '" size="30">';
58  $additionalFields = [];
59  $additionalFields[$fieldID] = [
60  'code' => $fieldCode,
61  'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.email',
62  'cshKey' => '_MOD_system_txschedulerM1',
63  'cshLabel' => $fieldID
64  ];
65  return $additionalFields;
66  }
67 
76  public function ‪validateAdditionalFields(array &$submittedData, ‪SchedulerModuleController $schedulerModule)
77  {
78  $submittedData['email'] = trim($submittedData['email']);
79  if (empty($submittedData['email'])) {
80  $this->‪addMessage(
81  ‪$GLOBALS['LANG']->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.noEmail'),
83  );
84  $result = false;
85  } else {
86  $result = true;
87  }
88  return $result;
89  }
90 
98  public function ‪saveAdditionalFields(array $submittedData, ‪AbstractTask $task)
99  {
100  $task->email = $submittedData['email'];
101  }
102 }
‪TYPO3\CMS\Scheduler\Task\Enumeration\Action\ADD
‪const ADD
Definition: Action.php:26
‪TYPO3\CMS\Scheduler\Example
Definition: SleepTask.php:2
‪TYPO3\CMS\Scheduler\Example\TestTaskAdditionalFieldProvider\validateAdditionalFields
‪bool validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule)
Definition: TestTaskAdditionalFieldProvider.php:76
‪TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider
Definition: AbstractAdditionalFieldProvider.php:26
‪TYPO3\CMS\Scheduler\Example\TestTaskAdditionalFieldProvider\saveAdditionalFields
‪saveAdditionalFields(array $submittedData, AbstractTask $task)
Definition: TestTaskAdditionalFieldProvider.php:98
‪TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider\addMessage
‪addMessage(string $message, int $severity=FlashMessage::OK)
Definition: AbstractAdditionalFieldProvider.php:33
‪TYPO3\CMS\Scheduler\Task\AbstractTask
Definition: AbstractTask.php:32
‪TYPO3\CMS\Scheduler\Controller\SchedulerModuleController
Definition: SchedulerModuleController.php:53
‪TYPO3\CMS\Scheduler\Example\TestTaskAdditionalFieldProvider
Definition: TestTaskAdditionalFieldProvider.php:28
‪TYPO3\CMS\Scheduler\Task\Enumeration\Action\EDIT
‪const EDIT
Definition: Action.php:28
‪TYPO3\CMS\Scheduler\Controller\SchedulerModuleController\getCurrentAction
‪Action getCurrentAction()
Definition: SchedulerModuleController.php:198
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:22
‪TYPO3\CMS\Scheduler\Task\Enumeration\Action
Definition: Action.php:24
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Scheduler\Example\TestTaskAdditionalFieldProvider\getAdditionalFields
‪array getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule)
Definition: TestTaskAdditionalFieldProvider.php:38
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:29