‪TYPO3CMS  ‪main
CodeEditor.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 
25 use TYPO3\CMS\Core\Package\PackageManager;
28 
35 {
36  protected ?array ‪$configuration = null;
37 
43  public function ‪registerConfiguration(): void
44  {
46 
47  if (isset(‪$configuration['modes'])) {
48  $modeRegistry = GeneralUtility::makeInstance(ModeRegistry::class);
49  foreach (‪$configuration['modes'] as $formatCode => $mode) {
50  $modeInstance = GeneralUtility::makeInstance(Mode::class, $mode['module'])->setFormatCode($formatCode);
51 
52  if (!empty($mode['extensions']) && is_array($mode['extensions'])) {
53  $modeInstance->bindToFileExtensions($mode['extensions']);
54  }
55 
56  if (isset($mode['default']) && $mode['default'] === true) {
57  $modeInstance->setAsDefault();
58  }
59 
60  $modeRegistry->register($modeInstance);
61  }
62  }
63 
64  $addonRegistry = GeneralUtility::makeInstance(AddonRegistry::class);
65  if (isset(‪$configuration['addons'])) {
66  foreach (‪$configuration['addons'] as ‪$identifier => $addon) {
67  $addonInstance = GeneralUtility::makeInstance(Addon::class, ‪$identifier, $addon['module'] ?? null, $addon['keymap'] ?? null);
68 
69  if (!empty($addon['cssFiles']) && is_array($addon['cssFiles'])) {
70  $addonInstance->setCssFiles($addon['cssFiles']);
71  }
72 
73  if (!empty($addon['options']) && is_array($addon['options'])) {
74  $addonInstance->setOptions($addon['options']);
75  }
76 
77  $addonRegistry->register($addonInstance);
78  }
79  }
80  }
81 
89  protected function ‪buildConfiguration(): array
90  {
91  if ($this->configuration !== null) {
93  }
94 
95  $this->configuration = [
96  'modes' => [],
97  'addons' => [],
98  ];
99 
100  $cache = $this->‪getCache();
101  $packageManager = GeneralUtility::makeInstance(PackageManager::class);
102  $cacheIdentifier = $this->‪generateCacheIdentifier($packageManager);
103  $configurationFromCache = $cache->get($cacheIdentifier);
104  if ($configurationFromCache !== false) {
105  $this->configuration = $configurationFromCache;
106  } else {
107  $packages = $packageManager->getActivePackages();
108 
109  foreach ($packages as $package) {
110  $configurationPath = $package->getPackagePath() . 'Configuration/Backend/T3editor';
111  $modesFileNameForPackage = $configurationPath . '/Modes.php';
112  if (is_file($modesFileNameForPackage)) {
113  $definedModes = require $modesFileNameForPackage;
114  if (is_array($definedModes)) {
115  $this->configuration['modes'] = array_merge($this->configuration['modes'], $definedModes);
116  }
117  }
118 
119  $addonsFileNameForPackage = $configurationPath . '/Addons.php';
120  if (is_file($addonsFileNameForPackage)) {
121  $definedAddons = require $addonsFileNameForPackage;
122  if (is_array($definedAddons)) {
123  $this->configuration['addons'] = array_merge($this->configuration['addons'], $definedAddons);
124  }
125  }
126  }
127  $cache->set($cacheIdentifier, $this->configuration);
128  }
129 
131  }
132 
133  protected function ‪generateCacheIdentifier(PackageManager $packageManager): string
134  {
135  return (new ‪PackageDependentCacheIdentifier($packageManager))->withPrefix('T3editorConfiguration')->toString();
136  }
137 
142  protected function ‪getCache(): ‪FrontendInterface
143  {
144  return GeneralUtility::makeInstance(CacheManager::class)->getCache('assets');
145  }
146 }
‪TYPO3\CMS\Backend\CodeEditor\Registry\AddonRegistry
Definition: AddonRegistry.php:28
‪TYPO3\CMS\Backend\CodeEditor\CodeEditor\generateCacheIdentifier
‪generateCacheIdentifier(PackageManager $packageManager)
Definition: CodeEditor.php:133
‪TYPO3\CMS\Backend\CodeEditor\CodeEditor\buildConfiguration
‪buildConfiguration()
Definition: CodeEditor.php:89
‪TYPO3\CMS\Backend\CodeEditor\CodeEditor\registerConfiguration
‪registerConfiguration()
Definition: CodeEditor.php:43
‪TYPO3\CMS\Core\Package\Cache\PackageDependentCacheIdentifier
Definition: PackageDependentCacheIdentifier.php:30
‪TYPO3\CMS\Backend\CodeEditor
Definition: Addon.php:18
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:36
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪TYPO3\CMS\Backend\CodeEditor\CodeEditor\$configuration
‪array $configuration
Definition: CodeEditor.php:36
‪TYPO3\CMS\Backend\CodeEditor\CodeEditor\getCache
‪getCache()
Definition: CodeEditor.php:142
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪TYPO3\CMS\Backend\CodeEditor\Registry\ModeRegistry
Definition: ModeRegistry.php:29
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Webhooks\Message\$identifier
‪identifier readonly string $identifier
Definition: FileAddedMessage.php:37
‪TYPO3\CMS\Backend\CodeEditor\CodeEditor
Definition: CodeEditor.php:35