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
10 
12 
18 {
22  const PARAM_CONTROLLER = 'controller';
23 
24  const PARAM_HEADER_TEXT = 'header_text';
25 
29  protected $_controller = 'empty';
30 
36  protected $_headerText = 'Container Widget Header';
37 
41  protected $buttonList;
42 
46  protected $toolbar;
47 
52  public function __construct(\Magento\Backend\Block\Widget\Context $context, array $data = [])
53  {
54  $this->buttonList = $context->getButtonList();
55  $this->toolbar = $context->getButtonToolbar();
56  parent::__construct($context, $data);
57  }
58 
64  protected function _construct()
65  {
66  parent::_construct();
67  if ($this->hasData(self::PARAM_CONTROLLER)) {
68  $this->_controller = $this->_getData(self::PARAM_CONTROLLER);
69  }
70  if ($this->hasData(self::PARAM_HEADER_TEXT)) {
71  $this->_headerText = $this->_getData(self::PARAM_HEADER_TEXT);
72  }
73  }
74 
85  public function addButton($buttonId, $data, $level = 0, $sortOrder = 0, $region = 'toolbar')
86  {
87  $this->buttonList->add($buttonId, $data, $level, $sortOrder, $region);
88  return $this;
89  }
90 
97  public function removeButton($buttonId)
98  {
99  $this->buttonList->remove($buttonId);
100  return $this;
101  }
102 
111  public function updateButton($buttonId, $key, $data)
112  {
113  $this->buttonList->update($buttonId, $key, $data);
114  return $this;
115  }
116 
122  protected function _prepareLayout()
123  {
124  $this->toolbar->pushButtons($this, $this->buttonList);
125  return parent::_prepareLayout();
126  }
127 
134  public function getButtonsHtml($region = null)
135  {
136  $out = '';
137  foreach ($this->buttonList->getItems() as $buttons) {
139  foreach ($buttons as $item) {
140  if ($region && $region != $item->getRegion()) {
141  continue;
142  }
143  $out .= $this->getChildHtml($item->getButtonKey());
144  }
145  }
146  return $out;
147  }
148 
154  public function getHeaderText()
155  {
156  return $this->_headerText;
157  }
158 
164  public function getHeaderCssClass()
165  {
166  return 'head-' . strtr($this->_controller, '_', '-');
167  }
168 
174  public function getHeaderHtml()
175  {
176  return '<h3 class="' . $this->getHeaderCssClass() . '">' . $this->getHeaderText() . '</h3>';
177  }
178 
184  public function hasFooterButtons()
185  {
186  foreach ($this->buttonList->getItems() as $buttons) {
187  foreach ($buttons as $data) {
188  if (isset($data['region']) && 'footer' == $data['region']) {
189  return true;
190  }
191  }
192  }
193  return false;
194  }
195 
202  public function canRender(Button\Item $item)
203  {
204  return !$item->isDeleted();
205  }
206 }
updateButton($buttonId, $key, $data)
Definition: Container.php:111
addButton($buttonId, $data, $level=0, $sortOrder=0, $region='toolbar')
Definition: Container.php:85
__construct(\Magento\Backend\Block\Widget\Context $context, array $data=[])
Definition: Container.php:52