I am working on module which will work for sync product from Third party Api.I have already created admin controller page but don't have Idea how to add button Sync Products whose action will call a controller file . Have anyone idea how to add new custom button with action controller?

I have added menu in admin section with Parent Catalog->

Admin menu is


<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
        <add id="Vendorname_Syncfromshopify::sync_product" title="Sync From Shopiofy" module="Vendorname_Syncfromshopify" parent="Magento_Catalog::catalog" sortOrder="30"  resource="Vendorname_Syncfromshopify::sync_product" action="syncproductshopify/syncproduct/" />

My controller is


namespace Vendorname\Syncfromshopify\Controller\Adminhtml\Syncproduct;

use Magento\Backend\App\Action\Context;
use Magento\Framework\View\ResultPageFactory;

class Index extends \Magento\Backend\App\Action

    * @var PageFactory
    public function execute()


My above controller is working fine and redirecting to admin page.

Now I want to add a button (ABC name) and in action of another controller which will responsible for sync data from third party and Insert in Magento.

So How we will create new button in admin controller and give action?

  • What is your Magento version? Commented Dec 18, 2017 at 11:32
  • Magento version 2.2.1
    – akgola
    Commented Dec 18, 2017 at 11:33
  • But, you want to add the button on product listing page or edit form? Commented Dec 18, 2017 at 12:06
  • I want to add button in custom module,just in an controller.
    – akgola
    Commented Dec 18, 2017 at 12:10
  • Please guide me how to add button in admin controller file and what we will require for it.
    – akgola
    Commented Dec 18, 2017 at 12:11

1 Answer 1


Create a file in Vendorname\Module\Block\Adminhtml\CustomButtom.php

namespace Vendorname\Module\Block\Adminhtml\Buttom;

use \Magento\Backend\Block\Widget\Context;
use \Magento\Backend\Model\UrlInterface;

class CustomButtom extends \Magento\Backend\Block\Widget\Container {
    protected $_backendUrl;

     * @param \Magento\Backend\Block\Widget\Context $context
     * @param array $data
    public function __construct(
        Context $context,
        UrlInterface $backendUrl,
        array $data = []
    ) {
        $this->_backendUrl = $backendUrl;
        parent::__construct($context, $data);

     * Block constructor adds buttons
    protected function _construct() {

     * Return button attributes array
    public function getButtonData() {
        $url = $this->_backendUrl->getUrl("module/page/index");
        return [
            'label' => __('Custom buttom label'),
            'on_click' => 'setLocation("'.$url.'")',
            'class' => 'primary'

In your layout just need to add the buttom


<block class="Vendorname\Module\Block\Adminhtml\Status\CustomButtom" name="CustomButtom"/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.