Template.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Adminhtml system templates page content block
  8. *
  9. * @author Magento Core Team <core@magentocommerce.com>
  10. */
  11. namespace Magento\Email\Block\Adminhtml;
  12. /**
  13. * @api
  14. * @since 100.0.2
  15. */
  16. class Template extends \Magento\Backend\Block\Template implements \Magento\Backend\Block\Widget\ContainerInterface
  17. {
  18. /**
  19. * Template list
  20. *
  21. * @var string
  22. */
  23. protected $_template = 'Magento_Email::template/list.phtml';
  24. /**
  25. * @var \Magento\Backend\Block\Widget\Button\ButtonList
  26. */
  27. protected $buttonList;
  28. /**
  29. * @var \Magento\Backend\Block\Widget\Button\ToolbarInterface
  30. */
  31. protected $toolbar;
  32. /**
  33. * @param \Magento\Backend\Block\Template\Context $context
  34. * @param \Magento\Backend\Block\Widget\Button\ButtonList $buttonList
  35. * @param \Magento\Backend\Block\Widget\Button\ToolbarInterface $toolbar
  36. * @param array $data
  37. */
  38. public function __construct(
  39. \Magento\Backend\Block\Template\Context $context,
  40. \Magento\Backend\Block\Widget\Button\ButtonList $buttonList,
  41. \Magento\Backend\Block\Widget\Button\ToolbarInterface $toolbar,
  42. array $data = []
  43. ) {
  44. $this->buttonList = $buttonList;
  45. $this->toolbar = $toolbar;
  46. parent::__construct($context, $data);
  47. }
  48. /**
  49. * {@inheritdoc}
  50. */
  51. public function updateButton($buttonId, $key, $data)
  52. {
  53. $this->buttonList->update($buttonId, $key, $data);
  54. return $this;
  55. }
  56. /**
  57. * Create add button and grid blocks
  58. *
  59. * @return \Magento\Framework\View\Element\AbstractBlock
  60. */
  61. protected function _prepareLayout()
  62. {
  63. $this->buttonList->add(
  64. 'add',
  65. [
  66. 'label' => __('Add New Template'),
  67. 'onclick' => "window.location='" . $this->getCreateUrl() . "'",
  68. 'class' => 'add primary add-template'
  69. ]
  70. );
  71. $this->toolbar->pushButtons($this, $this->buttonList);
  72. return parent::_prepareLayout();
  73. }
  74. /**
  75. * Get URL for create new email template
  76. *
  77. * @return string
  78. */
  79. public function getCreateUrl()
  80. {
  81. return $this->getUrl('adminhtml/*/new');
  82. }
  83. /**
  84. * {@inheritdoc}
  85. */
  86. public function addButton($buttonId, $data, $level = 0, $sortOrder = 0, $region = 'toolbar')
  87. {
  88. $this->buttonList->add($buttonId, $data, $level, $sortOrder, $region);
  89. return $this;
  90. }
  91. /**
  92. * Get transactional emails page header text
  93. *
  94. * @return \Magento\Framework\Phrase
  95. */
  96. public function getHeaderText()
  97. {
  98. return __('Transactional Emails');
  99. }
  100. /**
  101. * {@inheritdoc}
  102. */
  103. public function removeButton($buttonId)
  104. {
  105. $this->buttonList->remove($buttonId);
  106. return $this;
  107. }
  108. /**
  109. * Get Add New Template button html
  110. *
  111. * @return string
  112. */
  113. protected function getAddButtonHtml()
  114. {
  115. $out = '';
  116. foreach ($this->buttonList->getItems() as $buttons) {
  117. /** @var \Magento\Backend\Block\Widget\Button\Item $item */
  118. foreach ($buttons as $item) {
  119. $out .= $this->getChildHtml($item->getButtonKey());
  120. }
  121. }
  122. return $out;
  123. }
  124. /**
  125. * {@inheritdoc}
  126. */
  127. public function canRender(\Magento\Backend\Block\Widget\Button\Item $item)
  128. {
  129. return !$item->isDeleted();
  130. }
  131. }