‪TYPO3CMS  9.5
BackendUserConfiguration.php
Go to the documentation of this file.
1 <?php
2 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 
21 
28 {
32  protected ‪$backendUser;
33 
38  {
39  $this->backendUser = ‪$backendUser ?: ‪$GLOBALS['BE_USER'];
40  }
41 
48  public function get(string $key)
49  {
50  return (strpos($key, '.') !== false) ? $this->‪getFromDottedNotation($key) : $this->backendUser->uc[$key];
51  }
52 
58  public function ‪getAll()
59  {
60  return $this->backendUser->uc;
61  }
62 
69  public function set(string $key, $value): void
70  {
71  if (strpos($key, '.') !== false) {
72  $this->‪setFromDottedNotation($key, $value);
73  } else {
74  $this->backendUser->uc[$key] = $value;
75  }
76 
77  $this->backendUser->writeUC($this->backendUser->uc);
78  }
79 
87  public function ‪addToList(string $key, $value): void
88  {
89  $list = $this->get($key);
90 
91  if (!isset($list)) {
92  $list = $value;
93  } elseif (!GeneralUtility::inList($list, $value)) {
94  $list .= ',' . $value;
95  }
96 
97  $this->set($key, $list);
98  }
99 
107  public function ‪removeFromList(string $key, $value): void
108  {
109  $list = $this->get($key);
110 
111  if (GeneralUtility::inList($list, $value)) {
112  $list = GeneralUtility::trimExplode(',', $list, true);
113  $list = ‪ArrayUtility::removeArrayEntryByValue($list, $value);
114  $this->set($key, implode(',', $list));
115  }
116  }
117 
121  public function ‪clear(): void
122  {
123  $this->backendUser->resetUC();
124  }
125 
131  public function ‪unsetOption(string $key): void
132  {
133  if (isset($this->backendUser->uc[$key])) {
134  unset($this->backendUser->uc[$key]);
135  $this->backendUser->writeUC($this->backendUser->uc);
136  }
137  }
138 
145  protected function ‪getFromDottedNotation(string $key)
146  {
147  $subkeys = GeneralUtility::trimExplode('.', $key);
148  $configuration = $this->backendUser->uc;
149 
150  foreach ($subkeys as $subkey) {
151  if (isset($configuration[$subkey])) {
152  $configuration = &$configuration[$subkey];
153  } else {
154  $configuration = [];
155  break;
156  }
157  }
158 
159  return $configuration;
160  }
161 
168  protected function ‪setFromDottedNotation(string $key, $value): void
169  {
170  $subkeys = GeneralUtility::trimExplode('.', $key, true);
171  $lastKey = $subkeys[count($subkeys) - 1];
172  $configuration = &$this->backendUser->uc;
173 
174  foreach ($subkeys as $subkey) {
175  if ($subkey === $lastKey) {
176  $configuration[$subkey] = $value;
177  } else {
178  $configuration = &$configuration[$subkey];
179  }
180  }
181  }
182 }
‪TYPO3\CMS\Backend\Configuration\BackendUserConfiguration\__construct
‪__construct(BackendUserAuthentication $backendUser=null)
Definition: BackendUserConfiguration.php:36
‪TYPO3\CMS\Backend\Configuration\BackendUserConfiguration\getFromDottedNotation
‪mixed getFromDottedNotation(string $key)
Definition: BackendUserConfiguration.php:144
‪TYPO3\CMS\Backend\Configuration\BackendUserConfiguration\setFromDottedNotation
‪setFromDottedNotation(string $key, $value)
Definition: BackendUserConfiguration.php:167
‪TYPO3\CMS\Backend\Configuration\BackendUserConfiguration
Definition: BackendUserConfiguration.php:28
‪TYPO3\CMS\Backend\Configuration\BackendUserConfiguration\clear
‪clear()
Definition: BackendUserConfiguration.php:120
‪TYPO3\CMS\Core\Utility\ArrayUtility\removeArrayEntryByValue
‪static array removeArrayEntryByValue(array $array, $cmpValue)
Definition: ArrayUtility.php:643
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:45
‪TYPO3\CMS\Backend\Configuration\BackendUserConfiguration\removeFromList
‪removeFromList(string $key, $value)
Definition: BackendUserConfiguration.php:106
‪TYPO3\CMS\Backend\Configuration
Definition: BackendUserConfiguration.php:3
‪TYPO3\CMS\Backend\Configuration\BackendUserConfiguration\getAll
‪mixed getAll()
Definition: BackendUserConfiguration.php:57
‪TYPO3\CMS\Backend\Configuration\BackendUserConfiguration\unsetOption
‪unsetOption(string $key)
Definition: BackendUserConfiguration.php:130
‪TYPO3\CMS\Backend\Configuration\BackendUserConfiguration\addToList
‪addToList(string $key, $value)
Definition: BackendUserConfiguration.php:86
‪TYPO3\CMS\Backend\Configuration\BackendUserConfiguration\$backendUser
‪BackendUserAuthentication $backendUser
Definition: BackendUserConfiguration.php:31
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:23
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45