Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dont show disabled modules in "Disable Modules Output" config #4305

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,7 @@ public function render(Varien_Data_Form_Element_Abstract $element)
{
$html = $this->_getHeaderHtml($element);

$modules = array_keys((array)Mage::getConfig()->getNode('modules')->children());

$dispatchResult = new Varien_Object($modules);
Mage::dispatchEvent(
'adminhtml_system_config_advanced_disableoutput_render_before',
['modules' => $dispatchResult]
);
$modules = $dispatchResult->toArray();

sort($modules);

$modules = $this->getModules();
foreach ($modules as $moduleName) {
if ($moduleName === 'Mage_Adminhtml') {
continue;
Expand All @@ -49,6 +39,22 @@ public function render(Varien_Data_Form_Element_Abstract $element)
return $html;
}

public function getModules(): array
{
$modules = (array)Mage::getConfig()->getNode('modules')->children();
kiatng marked this conversation as resolved.
Show resolved Hide resolved

$dispatchResult = new Varien_Object($modules);
Mage::dispatchEvent(
'adminhtml_system_config_advanced_disableoutput_render_before',
['modules' => $dispatchResult]
);
$modules = array_keys($dispatchResult->toArray());

sort($modules);

return $modules;
}

protected function _getDummyElement()
{
if (empty($this->_dummyElement)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
8 changes: 8 additions & 0 deletions app/code/core/Mage/Adminhtml/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@
</bind_locale>
</observers>
</admin_system_config_changed_section_admin>
<adminhtml_system_config_advanced_disableoutput_render_before>
<observers>
<hide_disabled>
<class>adminhtml/system_config_backend_admin_observer</class>
<method>beforeRenderModuleList</method>
</hide_disabled>
</observers>
</adminhtml_system_config_advanced_disableoutput_render_before>
</events>
<global_search>
<products>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

/**
* OpenMage
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available at https://opensource.org/license/osl-3-0-php
*
* @category OpenMage
* @package OpenMage_Tests
* @copyright Copyright (c) 2024 The OpenMage Contributors (https://www.openmage.org)
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

declare(strict_types=1);

namespace OpenMage\Tests\Unit\Mage\Adminhtml\Block\System\Config\Form\Fieldset\Modules;

use Generator;
use Mage;
use Mage_Adminhtml_Block_System_Config_Form_Fieldset_Modules_DisableOutput;
use PHPUnit\Framework\TestCase;

class DisableOutputTest extends TestCase
{
public Mage_Adminhtml_Block_System_Config_Form_Fieldset_Modules_DisableOutput $subject;

public function setUp(): void
{
Mage::app();
// phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation
$this->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'
];
}
}
Loading