我想在Magento 2的管理产品编辑页面的页面操作按钮(返回,保存)旁边添加一个新按钮。这个新按钮将执行自定义操作。任何人都可以让我知道,我如何在管理产品编辑页面的页面操作按钮区域创建新的按钮。我使用的是Magento 2.0.2版本
经过一番研究,我发现,我们可以通过编辑核心文件vendormagentomodule-catalogBlockAdminhtml product edit .php中的_prepareLayout()函数来在管理产品编辑页面中创建一个自定义按钮
为了做到这一点,我在我的模块中扩展了这个块文件。为此,首先我编辑了我的模块(MyVendor/MyModule/etc/di.xml)中的di.xml文件
<preference for="MagentoCatalogBlockAdminhtmlProductEdit" type="MyVendorMyModuleBlockAdminhtmlProductEdit" />
然后我扩展了Block文件到我的模块(MyVendor/MyModule/Block/Adminhtml/Product/Edit.php)
名称空间块MyVendor MyModule里 Adminhtml 产品;
类编辑扩展MagentoCatalogBlockAdminhtmlProductEdit{
/**
* Add elements in layout
*
* @return $this
*/
protected function _prepareLayout()
{
$this->getToolbar()->addChild(
'custom_buttonfor_myaction',
'MagentoBackendBlockWidgetButton',
[
'label' => __('Custom Button'),
'title' => __('Custom Button'),
'onclick' => 'setLocation('' . $this->getUrl(
'mycustompath/*/',
['store' => $this->getRequest()->getParam('store', 0)]
) . '')',
'class' => 'action-default primary'
]
);
return parent::_prepareLayout();
}
}
这会在Admin产品编辑页面中创建自定义按钮。