‪TYPO3CMS  10.4
T3editor.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 
18 namespace ‪TYPO3\CMS\T3editor;
19 
24 use TYPO3\CMS\Core\Package\PackageManager;
29 
35 {
39  protected ‪$configuration;
40 
46  public function ‪registerConfiguration()
47  {
49 
50  if (isset(‪$configuration['modes'])) {
51  $modeRegistry = ‪ModeRegistry::getInstance();
52  foreach (‪$configuration['modes'] as $formatCode => $mode) {
53  $modeInstance = GeneralUtility::makeInstance(Mode::class, $mode['module'])->setFormatCode($formatCode);
54 
55  if (!empty($mode['extensions']) && is_array($mode['extensions'])) {
56  $modeInstance->bindToFileExtensions($mode['extensions']);
57  }
58 
59  if (isset($mode['default']) && $mode['default'] === true) {
60  $modeInstance->setAsDefault();
61  }
62 
63  $modeRegistry->register($modeInstance);
64  }
65  }
66 
67  $addonRegistry = GeneralUtility::makeInstance(AddonRegistry::class);
68  if (isset(‪$configuration['addons'])) {
69  foreach (‪$configuration['addons'] as $addon) {
70  $addonInstance = GeneralUtility::makeInstance(Addon::class, $addon['module']);
71 
72  if (!empty($addon['cssFiles']) && is_array($addon['cssFiles'])) {
73  $addonInstance->setCssFiles($addon['cssFiles']);
74  }
75 
76  if (!empty($addon['options']) && is_array($addon['options'])) {
77  $addonInstance->setOptions($addon['options']);
78  }
79 
80  if (!empty($addon['modes']) && is_array($addon['modes'])) {
81  $addonInstance->setModes($addon['modes']);
82  }
83 
84  $addonRegistry->register($addonInstance);
85  }
86  }
87  }
88 
97  protected function ‪buildConfiguration(): array
98  {
99  if ($this->configuration !== null) {
101  }
102 
103  $this->configuration = [
104  'modes' => [],
105  'addons' => [],
106  ];
107 
108  $cache = $this->‪getCache();
109  $cacheIdentifier = $this->‪generateCacheIdentifier('T3editorConfiguration');
110  $configurationFromCache = $cache->get($cacheIdentifier);
111  if ($configurationFromCache !== false) {
112  $this->configuration = $configurationFromCache;
113  } else {
114  $packageManager = GeneralUtility::makeInstance(PackageManager::class);
115  $packages = $packageManager->getActivePackages();
116 
117  foreach ($packages as $package) {
118  $configurationPath = $package->getPackagePath() . 'Configuration/Backend/T3editor';
119  $modesFileNameForPackage = $configurationPath . '/Modes.php';
120  if (is_file($modesFileNameForPackage)) {
121  $definedModes = require_once $modesFileNameForPackage;
122  if (is_array($definedModes)) {
123  $this->configuration['modes'] = array_merge($this->configuration['modes'], $definedModes);
124  }
125  }
126 
127  $addonsFileNameForPackage = $configurationPath . '/Addons.php';
128  if (is_file($addonsFileNameForPackage)) {
129  $definedAddons = require_once $addonsFileNameForPackage;
130  if (is_array($definedAddons)) {
131  $this->configuration['addons'] = array_merge($this->configuration['addons'], $definedAddons);
132  }
133  }
134  }
135  $cache->set($cacheIdentifier, $this->configuration);
136  }
137 
139  }
140 
145  protected function ‪generateCacheIdentifier(string $key): string
146  {
147  return $key . '_' . sha1((string)(new ‪Typo3Version()) . ‪Environment::getProjectPath() . $key);
148  }
149 
155  protected function ‪getCache(): ‪FrontendInterface
156  {
157  return GeneralUtility::makeInstance(CacheManager::class)->getCache('assets');
158  }
159 }
‪TYPO3\CMS\Core\Information\Typo3Version
Definition: Typo3Version.php:21
‪TYPO3\CMS\T3editor\Registry\AddonRegistry
Definition: AddonRegistry.php:29
‪TYPO3\CMS\T3editor
Definition: Addon.php:18
‪TYPO3\CMS\Core\Core\Environment\getProjectPath
‪static string getProjectPath()
Definition: Environment.php:169
‪TYPO3\CMS\T3editor\T3editor\buildConfiguration
‪array buildConfiguration()
Definition: T3editor.php:96
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:35
‪TYPO3\CMS\T3editor\T3editor
Definition: T3editor.php:35
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪TYPO3\CMS\T3editor\T3editor\generateCacheIdentifier
‪string generateCacheIdentifier(string $key)
Definition: T3editor.php:144
‪TYPO3\CMS\T3editor\T3editor\getCache
‪FrontendInterface getCache()
Definition: T3editor.php:154
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:23
‪TYPO3\CMS\T3editor\Registry\ModeRegistry
Definition: ModeRegistry.php:30
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:40
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\T3editor\T3editor\$configuration
‪array $configuration
Definition: T3editor.php:38
‪TYPO3\CMS\T3editor\Registry\ModeRegistry\getInstance
‪static self getInstance()
Definition: ModeRegistry.php:43
‪TYPO3\CMS\T3editor\T3editor\registerConfiguration
‪registerConfiguration()
Definition: T3editor.php:45