Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it good practice to add own file in lib/Varien/Data/Form/Element folder
    primarykey
    data
    text
    <p>I need to create module in Magento which will have few database tables. One of the function of the module is adding multiple images. For example while being on the "<strong>Add new item</strong>" or "<strong>Edit item</strong>" page in the admin, from the left side I have tabs, one of them is "<strong>Item Images</strong>". When being clicked I want the content of this tab to be my own custom one. After digging into the code, found out that the way it renders this content, Magento is using one of the <strong>Varien_Data_Form_Element</strong> classes for each element in the full form. I want to add my own class here that will render form elements the way I want. Is this a good practice to do so, or there is some other more elegant way of adding own content in the admin forms? EDIT: I must add that none of the existing classes is helping my problem.</p> <p>SOLUTION EDIT: I have a controller in my custom module that is in <strong>Mypackage/Mymodule/controllers/Adminhtml/Item.php</strong>. In the <strong>editAction()</strong> method which I am using for adding and creating new items, I am creating 2 blocks, one for the form and one left for the tabs:</p> <pre> $this->_addContent($this->getLayout()->createBlock('item/adminhtml_edit')) ->_addLeft($this->getLayout()->createBlock('item/adminhtml_edit_tabs')); $this->renderLayout(); </pre> <p>The <strong>Block/Adminhtml/Edit/Tabs.php</strong> block is creating 2 tabs on the left: <strong>General Info</strong> and <strong>Item Images</strong>, each of them are rendering different content on the right side using Block classes. </p> <pre> protected function _beforeToHtml() { $this->addTab('item_info', array( 'label' => Mage::helper('mymodule')->__('Item Info'), 'content'=> $this->getLayout()->createBlock('item/adminhtml_edit_tab_form')->toHtml(), )); $this->addTab('item_images', array( 'label' => Mage::helper('mymodule')->__('Item Images'), 'active' => ( $this->getRequest()->getParam('tab') == 'item_images' ) ? true : false, 'content' => $this->getLayout()->createBlock('item/adminhtml_images')->toHtml(), )); return parent::_beforeToHtml(); } </pre> <p>I wanted the tab <strong>item_images</strong> to render my own form elements and values, not the default varien form elements. </p> <pre> class Mypackage_Mymodule_Block_Adminhtml_Images extends Mage_Core_Block_Template { public function __construct() { parent::__construct(); $this->setTemplate('item/images.phtml'); //This is in adminhtml design } public function getPostId() { return $this->getRequest()->getParam('id'); } public function getExistingImages() { return Mage::getModel('mymodule/item')->getImages($this->getPostId()); } } </pre> <p>Then in the template app/design/adminhtml/default/default/template/item/images.phtml you can use these values:</p> <pre> //You can add your own custom form fields here and all of them will be included in the form foreach($this->getExistingImages() as $_img): //Do something with each image endforeach; //You can add your own custom form fields here and all of them will be included in the form </pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload