TYPO3 CMS  TYPO3_7-6
CachingFrameworkGarbageCollectionAdditionalFieldProvider.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 {
31  public function getAdditionalFields(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
32  {
33  // Initialize selected fields
34  if (empty($taskInfo['scheduler_cachingFrameworkGarbageCollection_selectedBackends'])) {
35  $taskInfo['scheduler_cachingFrameworkGarbageCollection_selectedBackends'] = [];
36  if ($parentObject->CMD === 'add') {
37  // In case of new task, set to dbBackend if it's available
38  if (in_array(\TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend::class, $this->getRegisteredBackends())) {
39  $taskInfo['scheduler_cachingFrameworkGarbageCollection_selectedBackends'][] = \TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend::class;
40  }
41  } elseif ($parentObject->CMD === 'edit') {
42  // In case of editing the task, set to currently selected value
43  $taskInfo['scheduler_cachingFrameworkGarbageCollection_selectedBackends'] = $task->selectedBackends;
44  }
45  }
46  $fieldName = 'tx_scheduler[scheduler_cachingFrameworkGarbageCollection_selectedBackends][]';
47  $fieldId = 'task_cachingFrameworkGarbageCollection_selectedBackends';
48  $fieldOptions = $this->getCacheBackendOptions($taskInfo['scheduler_cachingFrameworkGarbageCollection_selectedBackends']);
49  $fieldHtml = '<select class="form-control" name="' . $fieldName . '" id="' . $fieldId . '" class="from-control" size="10" multiple="multiple">' . $fieldOptions . '</select>';
50  $additionalFields[$fieldId] = [
51  'code' => $fieldHtml,
52  'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.cachingFrameworkGarbageCollection.selectBackends',
53  'cshKey' => '_MOD_system_txschedulerM1',
54  'cshLabel' => $fieldId
55  ];
56  return $additionalFields;
57  }
58 
66  public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
67  {
68  $validData = true;
69  $availableBackends = $this->getRegisteredBackends();
70  if (is_array($submittedData['scheduler_cachingFrameworkGarbageCollection_selectedBackends'])) {
71  $invalidBackends = array_diff($submittedData['scheduler_cachingFrameworkGarbageCollection_selectedBackends'], $availableBackends);
72  if (!empty($invalidBackends)) {
73  $parentObject->addMessage($GLOBALS['LANG']->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.selectionOfNonExistingCacheBackends'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
74  $validData = false;
75  }
76  } else {
77  $parentObject->addMessage($GLOBALS['LANG']->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.noCacheBackendSelected'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
78  $validData = false;
79  }
80  return $validData;
81  }
82 
90  public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task)
91  {
92  $task->selectedBackends = $submittedData['scheduler_cachingFrameworkGarbageCollection_selectedBackends'];
93  }
94 
101  protected function getCacheBackendOptions(array $selectedBackends)
102  {
103  $options = [];
104  $availableBackends = $this->getRegisteredBackends();
105  foreach ($availableBackends as $backendName) {
106  if (in_array($backendName, $selectedBackends)) {
107  $selected = ' selected="selected"';
108  } else {
109  $selected = '';
110  }
111  $options[] = '<option value="' . $backendName . '"' . $selected . '>' . $backendName . '</option>';
112  }
113  return implode('', $options);
114  }
115 
121  protected function getRegisteredBackends()
122  {
123  $backends = [];
124  $cacheConfigurations = $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'];
125  if (is_array($cacheConfigurations)) {
126  foreach ($cacheConfigurations as $cacheConfiguration) {
127  $backend = $cacheConfiguration['backend'];
128  if (!in_array($backend, $backends)) {
129  $backends[] = $backend;
130  }
131  }
132  }
133  return $backends;
134  }
135 }
validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
getAdditionalFields(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']