How to remove default magento 2 buttons (admin panel)

Hi guys today I had a little problem. It had to remove one of the magento 2 default buttons like you probably have seen. I needed to remove the save button.It is a read-only module so there is no need for a save button.

Starting point:

Magento 2 default buttonI looked at all possible places and could not find the answer so I tried to solve it on my own way and I came up with a solution.

In order to remove any default button that magento generates for you. You first need to check what is the button id. You can do it by simply going in the inspect element mode of your browser, which will give you something like this.

Inspect element:

Magento 2 inspect default button

Now that you have the button’s ID you can delete it. I’ll show you how to do that.

Now you just need to follow these simple steps:

  1. Find the php file which is responsible for generating your layout.In my case it is located in /Module/Controller/Block/Adminhtml/Controller/yourphpfile.php
  2. Make sure that your class is extending the Container class from the Magento\Backend\Block\Widget\Form\Container namespace. Because the buttonList->remove function is the Container classes function
  3. Since magento does not allow the __construct function to be changed the only solution for me was to change it in the _prepareLayout function. You can do it just by placing this function call in the _prepareLayout function of your php file $this->buttonList->remove(‘save’);
Example:

magento remove button code example

With this your button should be successfully removed.

End result:

Removed magento 2 default button

Leave a Reply

Your email address will not be published. Required fields are marked *