3

I created a form in backend like this:

ex

I want to change save button text from 'Save' to 'Insert', here's my code:

Block\Adminhtml\Tools\Edit.php:

namespace Test\UploadFile\Block\Adminhtml\Tools;

use Magento\Backend\Block\Widget\Form\Container;

class Edit extends Container
{

    protected $coreRegistry;

    protected $toolsId=false;

    public function __construct(
        \Magento\Backend\Block\Widget\Context $context,
        \Magento\Framework\Registry $registry,
        array $data = []
    ) {
        $this->coreRegistry = $registry;
        parent::__construct($context, $data);
    }

    protected function _construct()
    {
        $this->_objectId = 'tools_id';
        $this->_controller = 'adminhtml_tools';
        $this->_blockGroup = 'Lime_UploadFile';

        parent::_construct();

        $toolsId = $this->getToolsId();
        if (!$toolsId) {
            $this->buttonList->remove('delete');
        }
    }


    public function getHeaderText()
    {
        $toolsId = $this->getToolsId();
        if (!$toolsId) {
            return __('New File Item');
        } else {
            return __('Edit File Item');
        }
    }

    public function getToolsId()
    {
        if (!$this->toolsId) {
            $this->toolsId=$this->coreRegistry->registry('current_tools_id');
        }
        return $this->toolsId;
    }

}
2

You just need to add $this->buttonList->update() to update existing buttons of admin form in Edit.php

app/code/Vendor/Module/Block/Adminhtml/BlockClass/Edit.php

As per your code you can change save button label like this:

protected function _construct()
{
    $this->_objectId = 'tools_id';
    $this->_controller = 'adminhtml_tools';
    $this->_blockGroup = 'Lime_UploadFile';

    parent::_construct();

    $this->buttonList->update('save', 'label', __('Your Label Here'));

    $toolsId = $this->getToolsId();
    if (!$toolsId) {
        $this->buttonList->remove('delete');
    }
}

By this same way, you can change other buttons like save and continue, reset, back and other admin buttons

$this->buttonList->update('reset', 'label', __('Your Label Here')); //Change Reset Button Label
$this->buttonList->update('back', 'label', __('Your Label Here')); //Change Reset Button Label
$this->buttonList->update('saveandcontinue', 'label', __('Your Label Here')); //Change SaveAndContinue Button Label
$this->buttonList->update('delete', 'label', __('Your Label Here')); //Change Delete Button Label
1

This may help you. You can change your Edit.php file's _construct function as below.

protected function _construct()
{
    $this->_objectId = 'tools_id';
    $this->_controller = 'adminhtml_tools';
    $this->_blockGroup = 'Lime_UploadFile';

    parent::_construct();
    $this->buttonList->update('save', 'label', __('Insert'));
    $toolsId = $this->getToolsId();
    if (!$toolsId) {
        $this->buttonList->remove('delete');
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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