‪TYPO3CMS  10.4
ConfigurationService.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Http\Message\ServerRequestInterface;
27 
34 {
38  protected ‪$mainConfiguration;
39 
40  public function ‪__construct()
41  {
42  $this->mainConfiguration = $this->‪getBackendUser()->‪getTSConfig()['admPanel.'] ?? [];
43  }
44 
50  public function ‪getMainConfiguration(): array
51  {
53  }
54 
63  public function ‪getConfigurationOption(string $identifier, string $option): string
64  {
65  if ($identifier === '' || $option === '') {
66  throw new \InvalidArgumentException('Identifier and option may not be empty', 1532861423);
67  }
68 
69  if (isset($this->mainConfiguration['override.'][$identifier . '.'][$option])) {
70  $returnValue = $this->mainConfiguration['override.'][$identifier . '.'][$option];
71  } else {
72  $returnValue = $this->‪getBackendUser()->uc['AdminPanel'][$identifier . '_' . $option] ?? '';
73  }
74 
75  return (string)$returnValue;
76  }
77 
86  public function ‪saveConfiguration(array $modules, ServerRequestInterface $request): void
87  {
88  $configurationToSave = $request->getParsedBody()['TSFE_ADMIN_PANEL'] ?? [];
89  $beUser = $this->‪getBackendUser();
90  $this->‪triggerOnSubmitActors($modules, $request, $configurationToSave);
91 
92  $existingConfiguration = $beUser->uc['AdminPanel'] ?? [];
93  $existingConfiguration = is_array($existingConfiguration) ? $existingConfiguration : [];
94 
95  // Settings
96  $beUser->uc['AdminPanel'] = array_merge($existingConfiguration, $configurationToSave);
97  unset($beUser->uc['AdminPanel']['action']);
98  // Saving
99  $beUser->writeUC();
100  }
101 
107  protected function ‪getBackendUser(): BackendUserAuthentication
108  {
109  return ‪$GLOBALS['BE_USER'];
110  }
111 
117  protected function ‪triggerOnSubmitActors(
118  array $modules,
119  ServerRequestInterface $request,
120  $configurationToSave
121  ): void {
122  foreach ($modules as $module) {
123  if (
124  $module instanceof OnSubmitActorInterface
125  && (
126  ($module instanceof ConfigurableInterface && $module->isEnabled())
127  || !($module instanceof ConfigurableInterface)
128  )
129  ) {
130  $module->onSubmit($configurationToSave, $request);
131  }
132  if ($module instanceof SubmoduleProviderInterface) {
133  $this->‪triggerOnSubmitActors($module->getSubModules(), $request, $configurationToSave);
134  }
135  }
136  }
137 }
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication
Definition: FrontendBackendUserAuthentication.php:31
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\getTSConfig
‪array getTSConfig()
Definition: BackendUserAuthentication.php:1217
‪TYPO3\CMS\Adminpanel\Service\ConfigurationService\getMainConfiguration
‪array getMainConfiguration()
Definition: ConfigurationService.php:49
‪TYPO3\CMS\Adminpanel\ModuleApi\ConfigurableInterface
Definition: ConfigurableInterface.php:29
‪TYPO3\CMS\Adminpanel\Service\ConfigurationService\__construct
‪__construct()
Definition: ConfigurationService.php:39
‪TYPO3\CMS\Adminpanel\Service\ConfigurationService\triggerOnSubmitActors
‪triggerOnSubmitActors(array $modules, ServerRequestInterface $request, $configurationToSave)
Definition: ConfigurationService.php:116
‪TYPO3\CMS\Adminpanel\Service\ConfigurationService\getBackendUser
‪BackendUserAuthentication FrontendBackendUserAuthentication getBackendUser()
Definition: ConfigurationService.php:106
‪TYPO3\CMS\Adminpanel\ModuleApi\ConfigurableInterface\isEnabled
‪bool isEnabled()
‪TYPO3\CMS\Adminpanel\Service\ConfigurationService
Definition: ConfigurationService.php:34
‪TYPO3\CMS\Adminpanel\Service\ConfigurationService\getConfigurationOption
‪string getConfigurationOption(string $identifier, string $option)
Definition: ConfigurationService.php:62
‪TYPO3\CMS\Adminpanel\Service
Definition: ConfigurationService.php:18
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Adminpanel\Service\ConfigurationService\saveConfiguration
‪saveConfiguration(array $modules, ServerRequestInterface $request)
Definition: ConfigurationService.php:85
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:23
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Adminpanel\ModuleApi\OnSubmitActorInterface
Definition: OnSubmitActorInterface.php:27
‪TYPO3\CMS\Adminpanel\ModuleApi\SubmoduleProviderInterface
Definition: SubmoduleProviderInterface.php:30
‪TYPO3\CMS\Adminpanel\Service\ConfigurationService\$mainConfiguration
‪array $mainConfiguration
Definition: ConfigurationService.php:37