-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
Copy pathEdit.php
302 lines (274 loc) · 7.56 KB
/
Edit.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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* Newsletter Template Edit Block
*/
namespace Magento\Newsletter\Block\Adminhtml\Template;
use Magento\Backend\Block\Widget;
use Magento\Framework\App\TemplateTypesInterface;
/**
* @api
* @since 100.0.2
*/
class Edit extends Widget
{
/**
* @var \Magento\Framework\Registry
*/
protected $_coreRegistry = null;
/**
* @var \Magento\Cms\Model\Wysiwyg\Config
*/
protected $_wysiwygConfig;
/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig
* @param \Magento\Framework\Registry $registry
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig,
\Magento\Framework\Registry $registry,
array $data = []
) {
$this->_coreRegistry = $registry;
$this->_wysiwygConfig = $wysiwygConfig;
parent::__construct($context, $data);
}
/**
* Retrieve template object
*
* @return \Magento\Newsletter\Model\Template
*/
public function getModel()
{
return $this->_coreRegistry->registry('_current_template');
}
/**
* Preparing block layout
*
* @return $this
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
protected function _prepareLayout()
{
$this->getToolbar()->addChild(
'back_button',
\Magento\Backend\Block\Widget\Button::class,
[
'label' => __('Back'),
'onclick' => "window.location.href = '" . $this->getUrl('*/*') . "'",
'class' => 'action-back'
]
);
$this->getToolbar()->addChild(
'reset_button',
\Magento\Backend\Block\Widget\Button::class,
[
'label' => __('Reset'),
'onclick' => 'window.location.href = window.location.href',
'class' => 'reset'
]
);
if (!$this->isTextType()) {
$this->getToolbar()->addChild(
'to_plain_button',
\Magento\Backend\Block\Widget\Button::class,
[
'label' => __('Convert to Plain Text'),
'data_attribute' => [
'role' => 'template-strip',
],
'id' => 'convert_button',
'class' => 'convert'
]
);
$this->getToolbar()->addChild(
'to_html_button',
\Magento\Backend\Block\Widget\Button::class,
[
'label' => __('Return HTML Version'),
'data_attribute' => [
'role' => 'template-unstrip',
],
'id' => 'convert_button_back',
'style' => 'display:none',
'class' => 'return'
]
);
}
$this->getToolbar()->addChild(
'preview_button',
\Magento\Backend\Block\Widget\Button::class,
[
'label' => __('Preview Template'),
'data_attribute' => [
'role' => 'template-preview',
],
'class' => 'preview'
]
);
if ($this->getEditMode()) {
$this->getToolbar()->addChild(
'delete_button',
\Magento\Backend\Block\Widget\Button::class,
[
'label' => __('Delete Template'),
'data_attribute' => [
'role' => 'template-delete',
],
'class' => 'delete'
]
);
$this->getToolbar()->addChild(
'save_as_button',
\Magento\Backend\Block\Widget\Button::class,
[
'label' => __('Save As'),
'data_attribute' => [
'role' => 'template-save-as',
],
'class' => 'save-as'
]
);
}
$this->getToolbar()->addChild(
'save_button',
\Magento\Backend\Block\Widget\Button::class,
[
'label' => __('Save Template'),
'data_attribute' => [
'role' => 'template-save',
],
'class' => 'save primary'
]
);
return parent::_prepareLayout();
}
/**
* Return edit flag for block
*
* @return boolean
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
*/
public function getEditMode()
{
if ($this->getModel()->getId()) {
return true;
}
return false;
}
/**
* Return header text for form
*
* @return \Magento\Framework\Phrase
*/
public function getHeaderText()
{
if ($this->getEditMode()) {
return __('Edit Newsletter Template');
}
return __('New Newsletter Template');
}
/**
* Return form block HTML
*
* @return string
*/
public function getForm()
{
return $this->getLayout()->createBlock(
\Magento\Newsletter\Block\Adminhtml\Template\Edit\Form::class
)->toHtml();
}
/**
* Return template name for JS
*
* @return string
*/
public function getJsTemplateName()
{
$templateCode = $this->getModel()->getTemplateCode();
// phpcs:ignore Magento2.Functions.DiscouragedFunction
return $templateCode ? addcslashes($templateCode, "\"\r\n\\") : '';
}
/**
* Return action url for form
*
* @return string
*/
public function getSaveUrl()
{
return $this->getUrl('*/*/save');
}
/**
* Return preview action url for form
*
* @return string
*/
public function getPreviewUrl()
{
return $this->getUrl('*/*/preview', ['id' => $this->getRequest()->getParam('id')]);
}
/**
* Check Template Type is Plain Text
*
* @return bool
*/
public function isTextType()
{
return $this->getModel()->isPlain();
}
/**
* Return template type from template object or TYPE_HTML by default
*
* @return int
*/
public function getTemplateType()
{
if ($this->getModel()->getTemplateType()) {
return $this->getModel()->getTemplateType();
}
return TemplateTypesInterface::TYPE_HTML;
}
/**
* Return delete url for customer group
*
* @return string
*/
public function getDeleteUrl()
{
return $this->getUrl('*/*/delete', ['id' => $this->getRequest()->getParam('id')]);
}
/**
* Retrieve Save As Flag
*
* @return int
*/
public function getSaveAsFlag()
{
return $this->getRequest()->getParam('_save_as_flag') ? '1' : '';
}
/**
* Getter for single store mode check
*
* @return boolean
*/
protected function isSingleStoreMode()
{
return $this->_storeManager->isSingleStoreMode();
}
/**
* Getter for id of current store (the only one in single-store mode and current in multi-stores mode)
*
* @return int
*/
protected function getStoreId()
{
return $this->_storeManager->getStore(true)->getId();
}
}