Question

I want to write a module with a custom entity. In the backend it shall look like the backend from products (tabs on the left, forms on the right).

I tried many variants and inspected/copied many things from the core to understand it... well I don't.

Knows anyone a tutorial or the neccessary key points to realize this?

Many thanks

Edit: well, it's not the problem to create own entities, this is well known. I need help to create the backend, so that the result looks like the tabbed form when editting products

Was it helpful?

Solution

For adding multiple tabs in admin first go through the http://codemagento.com/2011/02/grids-and-forms-in-the-admin-panel/ provided by mpaepper.

after that create below class

Super_Awesome_Block_Adminhtml_Example_Edit_Tabs
Super_Awesome_Block_Adminhtml_Example_Edit_Tabs_Form
Super_Awesome_Block_Adminhtml_Example_Edit_Tabs_SecondTab

and modify the Super_Awesome_Block_Adminhtml_Example_Edit_Form to

class Super_Awesome_Block_Adminhtml_Example_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
{
    protected function _prepareForm()
    {
        $form = new Varien_Data_Form(array(
                'id' => 'edit_form',
                'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
                'method' => 'post',
                'enctype' => 'multipart/form-data',
        ));

        $form->setUseContainer(true);

        $this->setForm($form);

        return parent::_prepareForm();
    }
}

Add below code

class Super_Awesome_Block_Adminhtml_Example_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs {

    public function __construct() {
        parent::__construct();
        $this->setId('awesome_tabs');
        $this->setDestElementId('edit_form');
        $this->setTitle(Mage::helper('awesome')->__('Your Title Here'));
    }

    protected function _beforeToHtml() {
        $this->addTab('form_section', array(
            'label' => Mage::helper('awesome')->__('Details'),
            'title' => Mage::helper('awesome')->__('Details'),
            'content' => $this->getLayout()->createBlock('awesome/adminhtml_awesome_edit_tab_form')->toHtml(),
        ));


        $this->addTab('secondtab_section', array(
            'label'     => Mage::helper('awesome')->__('SecondTab'),
            'title' => Mage::helper('awesome')->__('SecondTab'),
            'content'   => $this->getLayout()->createBlock('awesome/adminhtml_awesome_edit_tab_secondtab')->toHtml(),
        ));

        return parent::_beforeToHtml();
    }

}

...

class Super_Awesome_Block_Adminhtml_Example_Edit_Tabs_Form extends Mage_Adminhtml_Block_Widget_Form
{
  protected function _prepareForm()
  {
      $form = new Varien_Data_Form();
      $this->setForm($form);
      $fieldset = $form->addFieldset('awesome_form', array('legend'=>Mage::helper('awesome')->__('Header text here')));

      $fieldset = $form->addFieldset('example_form', array(
             'legend' =>Mage::helper('awesome')->__('Example Information')
        ));

        $fieldset->addField('name', 'text', array(
             'label'     => Mage::helper('awesome')->__('Name'),
             'class'     => 'required-entry',
             'required'  => true,
             'name'      => 'name',
             'note'     => Mage::helper('awesome')->__('The name of the example.'),
        ));

        $fieldset->addField('description', 'text', array(
             'label'     => Mage::helper('awesome')->__('Description'),
             'class'     => 'required-entry',
             'required'  => true,
             'name'      => 'description',
        ));

        $fieldset->addField('other', 'text', array(
             'label'     => Mage::helper('awesome')->__('Other'),
             'class'     => 'required-entry',
             'required'  => true,
             'name'      => 'other',
        ));

        if (Mage::getSingleton('adminhtml/session')->getExampleData())
        {
            $data = Mage::getSingleton('adminhtml/session')->getExamplelData();
            Mage::getSingleton('adminhtml/session')->getExampleData(null);
        }
        elseif (Mage::registry('example_data'))
        {
            $data = Mage::registry('example_data')->getData();
        }
        else
        {
            $data = array();
        }

      return parent::_prepareForm();
  }
}

....

class Super_Awesome_Block_Adminhtml_Example_Edit_Tabs_SecondTab extends Mage_Adminhtml_Block_Widget_Grid {

    public function __construct() {
        parent::__construct();
        $this->setId('awesomeGrid');
        $this->setDefaultSort('awesome_secondtab_id');
        $this->setDefaultDir('DESC');
        $this->setSaveParametersInSession(true);
        $this->setFilterVisibility(false);
        $this->setPagerVisibility(false);
    }

    protected function _prepareCollection() {
        $id     = $this->getRequest()->getParam('id');
        $collection = Mage::getModel('awesome/secondtab')->getCollection()->addFilter('awesome_id', $id);
        $this->setCollection($collection);
        return parent::_prepareCollection();
    }

    protected function _prepareColumns() {


        $this->addColumn('created_time', array(
            'header' => Mage::helper('awesome')->__('Date'),
            'index' => 'created_time',
            'type' => 'datetime',
            'align' => 'left',
            'sortable' => false,
        ));

        $this->addColumn('type', array(
            'header' => Mage::helper('awesome')->__('Type'),
            'align' => 'left',
            'index' => 'type',
            'sortable' => false,
        ));

        $this->addColumn('amount', array(
            'header' => Mage::helper('awesome')->__('Amount'),
            'align' => 'left',
            'index' => 'amount',
            'type'  => 'currency',
            'currency' => 'amount',
            'sortable' => false,
        ));

        $this->addColumn('balance', array(
            'header' => Mage::helper('awesome')->__('Balance'),
            'align' => 'left',
            'index' => 'balance',
            'type'  => 'currency',
            'currency' => 'balance',
            'sortable' => false,
        ));

        $this->addColumn('order_number', array(
            'header' => Mage::helper('awesome')->__('Order Number'),
            'align' => 'left',
            'index' => 'order_number',
            'sortable' => false,
        ));

        return parent::_prepareColumns();
    }

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top