7

I have created a module which allows to add menu items dynamically from admin panel configuration. For this, I have added a dynamic field with "Add more" button.
It works perfectly and the menu I have created is being displayed on top menu. Now I want to add submenu to that menu item.

enter image description here
You can see it in the image.
I have this code in my form field block

public function __construct()
    {
        $this->addColumn('menutitle', array(
            'label' => Mage::helper('adminhtml')->__('Menu Title'),
            'style' => 'width:120px',
            'class' => 'input-text required-entry'
        ));
        $this->addColumn('link', array(
            'label' => Mage::helper('adminhtml')->__('Link'),
            'style' => 'width:220px',
            'class' => 'input-text required-entry'
        ));

        $this->addColumn('order', array(
            'label' => Mage::helper('adminhtml')->__('Order'),
            'style' => 'width:40px',
            'class' => 'required-entry input-text validate-number'
        ));

        $this->_addAfter = false;
        $this->_addButtonLabel = Mage::helper('adminhtml')->__('Add Menu Item');
        Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract::__construct();
    }
    protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
    {
        $this->setElement($element);
        $html = $this->_toHtml();
        $this->_arrayRowsCache = null; // doh, the object is used as singleton!
        $html ='<div id="myeditableitem">'.$html.'</div>';
    return $html;
    }

I have tried adding a button in form but without success. I dont have any idea where or how to start. Please help.

1
  • 1
    Are trying to use it the same way as custom options work? Commented May 26, 2014 at 8:21

3 Answers 3

2

Everything is dynamic, because of this, you have to add the buttons via JS.

1

Jaimin Sutariya, Instead of creating menu under configuration, you can easily build it dynamically by creating grid with add,update, delete functionlity.

1

The form you are using has the option to add a button "Add After", in your form PHP block class you have to set:

$this->_addAfter = false;

This will not make the system know that this item should be a submenu, therefore you could create a select/dropdown option to select the parent page and build the structure this way.

The dropdown/select is not a default option for this form array, see my pull-request for the changes needed to add this to your form:

https://github.com/vkerkhoff/hackathon_january_2014/commit/2c4338038477a993c44112dd072849ff9b8cd2f9

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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