-
Notifications
You must be signed in to change notification settings - Fork 21
/
General.php
222 lines (196 loc) · 6.15 KB
/
General.php
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<?php
namespace ScandiPWA\MenuOrganizer\Block\Adminhtml\Menu\Edit\Tab;
use Magento\Backend\Block\Widget\Form\Generic;
use Magento\Backend\Block\Widget\Tab\TabInterface;
/**
* @category ScandiPWA
* @package ScandiPWA\MenuOrganizer\Block\Adminhtml\Menu\Edit\Tab
* @copyright Copyright (c) 2015 Scandiweb, Ltd (http://scandiweb.com)
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*
* Menu create/edit form main tab
*
* Class General
*/
class General extends Generic implements TabInterface
{
/**
* @var \Magento\Store\Model\System\Store
*/
protected $_systemStore;
/**
* @param \Magento\Backend\Block\Template\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\Template\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\Data\FormFactory $formFactory,
\Magento\Store\Model\System\Store $systemStore,
\ScandiPWA\MenuOrganizer\Helper\Adminhtml\Data $menumanagerHelper,
array $data = []
) {
$this->_systemStore = $systemStore;
$this->_menumanagerHelper = $menumanagerHelper;
parent::__construct($context, $registry, $formFactory, $data);
}
/**
* Prepare form
*
* @return $this
*/
protected function _prepareForm()
{
/** @var \ScandiPWA\MenuOrganizer\Model\Menu $model */
$model = $this->_coreRegistry->registry('scandipwa_menuorganizer_menu');
/** @var \Magento\Framework\Data\Form $form */
$form = $this->_formFactory->create(
[
'data' => [
'id' => 'edit_form',
'action' => $this->getData('action'),
'method' => 'post',
]
]
);
$form->setHtmlIdPrefix('menu_');
$fieldset = $form->addFieldset(
'base_fieldset',
['legend' => __('General Information'), 'class' => 'fieldset-wide']
);
$fieldset->addField(
'title',
'text',
[
'name' => 'menu[title]',
'label' => __('Menu Title'),
'title' => __('Menu Title'),
'required' => true
]
);
$fieldset->addField(
'identifier',
'text',
[
'name' => 'menu[identifier]',
'label' => __('Menu Identifier'),
'title' => __('Menu Identifier'),
'required' => true,
'class' => 'validate-xml-identifier'
]
);
$fieldset->addField(
'css_class',
'text',
[
'name' => 'menu[css_class]',
'label' => __('Custom Menu CSS Class'),
'title' => __('Custom Menu CSS Class'),
'required' => false,
]
);
$fieldset->addField(
'is_active',
'select',
[
'name' => 'menu[is_active]',
'label' => __('Menu Status'),
'title' => __('Menu Status'),
'required' => true,
'options' => $this->_menumanagerHelper->getAvailableStatuses(),
]
);
$this->_addStoreRenderer($fieldset);
if (!$model->getId()) {
$model->setData('is_active', \ScandiPWA\MenuOrganizer\Helper\Adminhtml\Data::STATUS_ENABLED);
}
$this->_eventManager->dispatch('scandipwa_menuorganizer_menu_edit_tab_general_prepare_form', ['form' => $form]);
$form->setValues($model->getData());
$this->setForm($form);
return parent::_prepareForm();
}
/**
* Add store view multiselect field.
*
* @param $fieldset
*
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _addStoreRenderer(\Magento\Framework\Data\Form\Element\Fieldset $fieldset)
{
/** @var \ScandiPWA\MenuOrganizer\Model\Menu $model */
$model = $this->_coreRegistry->registry('scandipwa_menuorganizer_menu');
if (!$this->_storeManager->isSingleStoreMode()) {
$field = $fieldset->addField(
'store_id',
'multiselect',
[
'label' => __('Store'),
'title' => __('Store'),
'values' => $this->_systemStore->getStoreValuesForForm(false, true),
'name' => 'menu[store_id]',
'required' => false
]
);
$renderer = $this->getLayout()->createBlock(
'Magento\Backend\Block\Store\Switcher\Form\Renderer\Fieldset\Element'
);
$field->setRenderer($renderer);
} else {
$fieldset->addField(
'store_id',
'hidden',
['name' => 'menu[store_id]', 'value' => $this->_storeManager->getStore(true)->getId()]
);
}
if (!$model->getId()) {
$model->setData('store_id', 0);
}
}
/**
* Prepare label for tab
*
* @return \Magento\Framework\Phrase
*/
public function getTabLabel()
{
return __('General Information');
}
/**
* Prepare title for tab
*
* @return \Magento\Framework\Phrase
*/
public function getTabTitle()
{
return __('General Information');
}
/**
* {@inheritdoc}
*/
public function canShowTab()
{
return true;
}
/**
* {@inheritdoc}
*/
public function isHidden()
{
return false;
}
/**
* Check permission for passed action
*
* @param string $resourceId
* @return bool
*/
protected function _isAllowedAction($resourceId)
{
return $this->_authorization->isAllowed($resourceId);
}
}