‪TYPO3CMS  ‪main
SystemStatusUpdateTaskNotificationEmailField.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 
25 
32 {
38  protected ‪$fields = ['notificationEmail', 'notificationAll'];
39 
45  protected ‪$fieldPrefix = 'SystemStatusUpdate';
46 
55  public function ‪getAdditionalFields(array &$taskInfo, $task, ‪SchedulerModuleController $schedulerModule)
56  {
57  $currentSchedulerModuleAction = $schedulerModule->‪getCurrentAction();
58 
59  if ($currentSchedulerModuleAction === SchedulerManagementAction::EDIT) {
60  $taskInfo[$this->fieldPrefix . 'NotificationEmail'] = $task->getNotificationEmail();
61  $taskInfo[$this->fieldPrefix . 'NotificationAll'] = $task->getNotificationAll();
62  }
63  // build html for additional email field
64  $fieldName = $this->‪getFullFieldName('notificationEmail');
65  $fieldId = 'task_' . $fieldName;
66  $fieldContent = $taskInfo[$fieldName] ?? '';
67  $fieldHtml = '<textarea class="form-control" rows="3" cols="50" name="tx_scheduler[' . $fieldName . ']"'
68  . ' id="' . $fieldId . '" >' . htmlspecialchars($fieldContent) . '</textarea>';
69 
70  $additionalFields = [];
71  $additionalFields[$fieldId] = [
72  'code' => $fieldHtml,
73  'label' => 'LLL:EXT:reports/Resources/Private/Language/locallang_reports.xlf:status_updateTaskField_notificationEmails',
74  'cshKey' => '',
75  'cshLabel' => $fieldId,
76  'type' => 'textarea',
77  ];
78 
79  // build html for additional mail all checkbox field
80  $fieldName = $this->‪getFullFieldName('notificationAll');
81  $fieldId = 'task_' . $fieldName;
82  $fieldChecked = (bool)($taskInfo[$fieldName] ?? false);
83  $fieldHtml = '<input type="checkbox" class="form-check-input" name="tx_scheduler[' . $fieldName . ']" id="'
84  . $fieldId . '" value="1"' . ($fieldChecked ? ' checked="checked"' : '') . '>';
85 
86  $additionalFields[$fieldId] = [
87  'code' => $fieldHtml,
88  'label' => 'LLL:EXT:reports/Resources/Private/Language/locallang_reports.xlf:status_updateTaskField_notificationAll',
89  'cshKey' => '',
90  'cshLabel' => $fieldId,
91  'type' => 'checkToggle',
92  ];
93 
94  return $additionalFields;
95  }
96 
104  public function ‪validateAdditionalFields(array &$submittedData, ‪SchedulerModuleController $schedulerModule)
105  {
106  $validInput = true;
107  $notificationEmails = ‪GeneralUtility::trimExplode(LF, $submittedData[$this->fieldPrefix . 'NotificationEmail'], true);
108  foreach ($notificationEmails as $notificationEmail) {
109  if (!GeneralUtility::validEmail($notificationEmail)) {
110  $validInput = false;
111  break;
112  }
113  }
114  if (!$validInput || empty($submittedData[$this->fieldPrefix . 'NotificationEmail'])) {
115  $this->‪addMessage($this->‪getLanguageService()->sL('LLL:EXT:reports/Resources/Private/Language/locallang_reports.xlf:status_updateTaskField_notificationEmails_invalid'), ContextualFeedbackSeverity::ERROR);
116  $validInput = false;
117  }
118  return $validInput;
119  }
120 
128  public function ‪saveAdditionalFields(array $submittedData, ‪AbstractTask $task)
129  {
130  if (!$task instanceof ‪SystemStatusUpdateTask) {
131  throw new \InvalidArgumentException('Expected a task of type ' . SystemStatusUpdateTask::class . ', but got ' . get_class($task), 1295012802);
132  }
133  $task->setNotificationEmail($submittedData[$this->fieldPrefix . 'NotificationEmail']);
134  $task->setNotificationAll(!empty($submittedData[$this->fieldPrefix . 'NotificationAll']));
135  }
136 
143  protected function ‪getFullFieldName($fieldName)
144  {
145  return $this->fieldPrefix . ucfirst($fieldName);
146  }
147 
148  protected function ‪getLanguageService(): ‪LanguageService
149  {
150  return ‪$GLOBALS['LANG'];
151  }
152 }
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask
Definition: SystemStatusUpdateTask.php:34
‪TYPO3\CMS\Scheduler\SchedulerManagementAction
‪SchedulerManagementAction
Definition: SchedulerManagementAction.php:25
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTaskNotificationEmailField\saveAdditionalFields
‪saveAdditionalFields(array $submittedData, AbstractTask $task)
Definition: SystemStatusUpdateTaskNotificationEmailField.php:126
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTaskNotificationEmailField\validateAdditionalFields
‪bool validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule)
Definition: SystemStatusUpdateTaskNotificationEmailField.php:102
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTaskNotificationEmailField\getAdditionalFields
‪array getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule)
Definition: SystemStatusUpdateTaskNotificationEmailField.php:53
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTaskNotificationEmailField\$fieldPrefix
‪string $fieldPrefix
Definition: SystemStatusUpdateTaskNotificationEmailField.php:43
‪TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider
Definition: AbstractAdditionalFieldProvider.php:29
‪TYPO3\CMS\Core\Type\ContextualFeedbackSeverity
‪ContextualFeedbackSeverity
Definition: ContextualFeedbackSeverity.php:25
‪TYPO3\CMS\Scheduler\Controller\SchedulerModuleController\getCurrentAction
‪getCurrentAction()
Definition: SchedulerModuleController.php:197
‪TYPO3\CMS\Scheduler\Task\AbstractTask
Definition: AbstractTask.php:33
‪TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider\addMessage
‪addMessage(string $message, ContextualFeedbackSeverity $severity=ContextualFeedbackSeverity::OK)
Definition: AbstractAdditionalFieldProvider.php:36
‪TYPO3\CMS\Scheduler\Controller\SchedulerModuleController
Definition: SchedulerModuleController.php:61
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTaskNotificationEmailField\getFullFieldName
‪string getFullFieldName($fieldName)
Definition: SystemStatusUpdateTaskNotificationEmailField.php:141
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTaskNotificationEmailField
Definition: SystemStatusUpdateTaskNotificationEmailField.php:32
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Reports\Task
Definition: SystemStatusUpdateTask.php:16
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTaskNotificationEmailField\getLanguageService
‪getLanguageService()
Definition: SystemStatusUpdateTaskNotificationEmailField.php:146
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTaskNotificationEmailField\$fields
‪array $fields
Definition: SystemStatusUpdateTaskNotificationEmailField.php:37
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static list< string > trimExplode(string $delim, string $string, bool $removeEmptyValues=false, int $limit=0)
Definition: GeneralUtility.php:822