Translated using Weblate (Slovenian)
[phpmyadmin.git] / src / Controllers / ThemeSetController.php
blob87eef4870b7f7f698dc63658419f92d812a0e778
1 <?php
3 declare(strict_types=1);
5 namespace PhpMyAdmin\Controllers;
7 use PhpMyAdmin\Config;
8 use PhpMyAdmin\Http\ServerRequest;
9 use PhpMyAdmin\ResponseRenderer;
10 use PhpMyAdmin\Template;
11 use PhpMyAdmin\Theme\ThemeManager;
12 use PhpMyAdmin\Url;
13 use PhpMyAdmin\UserPreferences;
15 use function is_string;
17 final class ThemeSetController extends AbstractController
19 public function __construct(
20 ResponseRenderer $response,
21 Template $template,
22 private ThemeManager $themeManager,
23 private UserPreferences $userPreferences,
24 ) {
25 parent::__construct($response, $template);
28 public function __invoke(ServerRequest $request): void
30 $theme = $request->getParsedBodyParam('set_theme');
31 if (! Config::getInstance()->settings['ThemeManager'] || ! is_string($theme) || $theme === '') {
32 if ($request->isAjax()) {
33 $this->response->addJSON('themeColorMode', '');
35 return;
38 $this->response->redirect('index.php?route=/' . Url::getCommonRaw([], '&'));
40 return;
43 $this->themeManager->setActiveTheme($theme);
45 /** @var mixed $themeColorMode */
46 $themeColorMode = $request->getParsedBodyParam('themeColorMode');
47 if (is_string($themeColorMode) && $themeColorMode !== '') {
48 $this->themeManager->theme->setColorMode($themeColorMode);
51 $this->themeManager->setThemeCookie();
53 $preferences = $this->userPreferences->load();
54 $preferences['config_data']['ThemeDefault'] = $theme;
55 $this->userPreferences->save($preferences['config_data']);
57 if ($request->isAjax()) {
58 $this->response->addJSON('themeColorMode', $this->themeManager->theme->getColorMode());
60 return;
63 $this->response->redirect('index.php?route=/' . Url::getCommonRaw([], '&'));