【问题标题】:Magento 2 Image Selector in Widget CMS sectionWidget CMS 部分中的 Magento 2 图像选择器
【发布时间】:2016-04-25 23:55:39
【问题描述】:

我创建了一个带有图像选择器的 Magento 2 小部件(除其他外)。当我在 CMS 中使用此小部件并将其直接添加到页面(内容 > 页面 > 编辑页面 > 插入小部件)时,图像选择器将正确显示,并允许我选择或上传图像。

但是,如果我进入 CMS 的小部件部分(内容 > 小部件 > 添加小部件),尝试使用小部件的相同图像选择器部分会得到 Uncaught ReferenceError: MediabrowserUtility is not defined

在我所做的搜索中,似乎是由于此页面上未加载 TinyMCE,但我只能在 Magento 1 中找到修复它的代码参考。

如果是这样,我将如何在 CMS 的小部件页面中获取正确的 javascript 文件?

【问题讨论】:

  • 我也有同样的问题

标签: magento2


【解决方案1】:

我找到了这个解决方案: 在 Uploader 的区块中(例如:Company/Module/Block/Adminhtml/Uploader),方法prepareElementHtml(AbstractElement $element):

    $config = $this->_getData('config');
    $sourceUrl = $this->getUrl('cms/wysiwyg_images/index', ['target_element_id' => $element->getId(), 'type' => 'file']);

    $chooser = $this->getLayout()->createBlock(Button::class)
        ->setType('button')
        ->setClass('btn-chooser')
        ->setLabel($config['button']['open'])
        ->setOnClick('MediabrowserUtility.openDialog(\'' . $sourceUrl . '\', 0, 0, "MediaBrowser", {})')
        ->setDisabled($element->getReadonly());

    $input = $this->elementFactory->create("text", ['data' => $element->getData()]);
    $input->setId($element->getId());
    $input->setForm($element->getForm());
    $input->setClass("widget-option input-text admin__control-text");

    if ($element->getRequired()) {
        $input->addClass('required-entry');
    }

    $element->setData('after_element_html', $input->getElementHtml() . $chooser->toHtml() . "<script>require(['mage/adminhtml/browser']);</script>");
    
    return $element;

这是example

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-30
    • 2020-02-17
    • 2012-12-10
    • 2011-01-15
    • 1970-01-01
    • 2012-04-30
    • 1970-01-01
    相关资源
    最近更新 更多