I want add a new Draft button in Product Edit page (located between Back and Add Attribute)
I am able to add by following the tutorial : magento2-how-to-add-custom-button-in-product-edit-form
But, I am unable to add the link to my custom controller. Does anyone have any advice please.
-
5Possible duplicate of Magento2 : How to add Custom button in product edit formTeja Bhagavan Kollepara– Teja Bhagavan Kollepara2017年02月15日 11:27:42 +00:00Commented Feb 15, 2017 at 11:27
-
I am able to added Teja i want add link to my controller can you please tell mePawankumar– Pawankumar2017年02月15日 11:29:12 +00:00Commented Feb 15, 2017 at 11:29
1 Answer 1
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>
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' => __('Enter Your button label here'),
'on_click' => "alert('it works..')",
'class' => 'primary',
'sort_order' => 100
];
}
}
Your ui component file should be merged with the main file and your buttons should appear among the other buttons.
-
Sorry to ask, may you please have a look at my question related to this, regarding a button implementation. magento.stackexchange.com/questions/339727/… . In short, I want to know if there is any built-in behaviour.CvRChameleon– CvRChameleon2021年06月15日 10:39:06 +00:00Commented Jun 15, 2021 at 10:39