Изменить текст кнопки "Сохранить" в форме администратора
Я создал форму в бэкэнде следующим образом:
Я хочу изменить текст кнопки "Сохранить" с "Сохранить" на "Вставить", вот мой код:
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;
}
}
3
Author: Prince Patel, 2017-08-22
2 answers
Вам просто нужно добавить $this->buttonList->update()
, чтобы обновить существующие кнопки формы администратора в Edit.php
App/code/Vendor/Module/Block/Adminhtml/BlockClass/Edit.php
В соответствии с вашим кодом вы можете изменить метку кнопки сохранения следующим образом:
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');
}
}
Таким же образом вы можете изменить другие кнопки, такие как сохранить и продолжить, сброс, назад и другие кнопки администратора
$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
2
Author: Prince Patel, 2017-08-22 05:14:00
Это может вам помочь. Вы можете изменить свой Edit.php функция _construct файла, как показано ниже.
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');
}
}
1
Author: sabarivenkatesankrish, 2017-08-22 04:21:11