在添加/编辑产品页面上添加自定义按钮 [英] Add custom button on add/edit product page

查看:62
本文介绍了在添加/编辑产品页面上添加自定义按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

https://i.stack.imgur.com/uHZ33.png

如何在添加/编辑产品页面(magento2)中添加自定义按钮.我需要在点击按钮时打开弹出窗口.

How to add a custom button, in add/edit product page (magento2). I need to open popup on clicking of the button.

推荐答案

产品表单是通过 ui-components 生成的.产品表单的ui组件名称为 view/adminhtml/ui_component/product_form.xml .

The product form is generated via ui-components. The ui component name for product form is view/adminhtml/ui_component/product_form.xml.

您需要在自己的模块中使用以下内容创建具有相同名称和路径的文件:

You need to create a file with the same name and path in your own module with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <argument name="data" xsi:type="array">
        <item name="buttons" xsi:type="array">
            <item name="button-unique-identifier-here" xsi:type="string">[Namespace]\[Module]\Block\Adminhtml\Product\Edit\Button\CustomButton</item>
        </item>
    </argument>
</form>

然后在文件 [Namespace]/[Module]/Block/Adminhtml中创建类 [Namespace] \ [Module] \ Block \ Adminhtml \ Product \ Edit \ Button \ CustomButton /Product/Edit/Button/CustomButton.php

Then create the class [Namespace]\[Module]\Block\Adminhtml\Product\Edit\Button\CustomButton in the file [Namespace]/[Module]/Block/Adminhtml/Product/Edit/Button/CustomButton.php

<?php 
namespace [Namespace]\[Module]\Block\Adminhtml\Product\Edit\Button;

use Magento\Catalog\Block\Adminhtml\Product\Edit\Button\Generic;

class CustomButton extends Generic
{
    public function getButtonData()
    {
        return [
            'label' => __('Your button label here'),
            'on_click' => "alert('it works')",
            'sort_order' => 100
        ];
    }
}

您的ui组件文件应与主文件合并,并且您的按钮应出现在其他按钮之中.

Your ui component file should be merged with the main file and your buttons should appear among the other buttons.

在刷新缓存后检查这些更改

这篇关于在添加/编辑产品页面上添加自定义按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆