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