how does the Image Gallery form get populated in Magento Admin
I can see that Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Gallery_Content::getImagesJson()
and app\design\adminhtml\default\default\template\catalog\product\helper\gallery.phtml
are responsible for putting the image data into the browser via the Product.Gallery
prototype class.
However, I can't track down where the image collection gets set on the Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Gallery_Content
block. I'm assuming its via a magic setter somewhere in the controller or layout, but I can't track it down.
Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Gallery_Content::getImagesJson()
has
$value = $this->getElement()->getValue();
if(count($value['images'])>0) {
foreach ($value['images'] as &$image) {
so something is populating the element
attribute of that block.
Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Gallery_Content
seems to be instantiated by Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Gallery::getContentHtml()
but that doesn't set any attributes on the block.
I can see that Mage_Catalog_Model_Product_Attribute_Backend_Media::afterLoad()
populates the attribute with an array that matches the structure that the Product.Ga开发者_StackOverflowllery
Javascript is looking for, but I'm still a little mystified as to where the Attribute gets tied to the rendering Block.
I think I need a diagram to keep this tangled web straight in my head!
Thanks,
JonathanYou say;
... seems to be instantiated by
Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Gallery::getContentHtml()
but that doesn't set any attributes on the block.
But getContentHtml()
looks like this:
/**
* Prepares content block
*
* @return string
*/
public function getContentHtml()
{
/* @var $content Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Gallery_Content */
$content = Mage::getSingleton('core/layout')
->createBlock('adminhtml/catalog_product_helper_form_gallery_content');
$content->setId($this->getHtmlId() . '_content')
->setElement($this);
return $content->toHtml();
}
It clearly sets the element
for $content
to $this
, which is the Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Gallery
object.
The answer was right in front of me. The media_gallery
attribute in eav_attribute
defines Mage_Catalog_Model_Product_Attribute_Backend_Media
as its backend class which does the afterLoad
magic-setter.
Still not exactly sure where the Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Gallery
gets attached to the product edit screen Tabs, anyone know?
Still not exactly sure where the Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Gallery gets attached to the product edit screen Tabs, anyone know?
I found out that this is done in Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs
Look at line 74:
$this->addTab('group_'.$group->getId(), array(
'label' => Mage::helper('catalog')->__($group->getAttributeGroupName()),
'content' => $this->_translateHtml($this->getLayout()->createBlock($this->getAttributeTabBlock(),
'adminhtml.catalog.product.edit.tab.attributes')->setGroup($group)
->setGroupAttributes($attributes)
->toHtml()),
));
If you commented it out this code the "Images" tab will disappear.
There is a lot of "magic" in this gallery, I have open another discussion about it here: https://stackoverflow.com/questions/11740995/how-to-include-magento-image-gallery-in-a-custom-module-backend
I hope it helps :)
精彩评论