buildConfiguration(); if (isset($configuration['modes'])) { $modeRegistry = GeneralUtility::makeInstance(ModeRegistry::class); foreach ($configuration['modes'] as $formatCode => $mode) { $modeInstance = GeneralUtility::makeInstance(Mode::class, $mode['module'])->setFormatCode($formatCode); if (!empty($mode['extensions']) && is_array($mode['extensions'])) { $modeInstance->bindToFileExtensions($mode['extensions']); } if (isset($mode['default']) && $mode['default'] === true) { $modeInstance->setAsDefault(); } $modeRegistry->register($modeInstance); } } $addonRegistry = GeneralUtility::makeInstance(AddonRegistry::class); if (isset($configuration['addons'])) { foreach ($configuration['addons'] as $identifier => $addon) { $addonInstance = GeneralUtility::makeInstance(Addon::class, $identifier, $addon['module'] ?? null, $addon['keymap'] ?? null); if (!empty($addon['cssFiles']) && is_array($addon['cssFiles'])) { $addonInstance->setCssFiles($addon['cssFiles']); } if (!empty($addon['options']) && is_array($addon['options'])) { $addonInstance->setOptions($addon['options']); } $addonRegistry->register($addonInstance); } } } /** * Compiles the configuration for code editor. Configuration is stored in caching framework. * * @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException * @throws \TYPO3\CMS\Core\Cache\Exception\InvalidDataException * @throws \InvalidArgumentException */ protected function buildConfiguration(): array { if ($this->configuration !== null) { return $this->configuration; } $this->configuration = [ 'modes' => [], 'addons' => [], ]; $cache = $this->getCache(); $packageManager = GeneralUtility::makeInstance(PackageManager::class); $cacheIdentifier = $this->generateCacheIdentifier($packageManager); $configurationFromCache = $cache->get($cacheIdentifier); if ($configurationFromCache !== false) { $this->configuration = $configurationFromCache; } else { $packages = $packageManager->getActivePackages(); foreach ($packages as $package) { $configurationPath = $package->getPackagePath() . 'Configuration/Backend/T3editor'; $modesFileNameForPackage = $configurationPath . '/Modes.php'; if (is_file($modesFileNameForPackage)) { $definedModes = require $modesFileNameForPackage; if (is_array($definedModes)) { $this->configuration['modes'] = array_merge($this->configuration['modes'], $definedModes); } } $addonsFileNameForPackage = $configurationPath . '/Addons.php'; if (is_file($addonsFileNameForPackage)) { $definedAddons = require $addonsFileNameForPackage; if (is_array($definedAddons)) { $this->configuration['addons'] = array_merge($this->configuration['addons'], $definedAddons); } } } $cache->set($cacheIdentifier, $this->configuration); } return $this->configuration; } protected function generateCacheIdentifier(PackageManager $packageManager): string { return (new PackageDependentCacheIdentifier($packageManager))->withPrefix('T3editorConfiguration')->toString(); } /** * @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException * @throws \InvalidArgumentException */ protected function getCache(): FrontendInterface { return GeneralUtility::makeInstance(CacheManager::class)->getCache('assets'); } }