Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Container.php
Go to the documentation of this file.
1 <?php
7 
16 class Container extends \Magento\Backend\Block\Widget\Container
17 {
21  protected $_objectId = 'id';
22 
26  protected $_formScripts = [];
27 
31  protected $_formInitScripts = [];
32 
36  protected $_mode = 'edit';
37 
41  protected $_blockGroup = 'Magento_Backend';
42 
46  const PARAM_BLOCK_GROUP = 'block_group';
47 
51  const PARAM_MODE = 'mode';
52 
56  protected $_template = 'Magento_Backend::widget/form/container.phtml';
57 
61  protected function _construct()
62  {
63  parent::_construct();
64  if ($this->hasData(self::PARAM_BLOCK_GROUP)) {
65  $this->_blockGroup = $this->_getData(self::PARAM_BLOCK_GROUP);
66  }
67  if ($this->hasData(self::PARAM_MODE)) {
68  $this->_mode = $this->_getData(self::PARAM_MODE);
69  }
70 
71  $this->addButton(
72  'back',
73  [
74  'label' => __('Back'),
75  'onclick' => 'setLocation(\'' . $this->getBackUrl() . '\')',
76  'class' => 'back'
77  ],
78  -1
79  );
80  $this->addButton(
81  'reset',
82  ['label' => __('Reset'), 'onclick' => 'setLocation(window.location.href)', 'class' => 'reset'],
83  -1
84  );
85 
86  $objId = $this->getRequest()->getParam($this->_objectId);
87 
88  if (!empty($objId)) {
89  $this->addButton(
90  'delete',
91  [
92  'label' => __('Delete'),
93  'class' => 'delete',
94  'onclick' => 'deleteConfirm(\'' . __(
95  'Are you sure you want to do this?'
96  ) . '\', \'' . $this->getDeleteUrl() . '\', {data: {}})'
97  ]
98  );
99  }
100 
101  $this->addButton(
102  'save',
103  [
104  'label' => __('Save'),
105  'class' => 'save primary',
106  'data_attribute' => [
107  'mage-init' => ['button' => ['event' => 'save', 'target' => '#edit_form']],
108  ]
109  ],
110  1
111  );
112  }
113 
119  protected function _prepareLayout()
120  {
121  if ($this->_blockGroup && $this->_controller && $this->_mode && !$this->_layout->getChildName(
122  $this->_nameInLayout,
123  'form'
124  )
125  ) {
126  $this->addChild('form', $this->_buildFormClassName());
127  }
128  return parent::_prepareLayout();
129  }
130 
136  protected function _buildFormClassName()
137  {
138  return $this->nameBuilder->buildClassName(
139  [$this->_blockGroup, 'Block', $this->_controller, $this->_mode, 'Form']
140  );
141  }
142 
148  public function getBackUrl()
149  {
150  return $this->getUrl('*/*/');
151  }
152 
156  public function getDeleteUrl()
157  {
158  return $this->getUrl('*/*/delete', [$this->_objectId => $this->getRequest()->getParam($this->_objectId)]);
159  }
160 
167  public function getSaveUrl()
168  {
169  return $this->getFormActionUrl();
170  }
171 
177  public function getFormActionUrl()
178  {
179  if ($this->hasFormActionUrl()) {
180  return $this->getData('form_action_url');
181  }
182  return $this->getUrl('*/*/save');
183  }
184 
188  public function getFormHtml()
189  {
190  $this->getChildBlock('form')->setData('action', $this->getSaveUrl());
191  return $this->getChildHtml('form');
192  }
193 
197  public function getFormInitScripts()
198  {
199  if (!empty($this->_formInitScripts) && is_array($this->_formInitScripts)) {
200  return '<script>' . implode("\n", $this->_formInitScripts) . '</script>';
201  }
202  return '';
203  }
204 
208  public function getFormScripts()
209  {
210  if (!empty($this->_formScripts) && is_array($this->_formScripts)) {
211  return '<script>' . implode("\n", $this->_formScripts) . '</script>';
212  }
213  return '';
214  }
215 
219  public function getHeaderWidth()
220  {
221  return '';
222  }
223 
227  public function getHeaderCssClass()
228  {
229  return 'icon-head head-' . strtr($this->_controller, '_', '-');
230  }
231 
235  public function getHeaderHtml()
236  {
237  return '<h3 class="' . $this->getHeaderCssClass() . '">' . $this->getHeaderText() . '</h3>';
238  }
239 
246  public function setDataObject($object)
247  {
248  $this->getChildBlock('form')->setDataObject($object);
249  return $this->setData('data_object', $object);
250  }
251 }
if( $form)() ?>< script > require(['jquery' mage mage
Definition: save.phtml:15
__()
Definition: __.php:13
jquery extjs ext tree mage adminhtml form
Definition: tree.phtml:41
addButton($buttonId, $data, $level=0, $sortOrder=0, $region='toolbar')
Definition: Container.php:85