jeudi 16 avril 2015

Magento: How to build a custom image gallery in an admin form?

Before I begin, the answer in this Stack Overflow post, How to include Magento Image Gallery in a Custom Module Backend?, leads to a broken link and really does not provide a tangible answer, so please don't mark this as a duplicate of that.


I'm in the process of building a custom module to handle our customer's submitted product testimonials. I'm mostly done with the admin management portion of the module but am hitting a major stumbling block in understanding how to best implement the image management portion.


Just like the product management, when you edit a story, you can edit or add images associated with that story.


What I want is this: catalog_product images snapshot Though it will need to be custom built from scratch to suit my module's needs.


I'm using catalog_product as a reference for obvious reasons, but I don't understand how the catalog_product image grid and file uploader are being added to the attribute's fieldset.


What I have in the my image tab's class so far (not much) is:



class MyModule_Stories_Block_Adminhtml_Stories_Edit_Tab_Image
extends Mage_Adminhtml_Block_Widget_Form
implements Mage_Adminhtml_Block_Widget_Tab_Interface
{
protected function _prepareForm()
{
$model = Mage::registry('current_story');
$_data = $model->getData();

$form = new Varien_Data_Form();

$fieldset = $form->addFieldset('image_fieldset', array(
'legend' => $this->_translate('Story Images'),
));

$form->addValues($_data);
$this->setForm($form);
return parent::_prepareForm();
}


I'm just asking for a point in the right direction to proceed. Should I be creating the image grid in a custom block and add it to the form fieldset (and how do I add a block to a $fieldset)? And if I did add that block to the fieldset would I still be able to populate the any text fields in that block with the $_data using $form->addValues($_data);?


I'm kind of lost and any help would be appreciated. Thanks in advance.


Aucun commentaire:

Enregistrer un commentaire