‪TYPO3CMS  10.4
CleanerFieldProvider.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 
30 {
39  public function ‪getAdditionalFields(array &$taskInfo, $task, ‪SchedulerModuleController $schedulerModule)
40  {
41  $currentSchedulerModuleAction = $schedulerModule->‪getCurrentAction();
42 
43  if ($currentSchedulerModuleAction->equals(‪Action::EDIT)) {
44  $taskInfo['RecyclerCleanerTCA'] = $task->getTcaTables();
45  $taskInfo['RecyclerCleanerPeriod'] = $task->getPeriod();
46  }
47 
48  $additionalFields = [];
49  $additionalFields['period'] = [
50  'code' => '<input type="text" class="form-control" name="tx_scheduler[RecyclerCleanerPeriod]" value="' . $taskInfo['RecyclerCleanerPeriod'] . '">',
51  'label' => 'LLL:EXT:recycler/Resources/Private/Language/locallang_tasks.xlf:cleanerTaskPeriod',
52  'cshKey' => '',
53  'cshLabel' => 'task_recyclerCleaner_selectedPeriod'
54  ];
55 
56  $additionalFields['tca'] = [
57  'code' => $this->‪getTcaSelectHtml($taskInfo['RecyclerCleanerTCA']),
58  'label' => 'LLL:EXT:recycler/Resources/Private/Language/locallang_tasks.xlf:cleanerTaskTCA',
59  'cshKey' => '',
60  'cshLabel' => 'task_recyclerCleaner_selectedTables'
61  ];
62 
63  return $additionalFields;
64  }
65 
72  protected function ‪getTcaSelectHtml($selectedTables = [])
73  {
74  if (!is_array($selectedTables)) {
75  $selectedTables = [];
76  }
77  $tcaSelectHtml = '<select name="tx_scheduler[RecyclerCleanerTCA][]" multiple="multiple" class="form-control" size="10">';
78 
79  $options = [];
80  foreach (‪$GLOBALS['TCA'] as $table => $tableConf) {
81  if (!empty($tableConf['ctrl']['delete'])) {
82  $selected = in_array($table, $selectedTables, true) ? ' selected="selected"' : '';
83  $tableTitle = $this->‪getLanguageService()->sL($tableConf['ctrl']['title']);
84  $options[$tableTitle . ' ' . $table] = '<option' . $selected . ' value="' . $table . '">' . htmlspecialchars($tableTitle . ' (' . $table . ')') . '</option>';
85  }
86  }
87  ksort($options);
88 
89  $tcaSelectHtml .= implode('', $options);
90  $tcaSelectHtml .= '</select>';
91 
92  return $tcaSelectHtml;
93  }
94 
102  public function ‪validateAdditionalFields(array &$submittedData, ‪SchedulerModuleController $schedulerModule)
103  {
104  $validPeriod = $this->‪validateAdditionalFieldPeriod($submittedData['RecyclerCleanerPeriod']);
105  $validTca = $this->‪validateAdditionalFieldTca($submittedData['RecyclerCleanerTCA']);
106 
107  return $validPeriod && $validTca;
108  }
109 
117  {
118  return $this->‪checkTcaIsNotEmpty(‪$tca) && $this->‪checkTcaIsValid(‪$tca);
119  }
120 
127  protected function ‪checkTcaIsNotEmpty(‪$tca)
128  {
129  if (is_array(‪$tca) && !empty(‪$tca)) {
130  $validTca = true;
131  } else {
132  $this->‪addMessage(
133  $this->‪getLanguageService()->sL('LLL:EXT:recycler/Resources/Private/Language/locallang_tasks.xlf:cleanerTaskErrorTCAempty'),
135  );
136  $validTca = false;
137  }
138 
139  return $validTca;
140  }
141 
148  protected function ‪checkTcaIsValid(array ‪$tca)
149  {
150  $checkTca = false;
151  foreach (‪$tca as $tcaTable) {
152  if (!isset(‪$GLOBALS['TCA'][$tcaTable])) {
153  $checkTca = false;
154  $this->‪addMessage(
155  sprintf($this->‪getLanguageService()->sL('LLL:EXT:recycler/Resources/Private/Language/locallang_tasks.xlf:cleanerTaskErrorTCANotSet'), $tcaTable),
157  );
158  break;
159  }
160  $checkTca = true;
161  }
162 
163  return $checkTca;
164  }
165 
172  protected function ‪validateAdditionalFieldPeriod($period)
173  {
174  if (!empty($period) && filter_var($period, FILTER_VALIDATE_INT) !== false) {
175  $validPeriod = true;
176  } else {
177  $this->‪addMessage(
178  $this->‪getLanguageService()->sL('LLL:EXT:recycler/Resources/Private/Language/locallang_tasks.xlf:cleanerTaskErrorPeriod'),
180  );
181  $validPeriod = false;
182  }
183 
184  return $validPeriod;
185  }
186 
194  public function ‪saveAdditionalFields(array $submittedData, ‪AbstractTask $task)
195  {
196  if (!$task instanceof ‪CleanerTask) {
197  throw new \InvalidArgumentException(
198  'Expected a task of type ' . CleanerTask::class . ', but got ' . get_class($task),
199  1329219449
200  );
201  }
202 
203  $task->setTcaTables($submittedData['RecyclerCleanerTCA']);
204  $task->setPeriod($submittedData['RecyclerCleanerPeriod']);
205  }
206 
210  protected function ‪getLanguageService()
211  {
212  return ‪$GLOBALS['LANG'];
213  }
214 }
‪TYPO3\CMS\Recycler\Task\CleanerFieldProvider
Definition: CleanerFieldProvider.php:30
‪TYPO3\CMS\Recycler\Task\CleanerFieldProvider\validateAdditionalFieldPeriod
‪bool validateAdditionalFieldPeriod($period)
Definition: CleanerFieldProvider.php:172
‪TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider
Definition: AbstractAdditionalFieldProvider.php:28
‪TYPO3\CMS\Recycler\Task\CleanerFieldProvider\validateAdditionalFieldTca
‪bool validateAdditionalFieldTca($tca)
Definition: CleanerFieldProvider.php:116
‪TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider\addMessage
‪addMessage(string $message, int $severity=FlashMessage::OK)
Definition: AbstractAdditionalFieldProvider.php:35
‪TYPO3\CMS\Recycler\Task\CleanerFieldProvider\checkTcaIsValid
‪bool checkTcaIsValid(array $tca)
Definition: CleanerFieldProvider.php:148
‪TYPO3\CMS\Scheduler\Task\AbstractTask
Definition: AbstractTask.php:35
‪TYPO3\CMS\Recycler\Task\CleanerTask
Definition: CleanerTask.php:29
‪TYPO3\CMS\Scheduler\Controller\SchedulerModuleController
Definition: SchedulerModuleController.php:56
‪TYPO3\CMS\Recycler\Task\CleanerFieldProvider\getAdditionalFields
‪array getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule)
Definition: CleanerFieldProvider.php:39
‪TYPO3\CMS\Scheduler\Task\Enumeration\Action\EDIT
‪const EDIT
Definition: Action.php:30
‪TYPO3\CMS\Recycler\Task\CleanerFieldProvider\validateAdditionalFields
‪bool validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule)
Definition: CleanerFieldProvider.php:102
‪TYPO3\CMS\Scheduler\Controller\SchedulerModuleController\getCurrentAction
‪Action getCurrentAction()
Definition: SchedulerModuleController.php:181
‪TYPO3\CMS\Recycler\Task\CleanerFieldProvider\getLanguageService
‪TYPO3 CMS Core Localization LanguageService getLanguageService()
Definition: CleanerFieldProvider.php:210
‪TYPO3\CMS\Recycler\Task
Definition: CleanerFieldProvider.php:16
‪TYPO3\CMS\Recycler\Task\CleanerFieldProvider\getTcaSelectHtml
‪string getTcaSelectHtml($selectedTables=[])
Definition: CleanerFieldProvider.php:72
‪TYPO3\CMS\Recycler\Task\CleanerFieldProvider\checkTcaIsNotEmpty
‪bool checkTcaIsNotEmpty($tca)
Definition: CleanerFieldProvider.php:127
‪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
‪$tca
‪$tca
Definition: sys_file_metadata.php:5
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:31
‪TYPO3\CMS\Recycler\Task\CleanerFieldProvider\saveAdditionalFields
‪saveAdditionalFields(array $submittedData, AbstractTask $task)
Definition: CleanerFieldProvider.php:194