Add.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Admin tax class product toolbar
  8. *
  9. * @author Magento Core Team <core@magentocommerce.com>
  10. */
  11. namespace Magento\Tax\Block\Adminhtml\Rate\Toolbar;
  12. /**
  13. * @api
  14. * @since 100.0.2
  15. */
  16. class Add extends \Magento\Backend\Block\Template implements \Magento\Backend\Block\Widget\ContainerInterface
  17. {
  18. /**
  19. * @var string
  20. */
  21. protected $_template = 'Magento_Tax::toolbar/rate/add.phtml';
  22. /**
  23. * @var \Magento\Backend\Block\Widget\Button\ButtonList
  24. */
  25. protected $buttonList;
  26. /**
  27. * @var \Magento\Backend\Block\Widget\Button\ToolbarInterface
  28. */
  29. protected $toolbar;
  30. /**
  31. * @param \Magento\Backend\Block\Template\Context $context
  32. * @param \Magento\Backend\Block\Widget\Button\ButtonList $buttonList
  33. * @param \Magento\Backend\Block\Widget\Button\ToolbarInterface $toolbar
  34. * @param array $data
  35. */
  36. public function __construct(
  37. \Magento\Backend\Block\Template\Context $context,
  38. \Magento\Backend\Block\Widget\Button\ButtonList $buttonList,
  39. \Magento\Backend\Block\Widget\Button\ToolbarInterface $toolbar,
  40. array $data = []
  41. ) {
  42. $this->buttonList = $buttonList;
  43. $this->toolbar = $toolbar;
  44. parent::__construct($context, $data);
  45. }
  46. /**
  47. * {$@inheritdoc}
  48. */
  49. public function addButton($buttonId, $data, $level = 0, $sortOrder = 0, $region = 'toolbar')
  50. {
  51. $this->buttonList->add($buttonId, $data, $level, $sortOrder, $region);
  52. return $this;
  53. }
  54. /**
  55. * {$@inheritdoc}
  56. */
  57. public function removeButton($buttonId)
  58. {
  59. $this->buttonList->remove($buttonId);
  60. return $this;
  61. }
  62. /**
  63. * @return $this
  64. */
  65. protected function _prepareLayout()
  66. {
  67. $this->buttonList->add(
  68. 'add',
  69. [
  70. 'label' => __('Add New Tax Rate'),
  71. 'onclick' => 'window.location.href=\'' . $this->getUrl('tax/rate/add') . '\'',
  72. 'class' => 'add primary add-tax-rate'
  73. ]
  74. );
  75. $this->toolbar->pushButtons($this, $this->buttonList);
  76. return parent::_prepareLayout();
  77. }
  78. /**
  79. * {$@inheritdoc}
  80. */
  81. public function updateButton($buttonId, $key, $data)
  82. {
  83. $this->buttonList->update($buttonId, $key, $data);
  84. return $this;
  85. }
  86. /**
  87. * {$@inheritdoc}
  88. */
  89. public function canRender(\Magento\Backend\Block\Widget\Button\Item $item)
  90. {
  91. return !$item->isDeleted();
  92. }
  93. }