Skip to content

Commit

Permalink
use trait
Browse files Browse the repository at this point in the history
  • Loading branch information
sreichel committed Oct 31, 2024
1 parent 5c57b3e commit 51c7171
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*/
class Mage_Adminhtml_Block_Catalog_Helper_Form_Wysiwyg extends Varien_Data_Form_Element_Textarea
{
use Mage_Core_Trait_Module;

/**
* Retrieve additional html and put it at the end of element html
*
Expand Down Expand Up @@ -50,7 +52,7 @@ public function getAfterElementHtml()
*/
public function getIsWysiwygEnabled()
{
if (Mage::helper('catalog')->isModuleEnabled('Mage_Cms')) {
if ($this->isModuleEnabled('Mage_Cms', 'catalog')) {
return (bool)(Mage::getSingleton('cms/wysiwyg_config')->isEnabled()
&& $this->getEntityAttribute()->getIsWysiwygEnabled());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function editAction()
$block = $this->getLayout()->createBlock('adminhtml/system_config_edit');
$this->_addContent($block->initForm());

if (($current == 'carriers') && Mage::helper('core')->isModuleEnabled('Mage_Usa')) {
if (($current == 'carriers') && $this->isModuleEnabled('Mage_Usa')) {
$this->_addJs($this->getLayout()
->createBlock('adminhtml/template')
->setTemplate('system/shipping/ups.phtml'));
Expand Down
2 changes: 2 additions & 0 deletions app/code/core/Mage/Api2/Model/Resource/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
*/
abstract class Mage_Api2_Model_Resource_Validator
{
use Mage_Core_Trait_Module;

/**
* Array of validation failure errors.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ protected function _validateStockData($data)
if (isset($stockData['enable_qty_increments']) && (bool) $stockData['enable_qty_increments'] == true) {
$this->_validatePositiveNumeric($stockData, $fieldSet, 'qty_increments', false, true);
}
if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) {
if ($this->isModuleEnabled('Mage_CatalogInventory', 'catalog')) {
$this->_validateSource(
$stockData,
$fieldSet,
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Core/Block/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -1580,7 +1580,7 @@ protected function _isSecure()

public function isModuleEnabled(?string $moduleName = null, string $helperAlias = 'core'): bool
{
if ($moduleName === null) {
if (is_null($moduleName)) {
$moduleName = $this->getModuleName();
}

Expand All @@ -1595,7 +1595,7 @@ public function isModuleEnabled(?string $moduleName = null, string $helperAlias
*/
public function isModuleOutputEnabled(?string $moduleName = null, string $helperAlias = 'core'): bool
{
if ($moduleName === null) {
if (is_null($moduleName)) {
$moduleName = $this->getModuleName();
}

Expand Down
2 changes: 2 additions & 0 deletions app/code/core/Mage/Core/Controller/Varien/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/
abstract class Mage_Core_Controller_Varien_Action
{
use Mage_Core_Trait_Module;

public const FLAG_NO_CHECK_INSTALLATION = 'no-install-check';
public const FLAG_NO_DISPATCH = 'no-dispatch';
public const FLAG_NO_PRE_DISPATCH = 'no-preDispatch';
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Core/Helper/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ protected function _getModuleName()
*/
public function isModuleOutputEnabled($moduleName = null)
{
if ($moduleName === null) {
if (is_null($moduleName)) {
$moduleName = $this->_getModuleName();
}

Expand All @@ -148,7 +148,7 @@ public function isModuleOutputEnabled($moduleName = null)
*/
public function isModuleEnabled($moduleName = null)
{
if ($moduleName === null) {
if (is_null($moduleName)) {
$moduleName = $this->_getModuleName();
}

Expand Down
7 changes: 2 additions & 5 deletions app/code/core/Mage/Core/Model/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
*/
abstract class Mage_Core_Model_Abstract extends Varien_Object
{
use Mage_Core_Trait_Module;

/**
* Prefix of model events names
*
Expand Down Expand Up @@ -635,9 +637,4 @@ protected function _clearData()
{
return $this;
}

public function isModuleEnabled(string $moduleName, string $helperAlias = 'core'): bool
{
return Mage::helper($helperAlias)->isModuleEnabled($moduleName);
}
}
7 changes: 2 additions & 5 deletions app/code/core/Mage/Core/Model/Resource/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*/
abstract class Mage_Core_Model_Resource_Abstract
{
use Mage_Core_Trait_Module;

/**
* Main constructor
*/
Expand Down Expand Up @@ -226,9 +228,4 @@ protected function _prepareTableValueForSave($value, $type)
}
return $value;
}

public function isModuleEnabled(string $moduleName, string $helperAlias = 'core'): bool
{
return Mage::helper($helperAlias)->isModuleEnabled($moduleName);
}
}
33 changes: 33 additions & 0 deletions app/code/core/Mage/Core/Trait/Module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?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 Mage
* @package Mage_Core
* @copyright Copyright (c) 2006-2020 Magento, Inc. (https://www.magento.com)
* @copyright Copyright (c) 2020-2023 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);

/**
* Module trait
*
* @category Mage
* @package Mage_Core
*/
trait Mage_Core_Trait_Module
{
/**
* @uses Mage_Core_Helper_Abstract::isModuleEnabled()
*/
public function isModuleEnabled(?string $moduleName, string $helperAlias = 'core'): bool
{
return Mage::helper($helperAlias)->isModuleEnabled($moduleName);
}
}
7 changes: 2 additions & 5 deletions app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*/
abstract class Mage_Eav_Model_Entity_Collection_Abstract extends Varien_Data_Collection_Db
{
use Mage_Core_Trait_Module;

/**
* Array of items with item id key
*
Expand Down Expand Up @@ -1524,9 +1526,4 @@ public function _prepareSelect(Varien_Db_Select $select)

return (string)$select;
}

public function isModuleEnabled(string $moduleName, string $helperAlias = 'core'): bool
{
return Mage::helper($helperAlias)->isModuleEnabled($moduleName);
}
}

0 comments on commit 51c7171

Please sign in to comment.