Item.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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\Massaction;
  7. /**
  8. * Grid widget massaction single action item
  9. *
  10. * @api
  11. * @deprecated 100.2.0 in favour of UI component implementation
  12. * @since 100.0.2
  13. */
  14. class Item extends \Magento\Backend\Block\Widget
  15. {
  16. /**
  17. * @var Extended
  18. */
  19. protected $_massaction = null;
  20. /**
  21. * Set parent massaction block
  22. *
  23. * @param Extended $massaction
  24. * @return $this
  25. */
  26. public function setMassaction($massaction)
  27. {
  28. $this->_massaction = $massaction;
  29. return $this;
  30. }
  31. /**
  32. * Retrieve parent massaction block
  33. *
  34. * @return Extended
  35. */
  36. public function getMassaction()
  37. {
  38. return $this->_massaction;
  39. }
  40. /**
  41. * Set additional action block for this item
  42. *
  43. * @param string|\Magento\Framework\View\Element\AbstractBlock $block
  44. * @return $this
  45. * @throws \Magento\Framework\Exception\LocalizedException
  46. */
  47. public function setAdditionalActionBlock($block)
  48. {
  49. if (is_string($block)) {
  50. $block = $this->getLayout()->createBlock($block);
  51. } elseif (is_array($block)) {
  52. $block = $this->_createFromConfig($block);
  53. } elseif (!$block instanceof \Magento\Framework\View\Element\AbstractBlock) {
  54. throw new \Magento\Framework\Exception\LocalizedException(__('Unknown block type'));
  55. }
  56. $this->setChild('additional_action', $block);
  57. return $this;
  58. }
  59. /**
  60. * @param array $config
  61. * @return \Magento\Framework\View\Element\BlockInterface
  62. */
  63. protected function _createFromConfig(array $config)
  64. {
  65. $type = isset($config['type']) ? $config['type'] : 'default';
  66. switch ($type) {
  67. default:
  68. $blockClass = \Magento\Backend\Block\Widget\Grid\Massaction\Item\Additional\DefaultAdditional::class;
  69. break;
  70. }
  71. $block = $this->getLayout()->createBlock($blockClass);
  72. $block->createFromConfiguration(isset($config['type']) ? $config['config'] : $config);
  73. return $block;
  74. }
  75. /**
  76. * Retrieve additional action block for this item
  77. *
  78. * @return \Magento\Framework\View\Element\AbstractBlock
  79. */
  80. public function getAdditionalActionBlock()
  81. {
  82. return $this->getChildBlock('additional_action');
  83. }
  84. /**
  85. * Retrieve additional action block HTML for this item
  86. *
  87. * @return string
  88. */
  89. public function getAdditionalActionBlockHtml()
  90. {
  91. return $this->getChildHtml('additional_action');
  92. }
  93. }