1

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.Gallery 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,
Jonathan

Jonathan Day
  • 18,519
  • 10
  • 84
  • 137

3 Answers3

1

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 afterLoadmagic-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?

Jonathan Day
  • 18,519
  • 10
  • 84
  • 137
  • A quick [ack](http://betterthangrep.com/) shows the gallery tab gets instantiated in `Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Attributes::_getAdditionalElementTypes()`. – clockworkgeek Jun 22 '11 at 09:49
  • @clockworkgeek - yeah I saw that too, but I'm not seeing where that method gets called... – Jonathan Day Jun 22 '11 at 10:01
  • That method is called by it's inherited `_addElementTypes()` method which in turn is called by it's descendent - `Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Super_Config_Simple` - when preparing the form. – clockworkgeek Jun 22 '11 at 11:15
1

You 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.

clockworkgeek
  • 37,650
  • 9
  • 89
  • 127
0

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 :)

Community
  • 1
  • 1
WonderLand
  • 5,494
  • 7
  • 57
  • 76