0

I want to display success and error notification with Mage::getSingleton('core/session')->addSuccess() and ->addError() if the admin is on a specific Configuration Section.

The reason: I made an extension, which has a separate section in System / Configuration, and I want to give a feedback if it is configured properly or not, but only when the admin is at that section.

I tried to create a default.notifications block, which worked, but the notification was a 'global notification', not a smaller notification box, which was located on the top of the settings fields of my extensions' settingfields. Also: I want to add these notifications only if the admin is at this specific section's Configuration page.

Thanks!

  • Can you add an image indicating where exactly you intend to place this message? 'Separate section' in admin can have a few variations. An image will clarify any doubts – ProxiBlue Dec 14 '15 at 14:00
  • Is this what you want? magento.stackexchange.com/questions/16634/… – vinothavn Dec 14 '15 at 14:01
  • @ProxiBlue Yes, sure I'll upload the thing I want to get I have to prepare the pics. – TeeCee Dec 14 '15 at 14:31
  • @vinothavn yes, I can add those notifications, but my question is how to make those notices visible only on the System / Configurations page when my section is selected. – TeeCee Dec 14 '15 at 14:31
  • @ProxiBlue 'Screenshot Sorry I got some problems sharing a screenshot :shame: – TeeCee Dec 14 '15 at 14:49
3

The message area you are referring to

enter image description here

is populated from Mage_Adminhtml_System_ConfigController::saveAction.

Before the message is set, an event ("admin_system_config_changed_section_{$section}) is fired.

code ref:

Mage::dispatchEvent("admin_system_config_changed_section_{$section}",
                array('website' => $website, 'store' => $store)
            );
            $session->addSuccess(Mage::helper('adminhtml')->__('The configuration has been saved.'));

You just need to figure out what is in the section ($section = $this->getRequest()->getParam('section');) and you would most likely be able to target an event specific to your section saving.

There is also an alternative solution: Use a Hint field in the admin section.

Place a HINT group into your system.xml configuration file. An example:

<hint>
   <frontend_model>dyncatprod/adminhtml_system_config_fieldset_hint</frontend_model>
     <sort_order>0</sort_order>
     <show_in_default>1</show_in_default>
     <show_in_website>1</show_in_website>
     <show_in_store>1</show_in_store>
</hint>

make sure it has the lowest sort order.

You will need to define the block class, below is an example, showing teh path as per the xml example.

enter image description here

It must contain a render method

/**
     * Render fieldset html
     *
     * @param  Varien_Data_Form_Element_Abstract $element
     *
     * @return string
     */
    public function render(Varien_Data_Form_Element_Abstract $element)
    {
        return $this->toHtml();
    }

You can then of course output whatever you need, and run whatever logic you need, via your block adminhtml_system_config_fieldset_hint

An example, to output some information about the installed extension:

enter image description here

| improve this answer | |
  • Thanks, the Hint group will be the better, since I want to add some info there also. Thanks You for the great description! – TeeCee Dec 16 '15 at 8:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.