Container.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Backend\Block\Widget\Grid;
  7. /**
  8. * Backend grid container block
  9. *
  10. *
  11. * @SuppressWarnings(PHPMD.NumberOfChildren)
  12. * @api
  13. * @deprecated 100.2.0 in favour of UI component implementation
  14. * @since 100.0.2
  15. */
  16. class Container extends \Magento\Backend\Block\Widget\Container
  17. {
  18. /**#@+
  19. * Initialization parameters in pseudo-constructor
  20. */
  21. const PARAM_BLOCK_GROUP = 'block_group';
  22. const PARAM_BUTTON_NEW = 'button_new';
  23. const PARAM_BUTTON_BACK = 'button_back';
  24. /**#@-*/
  25. /**#@-*/
  26. protected $_addButtonLabel;
  27. /**
  28. * @var string
  29. */
  30. protected $_backButtonLabel;
  31. /**
  32. * @var string
  33. */
  34. protected $_blockGroup = 'Magento_Backend';
  35. /**
  36. * @var string
  37. */
  38. protected $_template = 'Magento_Backend::widget/grid/container.phtml';
  39. /**
  40. * Initialize object state with incoming parameters
  41. *
  42. * @return void
  43. */
  44. protected function _construct()
  45. {
  46. parent::_construct();
  47. if ($this->hasData(self::PARAM_BLOCK_GROUP)) {
  48. $this->_blockGroup = $this->_getData(self::PARAM_BLOCK_GROUP);
  49. }
  50. if ($this->hasData(self::PARAM_BUTTON_NEW)) {
  51. $this->_addButtonLabel = $this->_getData(self::PARAM_BUTTON_NEW);
  52. } else {
  53. // legacy logic to support all descendants
  54. if ($this->_addButtonLabel === null) {
  55. $this->_addButtonLabel = __('Add New');
  56. }
  57. $this->_addNewButton();
  58. }
  59. if ($this->hasData(self::PARAM_BUTTON_BACK)) {
  60. $this->_backButtonLabel = $this->_getData(self::PARAM_BUTTON_BACK);
  61. } else {
  62. // legacy logic
  63. if ($this->_backButtonLabel === null) {
  64. $this->_backButtonLabel = __('Back');
  65. }
  66. }
  67. }
  68. /**
  69. * {@inheritdoc}
  70. */
  71. protected function _prepareLayout()
  72. {
  73. // check if grid was created through the layout
  74. if (false === $this->getChildBlock('grid')) {
  75. $this->setChild(
  76. 'grid',
  77. $this->getLayout()->createBlock(
  78. str_replace(
  79. '_',
  80. '\\',
  81. $this->_blockGroup
  82. ) . '\\Block\\' . str_replace(
  83. ' ',
  84. '\\',
  85. ucwords(str_replace('_', ' ', $this->_controller))
  86. ) . '\\Grid',
  87. $this->_controller . '.grid'
  88. )->setSaveParametersInSession(
  89. true
  90. )
  91. );
  92. }
  93. return parent::_prepareLayout();
  94. }
  95. /**
  96. * @return string
  97. */
  98. public function getCreateUrl()
  99. {
  100. return $this->getUrl('*/*/new');
  101. }
  102. /**
  103. * @return string
  104. */
  105. public function getGridHtml()
  106. {
  107. return $this->getChildHtml('grid');
  108. }
  109. /**
  110. * @return string
  111. */
  112. public function getAddButtonLabel()
  113. {
  114. return $this->_addButtonLabel;
  115. }
  116. /**
  117. * @return string
  118. */
  119. public function getBackButtonLabel()
  120. {
  121. return $this->_backButtonLabel;
  122. }
  123. /**
  124. * Create "New" button
  125. *
  126. * @return void
  127. */
  128. protected function _addNewButton()
  129. {
  130. $this->addButton(
  131. 'add',
  132. [
  133. 'label' => $this->getAddButtonLabel(),
  134. 'onclick' => 'setLocation(\'' . $this->getCreateUrl() . '\')',
  135. 'class' => 'add primary'
  136. ]
  137. );
  138. }
  139. /**
  140. * @return void
  141. */
  142. protected function _addBackButton()
  143. {
  144. $this->addButton(
  145. 'back',
  146. [
  147. 'label' => $this->getBackButtonLabel(),
  148. 'onclick' => 'setLocation(\'' . $this->getBackUrl() . '\')',
  149. 'class' => 'back'
  150. ]
  151. );
  152. }
  153. /**
  154. * {@inheritdoc}
  155. */
  156. public function getHeaderCssClass()
  157. {
  158. return 'icon-head ' . parent::getHeaderCssClass();
  159. }
  160. /**
  161. * @return string
  162. */
  163. public function getHeaderWidth()
  164. {
  165. return 'width:50%;';
  166. }
  167. }