如何在 Magento Admin 中填充图片库表单

发布于 2024-11-16 17:37:07 字数 1161 浏览 4 评论 0原文

我可以看到 Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Gallery_Content::getImagesJson()app\design\adminhtml\default\default\template\catalog\product\helper\gallery.phtml 负责放置通过 Product.Gallery 原型类将图像数据传输到浏览器中。

但是,我无法追踪在 Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Gallery_Content 块上设置图像集合的位置。我假设它是通过控制器或布局中某处的魔术设置器实现的,但我无法追踪它。

Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Gallery_Content::getImagesJson()

$value = $this->getElement()->getValue();
        if(count($value['images'])>0) {
            foreach ($value['images'] as &$image) {

一些东西正在填充该块的 element 属性。

Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Gallery_Content 似乎是由 Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Gallery::getContentHtml() 实例化的,但不会在块上设置任何属性。

我可以看到 Mage_Catalog_Model_Product_Attribute_Backend_Media::afterLoad() 使用与 Product.Gallery Javascript 正在查找的结构相匹配的数组填充属性,但我仍然是对于属性与渲染块的绑定位置有点困惑。

我想我需要一个图表来让这个错综复杂的网络在我的脑海中保持清晰!

谢谢,
乔纳森

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

荒岛晴空 2024-11-23 17:37:07

你说;

...似乎是由 Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Gallery::getContentHtml() 实例化的,但不会在块上设置任何属性。

但是 getContentHtml() 看起来像这样:

/**
 * 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();
}

它明确地将 $contentelement 设置为 $this,即Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Gallery 对象。

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.

你不是我要的菜∠ 2024-11-23 17:37:07

答案就在我眼前。 eav_attribute 中的 media_gallery 属性将 Mage_Catalog_Model_Product_Attribute_Backend_Media 定义为执行 afterLoadmagic-setter 的后端类。

仍然不确定 Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Gallery 附加到产品编辑屏幕选项卡的位置,有人知道吗?

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?

感受沵的脚步 2024-11-23 17:37:07

仍然不确定 Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Gallery 附加到产品编辑屏幕选项卡的位置,有人知道吗?

我发现这是在 Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs 中完成的

。查看第 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()),
            ));

如果您注释掉此代码,“图像”选项卡将消失。

这个画廊里有很多“魔法”,我在这里打开了另一个关于它的讨论:
https://stackoverflow.com/questions/ 11740995/how-to-include-magento-image-gallery-in-a-custom-module-backend

我希望它有帮助:)

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文