Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
edit.phtml
Go to the documentation of this file.
1 <?php
8 
9 // @codingStandardsIgnoreFile
10 
12 ?>
13 <?php if (!$block->getEditMode()): ?>
14 <form action="<?= $block->escapeUrl($block->getLoadUrl()) ?>" method="post" id="email_template_load_form">
15  <?= $block->getBlockHtml('formkey') ?>
16  <fieldset class="admin__fieldset form-inline">
17  <legend class="admin__legend"><span><?= $block->escapeHtml(__('Load default template')) ?></span></legend><br>
18  <div class="admin__field">
19  <label class="admin__field-label" for="template_select"><?= $block->escapeHtml(__('Template')) ?></label>
20  <div class="admin__field-control">
21  <select id="template_select" name="code" class="admin__control-select required-entry">
22  <?php foreach ($block->getTemplateOptions() as $group => $options): ?>
23  <?php if ($group): ?>
24  <optgroup label="<?= $block->escapeHtmlAttr($group) ?>">
25  <?php endif; ?>
26  <?php foreach ($options as $option): ?>
27  <option value="<?= $block->escapeHtmlAttr($option['value']) ?>"<?= /* @noEscape */ $block->getOrigTemplateCode() == $option['value'] ? ' selected="selected"' : '' ?>><?= $block->escapeHtml($option['label']) ?></option>
28  <?php endforeach; ?>
29  <?php if ($group): ?>
30  </optgroup>
31  <?php endif; ?>
32  <?php endforeach; ?>
33  </select>
34  </div>
35  </div>
36  <div class="admin__field required">
37  <span class="admin__field-label"></span>
38  <div class="admin__field-control">
39  <?= /* @noEscape */ $block->getLoadButtonHtml() ?>
40  </div>
41  </div>
42  </fieldset>
43 </form>
44 <?php endif ?>
45 
46 <form action="<?= $block->escapeUrl($block->getSaveUrl()) ?>" method="post" id="email_template_edit_form">
47  <?= /* @noEscape */ $block->getBlockHtml('formkey') ?>
48  <input type="hidden" id="change_flag_element" name="_change_type_flag" value="" />
49  <input type="hidden" id="orig_template_code" name="orig_template_code" value="<?= $block->escapeHtmlAttr($block->getOrigTemplateCode()) ?>" />
50  <?= /* @noEscape */ $block->getFormHtml() ?>
51 </form>
52 
53 <form action="<?= $block->escapeUrl($block->getPreviewUrl()) ?>" method="post" id="email_template_preview_form" target="_blank">
54  <?= /* @noEscape */ $block->getBlockHtml('formkey') ?>
55  <div class="no-display">
56  <input type="hidden" id="preview_type" name="type" value="<?= /* @noEscape */ $block->isTextType() ? 1 : 2 ?>" />
57  <input type="hidden" id="preview_text" name="text" value="" />
58  <input type="hidden" id="preview_styles" name="styles" value="" />
59  </div>
60 </form>
61 <script>
62 require([
63  "jquery",
64  "wysiwygAdapter",
65  "Magento_Ui/js/modal/alert",
66  "mage/mage",
67  "Magento_Email/js/variables",
68  "prototype"
69 ], function(jQuery, tinyMCE, alert){
70 
71 //<![CDATA[
72  jQuery('#email_template_edit_form').mage('form').mage('validation');
73  jQuery('#email_template_preview_form').mage('form').mage('validation');
74  jQuery('#email_template_load_form').mage('validation');
75  templateControl = {
76  unconvertedText: '',
77  typeChange: false,
78  variables: null,
79 
80  events: {
81  'click [data-role=template-save]' : 'save',
82  'click [data-role=template-preview]' : 'preview',
83  'click [data-role=template-unstrip]' : 'unStripTags',
84  'click [data-role=template-strip]' : 'stripTags',
85  'click [data-role=template-delete]': 'deleteTemplate',
86  'click [data-role=template-load]': 'load'
87  },
88 
89  init: function () {
90  if ($('convert_button_back')) {
91  $('convert_button_back').hide();
92  }
93 
94  this.bindEvents();
95 
96  this.renderPaths(<?= /* @noEscape */ $block->getCurrentlyUsedForPaths() ?>, 'currently_used_for');
97  },
98 
99  bindEvents: function(){
100  var events = this.events,
101  eventName,
102  selector,
103  callback,
104  key;
105 
106  for( key in events ){
107  callback = this[events[key]];
108  key = key.split(' ');
109 
110  eventName = key[0];
111  selector = key.slice(1).join(' ');
112 
113  jQuery(selector).on(eventName, jQuery.proxy(callback, this) );
114  }
115  },
116 
117  stripTags: function () {
118  if(!window.confirm("<?= $block->escapeJs($block->escapeHtml(__('Are you sure you want to strip tags?'))) ?>")) {
119  return false;
120  }
121  this.unconvertedText = $('template_text').value;
122  $('convert_button').hide();
123  $('template_text').value = $('template_text').value.stripScripts().replace(
124  new RegExp('<style[^>]*>[\\S\\s]*?</style>', 'img'), ''
125  ).stripTags().strip();
126  $('convert_button_back').show();
127  $('field_template_styles').hide();
128  this.typeChange = true;
129  return false;
130  },
131  unStripTags: function () {
132  $('convert_button').show();
133  $('convert_button_back').hide();
134  $('template_text').value = this.unconvertedText;
135  $('field_template_styles').show();
136  this.typeChange = false;
137  return false;
138  },
139  save: function() {
140  if (this.typeChange) {
141  $('change_flag_element').value = '1';
142  }
143  // Temporary solution will be replaced after refactoring of email templates functionality
144  jQuery('#email_template_edit_form').triggerHandler('save');
145  return false;
146  },
147  preview: function() {
148  if (this.typeChange) {
149  $('preview_type').value = <?= /* @noEscape */ TemplateTypesInterface::TYPE_TEXT ?>;
150  } else {
151  $('preview_type').value = <?= (int) $block->getTemplateType() ?>;
152  }
153  if (typeof tinyMCE == 'undefined' || !tinyMCE.get('template_text')) {
154  $('preview_text').value = $('template_text').value;
155  } else {
156  $('preview_text').value = tinyMCE.get('template_text').getHTML();
157  }
158 
159  if ($('template_styles') != undefined) {
160  $('preview_styles').value = $('template_styles').value;
161  }
162 
163  // Temporary solution will be replaced after refactoring of email templates functionality
164  jQuery('#email_template_preview_form').triggerHandler('save');
165  return false;
166  },
167 
168  deleteTemplate: function() {
169  if(window.confirm("<?= $block->escapeJs($block->escapeHtml(__('Are you sure you want to delete this template?'))) ?>")) {
170  window.location.href = '<?= $block->escapeJs($block->escapeUrl($block->getDeleteUrl())) ?>';
171  }
172  },
173 
174  load: function() {
175  // Temporary solution will be replaced after refactoring of email templates functionality
176  if (!jQuery('#email_template_load_form').valid()) {
177  return;
178  }
179 
180  this.variables = null;
181 
182  new Ajax.Request($('email_template_load_form').action, {
183  parameters: Form.serialize($('email_template_load_form'), true),
184  area: $('email_template_load_form'),
185  onComplete: function (transport) {
186  if (transport.responseText.isJSON()) {
187  var fields = $H(transport.responseText.evalJSON());
188  fields.each(function(pair) {
189  if ($(pair.key)) {
190  $(pair.key).value = pair.value.strip();
191  }
192  if (pair.key == 'template_type') {
193  if (pair.value == 1) {
194  this.typeChange = true;
195  $('convert_button').hide();
196  $('convert_button_back').hide();
197  } else {
198  this.typeChange = false;
199  $('convert_button_back').hide();
200  $('convert_button').show();
201  }
202  }
203  if (pair.key == 'orig_template_currently_used_for') {
204  if(pair.value.length){
205  $('currently_used_for').show();
206  this.renderPaths(pair.value, 'currently_used_for');
207  }
208  else{
209  $('currently_used_for').hide();
210  }
211  }
212  }.bind(this));
213  } else {
214  alert({
215  content: '<?= $block->escapeJs($block->escapeHtml(__('The template did not load. Please review the log for details.'))) ?>'
216  });
217  }
218  }.bind(this)
219  });
220 
221  },
222 
223  renderPaths: function(paths, fieldId) {
224  var field = $(fieldId);
225  if (field) {
226  field.down('div').down('div').update(this.parsePath(paths, '<span class="path-delimiter">&nbsp;-&gt;&nbsp;</span>', '<br />'));
227  }
228  },
229 
230  parsePath: function (value, pathDelimiter, lineDelimiter) {
231  if (Object.isArray(value)) {
232  var result = [];
233  for (var i = 0, len = value.length; i < len; i++) {
234  result.push(this.parsePath(value[i], pathDelimiter, pathDelimiter));
235  }
236  return result.join(lineDelimiter);
237  }
238 
239  if(!Object.isString(value) && value.title) {
240  value = (value.url ? '<a href="' + value.url + '">' + value.title + '</a>' : value.title) + (value.scope ? '&nbsp;&nbsp;<span class="path-scope-label">(' + value.scope + ')</span>' : '');
241  }
242 
243  return value;
244  },
245 
246  openVariableChooser: function() {
247  Variables.init('template_text');
248  if (this.variables == null) {
249  Variables.resetData();
250  this.variables = $('variables').value.evalJSON();
251  var templateVariablesValue = $('template_variables').value;
252  if (this.variables && templateVariablesValue) {
253  if (templateVariables = templateVariablesValue.evalJSON()) {
254  this.variables.push(templateVariables);
255  }
256  }
257  }
258  if (this.variables) {
259  Variables.openVariableChooser(this.variables);
260  }
261  }
262  };
263 
264  templateControl.init();
265 //]]>
266 
267 });
268 </script>
$block setTitle( 'CMS Block Title') -> setIdentifier('fixture_block') ->setContent('< h1 >Fixture Block Title</h1 >< a href=" store url</a><p> Config value
Definition: block.php:9
if(!isset($_button['disabled'])||! $_button['disabled']) if(isset($_button['disabled']) && $_button['disabled']) if(isset($_button['comment'])) endforeach
Definition: edit.phtml:56
if(!defined( 'PHP_VERSION_ID')||!(PHP_VERSION_ID===70002||PHP_VERSION_ID===70004||PHP_VERSION_ID >=70006))
Definition: bootstrap.php:14
$group
Definition: sections.phtml:16
__()
Definition: __.php:13
jquery extjs ext tree mage adminhtml form
Definition: tree.phtml:41
$block
Definition: block.php:8
endif
Definition: edit.phtml:54
jQuery('.store-switcher .dropdown-menu li a').each(function()
Definition: switcher.phtml:203