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