123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Backend\Block\Widget\Grid;
- /**
- * Backend grid container block
- *
- *
- * @SuppressWarnings(PHPMD.NumberOfChildren)
- * @api
- * @deprecated 100.2.0 in favour of UI component implementation
- * @since 100.0.2
- */
- class Container extends \Magento\Backend\Block\Widget\Container
- {
- /**#@+
- * Initialization parameters in pseudo-constructor
- */
- const PARAM_BLOCK_GROUP = 'block_group';
- const PARAM_BUTTON_NEW = 'button_new';
- const PARAM_BUTTON_BACK = 'button_back';
- /**#@-*/
- /**#@-*/
- protected $_addButtonLabel;
- /**
- * @var string
- */
- protected $_backButtonLabel;
- /**
- * @var string
- */
- protected $_blockGroup = 'Magento_Backend';
- /**
- * @var string
- */
- protected $_template = 'Magento_Backend::widget/grid/container.phtml';
- /**
- * Initialize object state with incoming parameters
- *
- * @return void
- */
- protected function _construct()
- {
- parent::_construct();
- if ($this->hasData(self::PARAM_BLOCK_GROUP)) {
- $this->_blockGroup = $this->_getData(self::PARAM_BLOCK_GROUP);
- }
- if ($this->hasData(self::PARAM_BUTTON_NEW)) {
- $this->_addButtonLabel = $this->_getData(self::PARAM_BUTTON_NEW);
- } else {
- // legacy logic to support all descendants
- if ($this->_addButtonLabel === null) {
- $this->_addButtonLabel = __('Add New');
- }
- $this->_addNewButton();
- }
- if ($this->hasData(self::PARAM_BUTTON_BACK)) {
- $this->_backButtonLabel = $this->_getData(self::PARAM_BUTTON_BACK);
- } else {
- // legacy logic
- if ($this->_backButtonLabel === null) {
- $this->_backButtonLabel = __('Back');
- }
- }
- }
- /**
- * {@inheritdoc}
- */
- protected function _prepareLayout()
- {
- // check if grid was created through the layout
- if (false === $this->getChildBlock('grid')) {
- $this->setChild(
- 'grid',
- $this->getLayout()->createBlock(
- str_replace(
- '_',
- '\\',
- $this->_blockGroup
- ) . '\\Block\\' . str_replace(
- ' ',
- '\\',
- ucwords(str_replace('_', ' ', $this->_controller))
- ) . '\\Grid',
- $this->_controller . '.grid'
- )->setSaveParametersInSession(
- true
- )
- );
- }
- return parent::_prepareLayout();
- }
- /**
- * @return string
- */
- public function getCreateUrl()
- {
- return $this->getUrl('*/*/new');
- }
- /**
- * @return string
- */
- public function getGridHtml()
- {
- return $this->getChildHtml('grid');
- }
- /**
- * @return string
- */
- public function getAddButtonLabel()
- {
- return $this->_addButtonLabel;
- }
- /**
- * @return string
- */
- public function getBackButtonLabel()
- {
- return $this->_backButtonLabel;
- }
- /**
- * Create "New" button
- *
- * @return void
- */
- protected function _addNewButton()
- {
- $this->addButton(
- 'add',
- [
- 'label' => $this->getAddButtonLabel(),
- 'onclick' => 'setLocation(\'' . $this->getCreateUrl() . '\')',
- 'class' => 'add primary'
- ]
- );
- }
- /**
- * @return void
- */
- protected function _addBackButton()
- {
- $this->addButton(
- 'back',
- [
- 'label' => $this->getBackButtonLabel(),
- 'onclick' => 'setLocation(\'' . $this->getBackUrl() . '\')',
- 'class' => 'back'
- ]
- );
- }
- /**
- * {@inheritdoc}
- */
- public function getHeaderCssClass()
- {
- return 'icon-head ' . parent::getHeaderCssClass();
- }
- /**
- * @return string
- */
- public function getHeaderWidth()
- {
- return 'width:50%;';
- }
- }
|