-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
Copy pathForm.php
172 lines (156 loc) · 5.29 KB
/
Form.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
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* Newsletter Template Edit Form Block
*/
namespace Magento\Newsletter\Block\Adminhtml\Template\Edit;
class Form extends \Magento\Backend\Block\Widget\Form\Generic
{
/**
* @var \Magento\Cms\Model\Wysiwyg\Config
*/
protected $_wysiwygConfig;
/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Framework\Registry $registry
* @param \Magento\Framework\Data\FormFactory $formFactory
* @param \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\Data\FormFactory $formFactory,
\Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig,
array $data = []
) {
$this->_wysiwygConfig = $wysiwygConfig;
parent::__construct($context, $registry, $formFactory, $data);
}
/**
* Retrieve template object
*
* @return \Magento\Newsletter\Model\Template
*/
public function getModel()
{
return $this->_coreRegistry->registry('_current_template');
}
/**
* Prepare form before rendering HTML
*
* @return $this
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
protected function _prepareForm()
{
$model = $this->getModel();
$identity = $this->_scopeConfig->getValue(
\Magento\Newsletter\Model\Subscriber::XML_PATH_UNSUBSCRIBE_EMAIL_IDENTITY,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
$identityName = $this->_scopeConfig->getValue(
'trans_email/ident_' . $identity . '/name',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
$identityEmail = $this->_scopeConfig->getValue(
'trans_email/ident_' . $identity . '/email',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
/** @var \Magento\Framework\Data\Form $form */
$form = $this->_formFactory->create(
['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']]
);
$fieldset = $form->addFieldset(
'base_fieldset',
['legend' => __('Template Information'), 'class' => 'fieldset-wide']
);
if ($model->getId()) {
$fieldset->addField('id', 'hidden', ['name' => 'id', 'value' => $model->getId()]);
}
$fieldset->addField(
'code',
'text',
[
'name' => 'code',
'label' => __('Template Name'),
'title' => __('Template Name'),
'required' => true,
'value' => $model->getTemplateCode()
]
);
$fieldset->addField(
'subject',
'text',
[
'name' => 'subject',
'label' => __('Template Subject'),
'title' => __('Template Subject'),
'required' => true,
'value' => $model->getTemplateSubject()
]
);
$fieldset->addField(
'sender_name',
'text',
[
'name' => 'sender_name',
'label' => __('Sender Name'),
'title' => __('Sender Name'),
'required' => true,
'value' => $model->getId() !== null ? $model->getTemplateSenderName() : $identityName
]
);
$fieldset->addField(
'sender_email',
'text',
[
'name' => 'sender_email',
'label' => __('Sender Email'),
'title' => __('Sender Email'),
'class' => 'validate-email',
'required' => true,
'value' => $model->getId() !== null ? $model->getTemplateSenderEmail() : $identityEmail
]
);
$widgetFilters = ['is_email_compatible' => 1];
$wysiwygConfig = $this->_wysiwygConfig->getConfig(['widget_filters' => $widgetFilters]);
if ($model->isPlain()) {
$wysiwygConfig->setEnabled(false);
}
$fieldset->addField(
'text',
'editor',
[
'name' => 'text',
'label' => __('Template Content'),
'title' => __('Template Content'),
'required' => true,
'state' => 'html',
'style' => 'height:36em;',
'value' => $model->getTemplateText(),
'config' => $wysiwygConfig
]
);
if (!$model->isPlain()) {
$fieldset->addField(
'template_styles',
'textarea',
[
'name' => 'styles',
'label' => __('Template Styles'),
'container_id' => 'field_template_styles',
'value' => $model->getTemplateStyles()
]
);
}
$form->setAction($this->getUrl('*/*/save'));
$form->setUseContainer(true);
$this->setForm($form);
return parent::_prepareForm();
}
}