‪TYPO3CMS  ‪main
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 
23 use TYPO3\CMS\Core\Package\PackageManager;
28 
35 {
39  protected ‪$configuration;
40 
46  public function ‪registerConfiguration()
47  {
49 
50  if (isset(‪$configuration['modes'])) {
51  $modeRegistry = GeneralUtility::makeInstance(ModeRegistry::class);
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 ‪$identifier => $addon) {
70  $addonInstance = GeneralUtility::makeInstance(Addon::class, ‪$identifier, $addon['module'] ?? null, $addon['keymap'] ?? null);
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  $addonRegistry->register($addonInstance);
81  }
82  }
83  }
84 
92  protected function ‪buildConfiguration(): array
93  {
94  if ($this->configuration !== null) {
96  }
97 
98  $this->configuration = [
99  'modes' => [],
100  'addons' => [],
101  ];
102 
103  $cache = $this->‪getCache();
104  $packageManager = GeneralUtility::makeInstance(PackageManager::class);
105  $cacheIdentifier = $this->‪generateCacheIdentifier($packageManager);
106  $configurationFromCache = $cache->get($cacheIdentifier);
107  if ($configurationFromCache !== false) {
108  $this->configuration = $configurationFromCache;
109  } else {
110  $packages = $packageManager->getActivePackages();
111 
112  foreach ($packages as $package) {
113  $configurationPath = $package->getPackagePath() . 'Configuration/Backend/T3editor';
114  $modesFileNameForPackage = $configurationPath . '/Modes.php';
115  if (is_file($modesFileNameForPackage)) {
116  $definedModes = require_once $modesFileNameForPackage;
117  if (is_array($definedModes)) {
118  $this->configuration['modes'] = array_merge($this->configuration['modes'], $definedModes);
119  }
120  }
121 
122  $addonsFileNameForPackage = $configurationPath . '/Addons.php';
123  if (is_file($addonsFileNameForPackage)) {
124  $definedAddons = require_once $addonsFileNameForPackage;
125  if (is_array($definedAddons)) {
126  $this->configuration['addons'] = array_merge($this->configuration['addons'], $definedAddons);
127  }
128  }
129  }
130  $cache->set($cacheIdentifier, $this->configuration);
131  }
132 
134  }
135 
136  protected function ‪generateCacheIdentifier(PackageManager $packageManager): string
137  {
138  return (new ‪PackageDependentCacheIdentifier($packageManager))->withPrefix('T3editorConfiguration')->toString();
139  }
140 
145  protected function ‪getCache(): ‪FrontendInterface
146  {
147  return GeneralUtility::makeInstance(CacheManager::class)->getCache('assets');
148  }
149 }
‪TYPO3\CMS\T3editor\Registry\AddonRegistry
Definition: AddonRegistry.php:28
‪TYPO3\CMS\T3editor
Definition: Addon.php:18
‪TYPO3\CMS\Core\Package\Cache\PackageDependentCacheIdentifier
Definition: PackageDependentCacheIdentifier.php:30
‪TYPO3\CMS\T3editor\T3editor\buildConfiguration
‪buildConfiguration()
Definition: T3editor.php:91
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:36
‪TYPO3\CMS\T3editor\T3editor
Definition: T3editor.php:35
‪TYPO3\CMS\T3editor\T3editor\getCache
‪getCache()
Definition: T3editor.php:144
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪TYPO3\CMS\T3editor\Registry\ModeRegistry
Definition: ModeRegistry.php:29
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51
‪TYPO3\CMS\T3editor\T3editor\$configuration
‪array $configuration
Definition: T3editor.php:38
‪TYPO3\CMS\T3editor\T3editor\registerConfiguration
‪registerConfiguration()
Definition: T3editor.php:45
‪TYPO3\CMS\Webhooks\Message\$identifier
‪identifier readonly string $identifier
Definition: FileAddedMessage.php:37
‪TYPO3\CMS\T3editor\T3editor\generateCacheIdentifier
‪generateCacheIdentifier(PackageManager $packageManager)
Definition: T3editor.php:135