Main.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. namespace Dotdigitalgroup\Email\Block\Adminhtml\Rules\Edit\Tab;
  3. /**
  4. * Exclusion rules main tab block
  5. *
  6. * @api
  7. */
  8. class Main extends \Magento\Backend\Block\Widget\Form\Generic implements \Magento\Backend\Block\Widget\Tab\TabInterface
  9. {
  10. /**
  11. * @var \Magento\Store\Model\System\Store
  12. */
  13. public $systemStore;
  14. /**
  15. * Main constructor.
  16. *
  17. * @param \Magento\Backend\Block\Widget\Context $context
  18. * @param \Magento\Framework\Registry $registry
  19. * @param \Magento\Framework\Data\FormFactory $formFactory
  20. * @param \Magento\Store\Model\System\Store $systemStore
  21. * @param array $data
  22. */
  23. public function __construct(
  24. \Magento\Backend\Block\Widget\Context $context,
  25. \Magento\Framework\Registry $registry,
  26. \Magento\Framework\Data\FormFactory $formFactory,
  27. \Magento\Store\Model\System\Store $systemStore,
  28. array $data = []
  29. ) {
  30. $this->systemStore = $systemStore;
  31. parent::__construct($context, $registry, $formFactory, $data);
  32. }
  33. /**
  34. * Prepare content for tab.
  35. *
  36. * @return string
  37. */
  38. public function getTabLabel()
  39. {
  40. return __('Rule Information');
  41. }
  42. /**
  43. * Prepare title for tab.
  44. *
  45. * @return string
  46. */
  47. public function getTabTitle()
  48. {
  49. return __('Rule Information');
  50. }
  51. /**
  52. * Returns status flag about this tab can be showed or not.
  53. *
  54. * @return true
  55. */
  56. public function canShowTab()
  57. {
  58. return true;
  59. }
  60. /**
  61. * Returns status flag about this tab hidden or not.
  62. *
  63. * @return true
  64. */
  65. public function isHidden()
  66. {
  67. return false;
  68. }
  69. /**
  70. * @return \Magento\Backend\Block\Widget\Form\Generic
  71. *
  72. * @throws \Magento\Framework\Exception\LocalizedException
  73. */
  74. public function _prepareForm()
  75. {
  76. $model = $this->_coreRegistry->registry('current_ddg_rule');
  77. $form = $this->_formFactory->create();
  78. $form->setHtmlIdPrefix('rule_');
  79. $fieldset = $form->addFieldset(
  80. 'base_fieldset',
  81. ['legend' => __('Rule Information')]
  82. );
  83. if ($model->getId()) {
  84. $fieldset->addField('id', 'hidden', [
  85. 'name' => 'id',
  86. ]);
  87. }
  88. $fieldset->addField('name', 'text', [
  89. 'name' => 'name',
  90. 'label' => __('Rule Name'),
  91. 'title' => __('Rule Name'),
  92. 'required' => true,
  93. ]);
  94. $fieldset->addField('type', 'select', [
  95. 'label' => __('Rule Type'),
  96. 'title' => __('Rule Type'),
  97. 'name' => 'type',
  98. 'required' => true,
  99. 'options' => [
  100. \Dotdigitalgroup\Email\Model\Rules::ABANDONED => 'Abandoned Cart Exclusion Rule',
  101. \Dotdigitalgroup\Email\Model\Rules::REVIEW => 'Review Email Exclusion Rule',
  102. ],
  103. ]);
  104. $fieldset->addField('status', 'select', [
  105. 'label' => __('Status'),
  106. 'title' => __('Status'),
  107. 'name' => 'status',
  108. 'required' => true,
  109. 'options' => [
  110. '1' => __('Active'),
  111. '0' => __('Inactive'),
  112. ],
  113. ]);
  114. if (!$model->getId()) {
  115. $model->setData('status', '0');
  116. }
  117. if ($this->_storeManager->isSingleStoreMode()) {
  118. $websiteId = $this->_storeManager->getStore(true)->getWebsiteId();
  119. $fieldset->addField(
  120. 'website_ids',
  121. 'hidden',
  122. ['name' => 'website_ids[]', 'value' => $websiteId]
  123. );
  124. $model->setWebsiteIds($websiteId);
  125. } else {
  126. $field = $fieldset->addField(
  127. 'website_ids',
  128. 'multiselect',
  129. [
  130. 'name' => 'website_ids[]',
  131. 'label' => __('Websites'),
  132. 'title' => __('Websites'),
  133. 'required' => true,
  134. 'values' => $this->systemStore->getWebsiteValuesForForm(),
  135. ]
  136. );
  137. $renderer = $this->getLayout()->createBlock(
  138. \Magento\Backend\Block\Store\Switcher\Form\Renderer\Fieldset\Element::class
  139. );
  140. $field->setRenderer($renderer);
  141. }
  142. $form->setValues($model->getData());
  143. $this->setForm($form);
  144. return parent::_prepareForm();
  145. }
  146. }