From 714ba482290301c9e04ea528ea980d73346bd0d9 Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Thu, 24 Oct 2024 06:14:15 +0200 Subject: [PATCH 1/6] hide disabled module --- .../Config/Form/Fieldset/Modules/DisableOutput.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php index da8829fd498..475f2cf4516 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php @@ -27,7 +27,16 @@ public function render(Varien_Data_Form_Element_Abstract $element) { $html = $this->_getHeaderHtml($element); - $modules = array_keys((array)Mage::getConfig()->getNode('modules')->children()); + $modules = (array)Mage::getConfig()->getNode('modules')->children(); + /** @var Mage_Core_Model_Config_Element $module */ + foreach ($modules as $index => $module) { + $module = $module->asArray(); + if ($module['active'] === 'false') { + unset($modules[$index]); + } + } + + $modules = array_keys($modules); $dispatchResult = new Varien_Object($modules); Mage::dispatchEvent( From 49eea29547382a88ee447175b19a0e1f59363104 Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Fri, 25 Oct 2024 14:30:47 +0200 Subject: [PATCH 2/6] use observer --- .../Form/Fieldset/Modules/DisableOutput.php | 11 +--------- .../System/Config/Backend/Admin/Observer.php | 20 +++++++++++++++++++ app/code/core/Mage/Adminhtml/etc/config.xml | 8 ++++++++ 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php index 475f2cf4516..f370459f3fe 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php @@ -28,22 +28,13 @@ public function render(Varien_Data_Form_Element_Abstract $element) $html = $this->_getHeaderHtml($element); $modules = (array)Mage::getConfig()->getNode('modules')->children(); - /** @var Mage_Core_Model_Config_Element $module */ - foreach ($modules as $index => $module) { - $module = $module->asArray(); - if ($module['active'] === 'false') { - unset($modules[$index]); - } - } - - $modules = array_keys($modules); $dispatchResult = new Varien_Object($modules); Mage::dispatchEvent( 'adminhtml_system_config_advanced_disableoutput_render_before', ['modules' => $dispatchResult] ); - $modules = $dispatchResult->toArray(); + $modules = array_keys($dispatchResult->toArray()); sort($modules); diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Admin/Observer.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Admin/Observer.php index 42c73282acb..29a5217a2b4 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Admin/Observer.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Admin/Observer.php @@ -44,4 +44,24 @@ public function afterCustomUrlChanged($observer) ->sendResponse(); exit(0); } + + /** + * Hide disabled modules + * + * @see Mage_Adminhtml_Block_System_Config_Form_Fieldset_Modules_DisableOutput::render() + */ + public function beforeRenderModuleList(Varien_Event_Observer $observer): void + { + $event = $observer->getDataByKey('event'); + $modules = $event->getDataByKey('modules'); + $data = $modules->getData(); + /** @var Mage_Core_Model_Config_Element $module */ + foreach ($data as $index => $module) { + $module = $module->asArray(); + if ($module['active'] === 'false') { + unset($data[$index]); + } + } + $modules->setData($data); + } } diff --git a/app/code/core/Mage/Adminhtml/etc/config.xml b/app/code/core/Mage/Adminhtml/etc/config.xml index 4d06c0c927a..6b8e62bc338 100644 --- a/app/code/core/Mage/Adminhtml/etc/config.xml +++ b/app/code/core/Mage/Adminhtml/etc/config.xml @@ -115,6 +115,14 @@ + + + + adminhtml/system_config_backend_admin_observer + beforeRenderModuleList + + + From 3dd04c83d89e266aff1253fca94b483222bfefc1 Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Fri, 25 Oct 2024 15:42:33 +0200 Subject: [PATCH 3/6] refactor --- .../Form/Fieldset/Modules/DisableOutput.php | 24 ++++--- .../Fieldset/Modules/DisableOutputTest.php | 65 +++++++++++++++++++ 2 files changed, 80 insertions(+), 9 deletions(-) create mode 100644 tests/unit/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Modules/DisableOutputTest.php diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php index f370459f3fe..746358049ee 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php @@ -27,6 +27,20 @@ public function render(Varien_Data_Form_Element_Abstract $element) { $html = $this->_getHeaderHtml($element); + $modules = $this->getModules(); + foreach ($modules as $moduleName) { + if ($moduleName === 'Mage_Adminhtml') { + continue; + } + $html .= $this->_getFieldHtml($element, $moduleName); + } + $html .= $this->_getFooterHtml($element); + + return $html; + } + + public function getModules(): array + { $modules = (array)Mage::getConfig()->getNode('modules')->children(); $dispatchResult = new Varien_Object($modules); @@ -38,15 +52,7 @@ public function render(Varien_Data_Form_Element_Abstract $element) sort($modules); - foreach ($modules as $moduleName) { - if ($moduleName === 'Mage_Adminhtml') { - continue; - } - $html .= $this->_getFieldHtml($element, $moduleName); - } - $html .= $this->_getFooterHtml($element); - - return $html; + return $modules; } protected function _getDummyElement() diff --git a/tests/unit/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Modules/DisableOutputTest.php b/tests/unit/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Modules/DisableOutputTest.php new file mode 100644 index 00000000000..230fa611c1b --- /dev/null +++ b/tests/unit/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Modules/DisableOutputTest.php @@ -0,0 +1,65 @@ +subject = new Mage_Adminhtml_Block_System_Config_Form_Fieldset_Modules_DisableOutput(); + } + + /** + * @group Mage_Adminhtml + * @group Mage_Adminhtml_Block + */ + public function testGetModulesCount(): void + { + $this->assertSame(61, count($this->subject->getModules())); + } + + /** + * @dataProvider provideModules + * @group Mage_Adminhtml + * @group Mage_Adminhtml_Block + */ + public function testGetModules(string $module): void + { + $result = $this->subject->getModules(); + $this->assertArrayHasKey($module, array_flip($result)); + } + + public function provideModules(): Generator + { + yield 'Mage_Admin' => [ + 'Mage_Admin' + ]; + yield 'Mage_Core' => [ + 'Mage_Core' + ]; + } +} From be04bb2968d0669e087bec1239fdaf499bde836b Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Sun, 10 Nov 2024 09:12:12 +0100 Subject: [PATCH 4/6] dispatch event after config load --- .../Config/Form/Fieldset/Modules/DisableOutput.php | 12 +++++++++--- .../Model/System/Config/Backend/Admin/Observer.php | 2 +- app/code/core/Mage/Adminhtml/etc/config.xml | 8 ++++---- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php index 746358049ee..7c2dcc3ca1a 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php @@ -45,14 +45,20 @@ public function getModules(): array $dispatchResult = new Varien_Object($modules); Mage::dispatchEvent( - 'adminhtml_system_config_advanced_disableoutput_render_before', + 'adminhtml_system_config_advanced_disableoutput_module_config_after', ['modules' => $dispatchResult] ); - $modules = array_keys($dispatchResult->toArray()); + $modules = array_keys($dispatchResult->toArray()); sort($modules); - return $modules; + $dispatchResult = new Varien_Object($modules); + Mage::dispatchEvent( + 'adminhtml_system_config_advanced_disableoutput_render_before', + ['modules' => $dispatchResult] + ); + + return $dispatchResult->toArray(); } protected function _getDummyElement() diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Admin/Observer.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Admin/Observer.php index 29a5217a2b4..a7672389aa6 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Admin/Observer.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Admin/Observer.php @@ -48,7 +48,7 @@ public function afterCustomUrlChanged($observer) /** * Hide disabled modules * - * @see Mage_Adminhtml_Block_System_Config_Form_Fieldset_Modules_DisableOutput::render() + * @see Mage_Adminhtml_Block_System_Config_Form_Fieldset_Modules_DisableOutput::getModules() */ public function beforeRenderModuleList(Varien_Event_Observer $observer): void { diff --git a/app/code/core/Mage/Adminhtml/etc/config.xml b/app/code/core/Mage/Adminhtml/etc/config.xml index 6b8e62bc338..74f8bd1e1e3 100644 --- a/app/code/core/Mage/Adminhtml/etc/config.xml +++ b/app/code/core/Mage/Adminhtml/etc/config.xml @@ -115,14 +115,14 @@ - + - + adminhtml/system_config_backend_admin_observer beforeRenderModuleList - + - + From c9393d88ac46fc5ce682993d46e50b8750b93cfe Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Mon, 11 Nov 2024 14:29:11 +0100 Subject: [PATCH 5/6] Updated test --- .../Adminhtml/Model/System/Config/Backend/Admin/Observer.php | 3 +-- .../System/Config/Form/Fieldset/Modules/DisableOutputTest.php | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Admin/Observer.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Admin/Observer.php index 3686a208d25..39d40d0be7c 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Admin/Observer.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Admin/Observer.php @@ -58,8 +58,7 @@ public function beforeRenderModuleList(Varien_Event_Observer $observer): void $data = $modules->getData(); /** @var Mage_Core_Model_Config_Element $module */ foreach ($data as $index => $module) { - $module = $module->asArray(); - if ($module['active'] === 'false') { + if ($module->active === 'false') { unset($data[$index]); } } diff --git a/tests/unit/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Modules/DisableOutputTest.php b/tests/unit/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Modules/DisableOutputTest.php index 230fa611c1b..05cf7aa8bc6 100644 --- a/tests/unit/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Modules/DisableOutputTest.php +++ b/tests/unit/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Modules/DisableOutputTest.php @@ -39,7 +39,7 @@ public function setUp(): void */ public function testGetModulesCount(): void { - $this->assertSame(61, count($this->subject->getModules())); + $this->assertSame(60, count($this->subject->getModules())); } /** From f94fee2e58d72133b9cfa4c8006cdafdddb53dea Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Thu, 28 Nov 2024 20:30:58 +0100 Subject: [PATCH 6/6] rector --- .../System/Config/Form/Fieldset/Modules/DisableOutputTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Modules/DisableOutputTest.php b/tests/unit/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Modules/DisableOutputTest.php index 05cf7aa8bc6..74ed0b5e1f5 100644 --- a/tests/unit/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Modules/DisableOutputTest.php +++ b/tests/unit/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Modules/DisableOutputTest.php @@ -39,7 +39,7 @@ public function setUp(): void */ public function testGetModulesCount(): void { - $this->assertSame(60, count($this->subject->getModules())); + $this->assertCount(60, $this->subject->getModules()); } /**