From 66982e43ea20b77304c9d216195e8efac7b0b1d1 Mon Sep 17 00:00:00 2001 From: Stefan Hagspiel Date: Thu, 15 Aug 2024 19:03:30 +0200 Subject: [PATCH] ignore disabled area bricks in autoload watcher pass (#229) --- UPGRADE.md | 3 +++ .../Compiler/AreaBrickAutoloadWatcherPass.php | 6 ++++++ src/DependencyInjection/ToolboxExtension.php | 5 +++++ src/Manager/ConfigManager.php | 7 +++++-- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 43a76a40..d1b45c26 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,8 @@ # Upgrade Notes +## 5.2.2 +- [ENHANCEMENT] Ignore disabled area bricks in autoload watcher pass + ## 5.2.1 - [BUGFIX] Fix column hash selector diff --git a/src/DependencyInjection/Compiler/AreaBrickAutoloadWatcherPass.php b/src/DependencyInjection/Compiler/AreaBrickAutoloadWatcherPass.php index cf4c57f6..00a898a3 100644 --- a/src/DependencyInjection/Compiler/AreaBrickAutoloadWatcherPass.php +++ b/src/DependencyInjection/Compiler/AreaBrickAutoloadWatcherPass.php @@ -12,6 +12,7 @@ final class AreaBrickAutoloadWatcherPass implements CompilerPassInterface { public function process(ContainerBuilder $container): void { + $disabledAreaBricks = $container->getParameter('toolbox.area_brick.disabled_bricks'); $config = $container->getParameter('pimcore.config'); if (!$config['documents']['areas']['autoload']) { @@ -21,6 +22,11 @@ public function process(ContainerBuilder $container): void $possibleNoPimcoreAwareBricks = []; foreach ($container->getDefinitions() as $definitionId => $definition) { + + if (in_array($definitionId, $disabledAreaBricks, true)) { + continue; + } + if (!str_contains((string) $definitionId, '.area.brick.')) { continue; } diff --git a/src/DependencyInjection/ToolboxExtension.php b/src/DependencyInjection/ToolboxExtension.php index e39f0ae2..40c58220 100644 --- a/src/DependencyInjection/ToolboxExtension.php +++ b/src/DependencyInjection/ToolboxExtension.php @@ -80,6 +80,11 @@ public function load(array $configs, ContainerBuilder $container): void $configManagerDefinition = $container->getDefinition(ConfigManager::class); $configManagerDefinition->addMethodCall('setConfig', [$config]); + $disabledAreaBricks = array_filter($config['areas'], static function(array $area) { + return $area['enabled'] === false; + }); + + $container->setParameter('toolbox.area_brick.disabled_bricks', array_keys($disabledAreaBricks)); $container->setParameter('toolbox.area_brick.dialog_aware_bricks', $this->determinateConfigDialogAwareBricks($config)); //context resolver diff --git a/src/Manager/ConfigManager.php b/src/Manager/ConfigManager.php index 6cffe43f..36c01a1f 100644 --- a/src/Manager/ConfigManager.php +++ b/src/Manager/ConfigManager.php @@ -74,8 +74,11 @@ public function areaIsEnabled(string $areaName): bool { $this->ensureCoreConfig(); - if (array_key_exists($areaName, $this->config['areas'])) { - return $this->config['areas'][$areaName]['enabled'] === true; + // keys cannot have dashes in symfony configuration, so replace if given + $saveKeyName = str_replace('-', '_', $areaName); + + if (array_key_exists($saveKeyName, $this->config['areas'])) { + return $this->config['areas'][$saveKeyName]['enabled'] === true; } return true;