Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Save.php
Go to the documentation of this file.
1 <?php
13 
14 class Save extends \Magento\Backend\Block\Template implements \Magento\Backend\Block\Widget\ContainerInterface
15 {
19  protected $_template = 'Magento_Tax::toolbar/rate/save.phtml';
20 
24  protected $buttonList;
25 
29  protected $toolbar;
30 
37  public function __construct(
38  \Magento\Backend\Block\Template\Context $context,
39  \Magento\Backend\Block\Widget\Button\ButtonList $buttonList,
40  \Magento\Backend\Block\Widget\Button\ToolbarInterface $toolbar,
41  array $data = []
42  ) {
43  $this->buttonList = $buttonList;
44  $this->toolbar = $toolbar;
45  parent::__construct($context, $data);
46  }
47 
51  protected function _construct()
52  {
53  parent::_construct();
54  $this->assign('createUrl', $this->getUrl('tax/rate/save'));
55  }
56 
67  public function addButton($buttonId, $data, $level = 0, $sortOrder = 0, $region = 'toolbar')
68  {
69  $this->buttonList->add($buttonId, $data, $level, $sortOrder, $region);
70  return $this;
71  }
72 
79  public function removeButton($buttonId)
80  {
81  $this->buttonList->remove($buttonId);
82  return $this;
83  }
84 
93  public function updateButton($buttonId, $key, $data)
94  {
95  $this->buttonList->update($buttonId, $key, $data);
96  return $this;
97  }
98 
102  protected function _prepareLayout()
103  {
104  $this->buttonList->add(
105  'back',
106  [
107  'label' => __('Back'),
108  'onclick' => 'window.location.href=\'' . $this->getUrl('tax/*/') . '\'',
109  'class' => 'back'
110  ]
111  );
112 
113  $this->buttonList->add(
114  'reset',
115  ['label' => __('Reset'), 'onclick' => 'window.location.reload()', 'class' => 'reset']
116  );
117 
118  $rate = intval($this->getRequest()->getParam('rate'));
119  if ($rate) {
120  $this->buttonList->add(
121  'delete',
122  [
123  'label' => __('Delete Rate'),
124  'onclick' => 'deleteConfirm(\'' . __(
125  'Are you sure you want to do this?'
126  ) . '\', \'' . $this->getUrl(
127  'tax/*/delete',
128  ['rate' => $rate]
129  ) . '\')',
130  'class' => 'delete'
131  ]
132  );
133  }
134 
135  $this->buttonList->add(
136  'save',
137  [
138  'label' => __('Save Rate'),
139  'class' => 'save primary save-rate',
140  'data_attribute' => [
141  'mage-init' => ['button' => ['event' => 'save', 'target' => '#rate-form']],
142  ]
143  ]
144  );
145  $this->toolbar->pushButtons($this, $this->buttonList);
146  return parent::_prepareLayout();
147  }
148 
155  public function canRender(\Magento\Backend\Block\Widget\Button\Item $item)
156  {
157  return !$item->isDeleted();
158  }
159 }
updateButton($buttonId, $key, $data)
Definition: Save.php:93
if( $form)() ?>< script > require(['jquery' mage mage
Definition: save.phtml:15
__()
Definition: __.php:13
__construct(\Magento\Backend\Block\Template\Context $context, \Magento\Backend\Block\Widget\Button\ButtonList $buttonList, \Magento\Backend\Block\Widget\Button\ToolbarInterface $toolbar, array $data=[])
Definition: Save.php:37
jquery extjs ext tree mage adminhtml form
Definition: tree.phtml:41
addButton($buttonId, $data, $level=0, $sortOrder=0, $region='toolbar')
Definition: Save.php:67