From 63595d09af513e5319385e5276bfd22c7ecd26b1 Mon Sep 17 00:00:00 2001 From: Cosmo Date: Sat, 13 May 2023 21:13:13 +0800 Subject: [PATCH] Fixed "if newsletter module disabled, customer backend would blank without notice" (#3078) Co-authored-by: Fabrizio Balliano --- .../Adminhtml/Block/Customer/Edit/Tabs.php | 16 +++++----- .../Block/Sales/Order/View/Giftmessage.php | 29 +++++++++++-------- app/etc/modules/Mage_Captcha.xml | 4 +-- lib/Varien/Data/Form/Abstract.php | 8 ++++- 4 files changed, 34 insertions(+), 23 deletions(-) diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tabs.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tabs.php index 510700ea5dd..256c104c1c3 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tabs.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tabs.php @@ -73,13 +73,15 @@ protected function _beforeToHtml() 'url' => $this->getUrl('*/*/wishlist', ['_current' => true]), ]); - /** @var Mage_Adminhtml_Block_Customer_Edit_Tab_Newsletter $block */ - $block = $this->getLayout()->createBlock('adminhtml/customer_edit_tab_newsletter'); - if (Mage::getSingleton('admin/session')->isAllowed('newsletter/subscriber')) { - $this->addTab('newsletter', [ - 'label' => Mage::helper('customer')->__('Newsletter'), - 'content' => $block->initForm()->toHtml() - ]); + if (Mage::helper('core')->isModuleOutputEnabled('Mage_Newsletter')) { + /** @var Mage_Adminhtml_Block_Customer_Edit_Tab_Newsletter $block */ + $block = $this->getLayout()->createBlock('adminhtml/customer_edit_tab_newsletter'); + if (Mage::getSingleton('admin/session')->isAllowed('newsletter/subscriber')) { + $this->addTab('newsletter', [ + 'label' => Mage::helper('customer')->__('Newsletter'), + 'content' => $block->initForm()->toHtml() + ]); + } } if (Mage::getSingleton('admin/session')->isAllowed('catalog/reviews_ratings')) { diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Giftmessage.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Giftmessage.php index ce5b18ce4de..88c894a345a 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Giftmessage.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Giftmessage.php @@ -50,10 +50,14 @@ public function getOrder() */ protected function _beforeToHtml() { - if ($this->getParentBlock() && ($order = $this->getOrder())) { - $this->setEntity($order); + if (Mage::helper('core')->isModuleOutputEnabled('Mage_Giftmessage')) { + if ($this->getParentBlock() && ($order = $this->getOrder())) { + $this->setEntity($order); + } + return parent::_beforeToHtml(); + } else { + return parent::_beforeToHtml(); } - return parent::_beforeToHtml(); } /** @@ -63,15 +67,16 @@ protected function _beforeToHtml() */ protected function _prepareLayout() { - $this->setChild( - 'save_button', - $this->getLayout()->createBlock('adminhtml/widget_button') - ->setData([ - 'label' => Mage::helper('giftmessage')->__('Save Gift Message'), - 'class' => 'save' - ]) - ); - + if (Mage::helper('core')->isModuleOutputEnabled('Mage_Giftmessage')) { + $this->setChild( + 'save_button', + $this->getLayout()->createBlock('adminhtml/widget_button') + ->setData([ + 'label' => Mage::helper('giftmessage')->__('Save Gift Message'), + 'class' => 'save' + ]) + ); + } return $this; } diff --git a/app/etc/modules/Mage_Captcha.xml b/app/etc/modules/Mage_Captcha.xml index 6622355c4d0..a7e1ae74b07 100644 --- a/app/etc/modules/Mage_Captcha.xml +++ b/app/etc/modules/Mage_Captcha.xml @@ -21,9 +21,7 @@ core - - - + diff --git a/lib/Varien/Data/Form/Abstract.php b/lib/Varien/Data/Form/Abstract.php index 8c43dec64c3..e71920d1107 100644 --- a/lib/Varien/Data/Form/Abstract.php +++ b/lib/Varien/Data/Form/Abstract.php @@ -132,7 +132,13 @@ public function addField($elementId, $type, $config, $after = false) } else { $className = 'Varien_Data_Form_Element_' . ucfirst(strtolower($type)); } - $element = new $className($config); + + if (class_exists($className)) { + $element = new $className($config); + } else { + $className = 'Varien_Data_Form_Element_Note'; + $element = new $className($config); + } $element->setId($elementId); $this->addElement($element, $after); return $element;