‪TYPO3CMS  9.5
T3editor.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 namespace ‪TYPO3\CMS\T3editor;
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 use TYPO3\CMS\Core\Package\PackageManager;
26 
32 {
36  protected ‪$configuration;
37 
43  public function ‪registerConfiguration()
44  {
46 
47  if (isset(‪$configuration['modes'])) {
48  $modeRegistry = ‪ModeRegistry::getInstance();
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 $addon) {
67  $addonInstance = GeneralUtility::makeInstance(Addon::class, $addon['module']);
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  if (!empty($addon['modes']) && is_array($addon['modes'])) {
78  $addonInstance->setModes($addon['modes']);
79  }
80 
81  $addonRegistry->register($addonInstance);
82  }
83  }
84  }
85 
94  protected function ‪buildConfiguration(): array
95  {
96  if ($this->configuration !== null) {
98  }
99 
100  $this->configuration = [
101  'modes' => [],
102  'addons' => [],
103  ];
104 
105  $cache = $this->‪getCache();
106  $cacheIdentifier = $this->‪generateCacheIdentifier('T3editorConfiguration');
107  $configurationFromCache = $cache->get($cacheIdentifier);
108  if ($configurationFromCache !== false) {
109  $this->configuration = $configurationFromCache;
110  } else {
111  $packageManager = GeneralUtility::makeInstance(PackageManager::class);
112  $packages = $packageManager->getActivePackages();
113 
114  foreach ($packages as $package) {
115  $configurationPath = $package->getPackagePath() . 'Configuration/Backend/T3editor';
116  $modesFileNameForPackage = $configurationPath . '/Modes.php';
117  if (is_file($modesFileNameForPackage)) {
118  $definedModes = require_once $modesFileNameForPackage;
119  if (is_array($definedModes)) {
120  $this->configuration['modes'] = array_merge($this->configuration['modes'], $definedModes);
121  }
122  }
123 
124  $addonsFileNameForPackage = $configurationPath . '/Addons.php';
125  if (is_file($addonsFileNameForPackage)) {
126  $definedAddons = require_once $addonsFileNameForPackage;
127  if (is_array($definedAddons)) {
128  $this->configuration['addons'] = array_merge($this->configuration['addons'], $definedAddons);
129  }
130  }
131  }
132  $cache->set($cacheIdentifier, $this->configuration);
133  }
134 
136  }
137 
142  protected function ‪generateCacheIdentifier(string $key): string
143  {
144  return $key . '_' . sha1(TYPO3_version . ‪Environment::getProjectPath() . $key);
145  }
146 
152  protected function ‪getCache(): ‪FrontendInterface
153  {
154  return GeneralUtility::makeInstance(CacheManager::class)->getCache('assets');
155  }
156 }
‪TYPO3\CMS\T3editor\Registry\AddonRegistry
Definition: AddonRegistry.php:27
‪TYPO3\CMS\T3editor
Definition: Addon.php:3
‪TYPO3\CMS\Core\Core\Environment\getProjectPath
‪static string getProjectPath()
Definition: Environment.php:142
‪TYPO3\CMS\T3editor\T3editor\buildConfiguration
‪array buildConfiguration()
Definition: T3editor.php:93
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:34
‪TYPO3\CMS\T3editor\T3editor
Definition: T3editor.php:32
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:21
‪TYPO3\CMS\T3editor\T3editor\generateCacheIdentifier
‪string generateCacheIdentifier(string $key)
Definition: T3editor.php:141
‪TYPO3\CMS\T3editor\T3editor\getCache
‪FrontendInterface getCache()
Definition: T3editor.php:151
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪TYPO3\CMS\T3editor\Registry\ModeRegistry
Definition: ModeRegistry.php:28
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:39
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\T3editor\T3editor\$configuration
‪array $configuration
Definition: T3editor.php:35
‪TYPO3\CMS\T3editor\Registry\ModeRegistry\getInstance
‪static self getInstance()
Definition: ModeRegistry.php:41
‪TYPO3\CMS\T3editor\T3editor\registerConfiguration
‪registerConfiguration()
Definition: T3editor.php:42