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
7 // @codingStandardsIgnoreFile
8 
9 ?>
10 <?php
14 ?>
15 <div class="admin__scope-old">
16  <div class="product-actions">
17  <div id="product-template-suggest-container" class="suggest-expandable">
18  <div class="action-dropdown">
19  <button type="button" class="action-toggle" data-mage-init='{"dropdown":{}}' data-toggle="dropdown">
20  <span><?= /* @escapeNotVerified */ $block->getAttributeSetName() ?></span>
21  </button>
22  <ul class="dropdown-menu">
23  <li><input type="text" id="product-template-suggest" class="search"
24  placeholder="<?= /* @noEscape */ __('start typing to search template') ?>"/></li>
25  </ul>
26  </div>
27  </div>
28 
29  <div class="switcher" onselectstart='return false;'>
30  <input type="checkbox" id="product-online-switcher" name="product-online-switcher" />
31  <label class="switcher-label"
32  for="product-online-switcher"
33  data-text-on="<?= /* @escapeNotVerified */ __('Product online') ?>"
34  data-text-off="<?= /* @escapeNotVerified */ __('Product offline') ?>"
35  title="<?= /* @escapeNotVerified */ __('Product online status') ?>"></label>
36  </div>
37 
38  <?php if ($block->getProductId()): ?>
39  <?= $block->getDeleteButtonHtml() ?>
40  <?php endif; ?>
41  <?php if ($block->getProductSetId()): ?>
42  <?= $block->getChangeAttributeSetButtonHtml() ?>
43  <?= $block->getSaveSplitButtonHtml() ?>
44  <?php endif; ?>
45  <?= $block->getBackButtonHtml() ?>
46  </div>
47 </div>
48 <?php if ($block->getUseContainer()): ?>
49 <form action="<?= /* @escapeNotVerified */ $block->getSaveUrl() ?>" method="post" enctype="multipart/form-data"
50  data-form="edit-product" data-product-id="<?= /* @escapeNotVerified */ $block->getProduct()->getId() ?>">
51 <?php endif; ?>
52  <?= $block->getBlockHtml('formkey') ?>
53  <div data-role="tabs" id="product-edit-form-tabs"></div> <?php /* @TODO: remove id after elimination of setDestElementId('product-edit-form-tabs') */?>
54  <?= $block->getChildHtml('product-type-tabs') ?>
55  <input type="hidden" id="product_type_id" value="<?= /* @escapeNotVerified */ $block->getProduct()->getTypeId() ?>"/>
56  <input type="hidden" id="attribute_set_id" value="<?= /* @escapeNotVerified */ $block->getProduct()->getAttributeSetId() ?>"/>
57  <button type="submit" class="hidden"></button>
58 <?php if ($block->getUseContainer()): ?>
59 </form>
60 <?php endif; ?>
61 <script>
62 require([
63  "jquery",
64  "Magento_Catalog/catalog/type-events",
65  "underscore",
66  "mage/mage",
67  "mage/backend/tabs",
68  "domReady!"
69 ], function($, TypeSwitcher){
70  var $form = $('[data-form=edit-product]');
71  $form.data('typeSwitcher', TypeSwitcher.init());
72 
73  var scriptTagManager = (function($) {
74  var hiddenPrefix = 'hidden',
75  scriptTypeRegExp = /((java|ecma)script)/gi,
76  hiddenScriptType = 'text/' + hiddenPrefix + 'javascript',
77  changeScriptsType = function(source, callback) {
78  var isString = (typeof source === 'string'),
79  div = document.createElement('div'),
80  scripts,
81  scriptsLength;
82  div.innerHTML = isString ? source : $(source).clone().wrap('<p>').parent().html();
83  scripts = div.getElementsByTagName('script');
84  scriptsLength = scripts.length;
85  for (var i = 0; i < scriptsLength; i++) {
86  scripts[i].type = callback(scripts[i].type);
87  }
88  return isString ? div.innerHTML : $(div.innerHTML);
89  },
90  disableScripts = function(source) {
91  enableScripts(source);
92  return changeScriptsType(source, function(type) {
93  return type ? type.replace(scriptTypeRegExp, hiddenPrefix + '$1') : hiddenScriptType;
94  });
95  },
96  enableScripts = function(source) {
97  return changeScriptsType(source, function(type) {
98  return type.replace(hiddenPrefix, '');
99  });
100  };
101  return {
102  'disableScripts' : disableScripts,
103  'enableScripts' : enableScripts
104  }
105  })($);
106 
107  $('#meta_description').on('change keyup paste', function () {
108  var maxLength = $(this).data('maxLength') || 255;
109  if ($(this).val().length >= maxLength) {
110  $(this).val($(this).val().substr(0, maxLength));
111  }
112  });
113  $form.mage('form', {
114  handlersData: {
115  save: {},
116  saveAndContinueEdit: {
117  action: {
118  args: {back: 'edit'}
119  }
120  },
121  saveAndNew: {
122  action: {
123  args: {back: 'new'}
124  }
125  },
126  saveAndDuplicate: {
127  action: {
128  args: {back: 'duplicate'}
129  }
130  }
131  }
132  });
133  $form.mage('validation', {validationUrl: '<?= /* @escapeNotVerified */ $block->getValidationUrl() ?>'});
134 
135  var masks = <?= /* @escapeNotVerified */ $this->helper('Magento\Framework\Json\Helper\Data')->jsonEncode($block->getFieldsAutogenerationMasks()) ?>;
136  var availablePlaceholders = <?= /* @escapeNotVerified */ $this->helper('Magento\Framework\Json\Helper\Data')->jsonEncode($block->getAttributesAllowedForAutogeneration()) ?>;
137  var Autogenerator = function(masks) {
138  this._masks = masks || {};
139  this._fieldReverseIndex = this._buildReverseIndex(this._masks);
140  this.form = $('[data-form=edit-product], #drawer-form');
141  };
142 
143  $.extend(Autogenerator.prototype, {
144  varRegexp: /{{([\w_]+?)}}/,
145  varsRegexp: new RegExp('{{(' + availablePlaceholders.join('|') + ')}}', 'g'),
146  data: {
147  disabled: 'autogenerator-disabled'
148  },
149  bindAll: function(events) {
150  var self = this;
151  var elementSelector = _(this._masks).keys().map(function(key) {
152  return '#' + key;
153  }).join(',');
154  var disabler = function() {
155  this.form.on(
156  'change init',
157  elementSelector,
158  $.proxy(function(event) {
159  var $element = $(event.target);
160  if (event.type == 'init' && $element.data('disablerInited')) {
161  return;
162  } else {
163  $element.data('disablerInited', true);
164  }
165  $element.data(this.data.disabled, $element.val().replace(/\s/g, '') != '');
166  }, this)
167  ).find(elementSelector).trigger('init');
168  };
169  disabler.call(this);
170  $("#product_info_tabs").on("tabscreate tabsactivate", $.proxy(disabler, this));
171 
172  $.each(this._masks, function(field, mask) {
173  var $field = $('#' + field);
174  if (!$field.val() && mask && mask.length > 0 && !self.varRegexp.test(mask)) {
175  $field.val(mask);
176  }
177  $field.trigger('change');
178  });
179 
180  $.each(self._fieldReverseIndex, function(field) {
181  var fields = this, $field = $('#' + field);
182  var filler = function(onlyText) {
183  $.each(fields, function() {
184  var $el = $('#' + this);
185  if ($el.data(self.data.disabled)) {
186  return;
187  }
188  if (onlyText === true && self.varRegexp.test(self._masks[this])) {
189  return;
190  }
191  var value = self._masks[this].replace(self.varsRegexp, function(maskfieldName) {
192  return $('#' + maskfieldName.slice(2, -2)).val();
193  });
194  $el.val(value);
195  });
196  };
197  if ($field.length) {
198  self.form.on('keyup change blur click paste', '#' + field, filler);
199  $field.trigger('change');
200  }
201  });
202  },
203  _buildReverseIndex: function(masks) {
204  var self = this;
205  var fieldReverseIndex = {};
206  $.each(masks, function(field, mask) {
207  if (mask) {
208  $.each(mask.toString().match(self.varsRegexp) || [], function (key, maskName) {
209  var fieldName = maskName.slice(2, -2);
210  if (!(fieldName in fieldReverseIndex)) {
211  fieldReverseIndex[fieldName] = [];
212  }
213  fieldReverseIndex[fieldName].push(field);
214  })
215  }
216  });
217  return fieldReverseIndex;
218  }
219  });
220 
221  $form.data('autogenerator', new Autogenerator(masks).bindAll());
222 
223  $('.widget-button-save .item-default').parent().hide();
224 
225  $('#product-online-switcher')
226  .prop('checked', $('#status').val() == '1')
227  .trigger('change');
228 
229  $('#product-online-switcher').on('change', function(event) {
230  $('#status').val($(this).prop('checked') ? '1' : '2');
231  });
232 
233  $form.on('changeAttributeSet', function(event, data) {
234  if (data.label) {
235  $('#product-template-suggest-container .action-toggle>span').text(data.label);
236  $('[data-role=affected-attribute-set-selector] [data-role=name-container]').text(data.label);
237  }
238  $('#product-template-suggest').suggest('option', "currentlySelected", data.id).val('');
239 
240  var uri = document.location.href.replace(/(\/|&|\?)?\bset(\/|=)\d+/g, '').replace(/#[^#]*$/, '');
241  uri += /\?/.test(uri) ? '&' : '?';
242  uri += 'set=' + window.encodeURIComponent(data.id);
243 
244  var $form = $('[data-form=edit-product]');
245  $form.attr('action', $form.attr('action').replace(/(\/|&|\?)?\bset(\/|=)\d+/g, ''));
246  $form.find('#attribute_set_id').attr('name', 'set').val(data.id);
247  $.ajax({
248  url: uri.replace('/edit/', '/new/') + '&popup=1',
249  type: 'post',
250  data: $form.serializeArray(),
251  dataType: 'html',
252  context: $('body'),
253  showLoader: true
254  }).done(function(data) {
255  //Hide all js scripts to prevent removing them during jQuery object creation
256  data = scriptTagManager.disableScripts(data);
257  var removedElementClass = 'removed';
258 
259  var $page = $('body');
260  var $newPage = $(data);
261 
262  var nameMapper = function() {
263  return $(this).attr('name');
264  };
265  var activeTabId = $('.ui-tabs-active>a').attr('id');
266  //add new tab tabs or reorder
267  $page.find('#product_info_tabs .tabs').each(function(i, tabContainer) {
268  $newPage.find('#product_info_tabs .tabs').each(function(j, newTabContainer) {
269  if (i != j) {
270  return;
271  }
272  var $tabContainer = $(tabContainer);
273  $(tabContainer).find('li').removeClass(removedElementClass);
274  var $tabs = $(tabContainer)
275  .find('li:not(.' + removedElementClass + ') .tab-item-link.user-defined:not(.ajax)');
276  var $newTabs = $(newTabContainer).find('.tab-item-link.user-defined:not(.ajax)'),
277  tabsNames = $tabs.map(nameMapper).toArray();
278 
279  //hide not exists elements
280  $.each(
281  _.difference(tabsNames, $newTabs.map(nameMapper).toArray()),
282  function(index, tabName) {
283  $tabContainer.find('[name=' + tabName + ']').closest('li')
284  .addClass(removedElementClass);
285  $page.find('#' + tabName)
286  .addClass(removedElementClass)
287  .addClass('ignore-validate');
288  }
289  );
290 
291  $(newTabContainer).find('.tab-item-link.user-defined:not(.ajax)').each(function(index, tab) {
292  var $tab = $(tab),
293  tabName = nameMapper.apply($tab),
294  $tabsContent = $tab.closest('li').clone();
295  $tabsContent.find('.fieldset>.field').remove();
296  if (nameMapper.apply($tabs.eq(index)) == tabName) {
297  return true;
298  }
299  var $tabToMove = $.inArray(tabName, tabsNames) !== -1
300  ? $tabs.filter(function() {
301  return nameMapper.apply(this) === tabName;
302  }).closest('li')
303  : $tabsContent;
304  if (index === 0) {
305  $tabToMove.prependTo($tabContainer);
306  } else {
307  $tabToMove.insertAfter($tabs.eq(index - 1).closest('li'));
308  }
309  $tabToMove.removeClass(removedElementClass).removeClass('ignore-validate');
310  $tabs = $tabContainer.find('li:not(.' + removedElementClass + ') .tab-item-link.user-defined:not(.ajax)');
311  });
312  });
313  });
314 
315  //add new fieldsets or reorder
316  $newPage.find('#product_info_tabs .fieldset.user-defined').each(function(index, newFieldset) {
317  var fieldsetContainer, newFieldsetContainer, sourceContainer, destinationContainer;
318  newFieldsetContainer = $(newFieldset).parents('[data-ui-id*=-tab-content-]').first();
319  if ($page.find('[data-ui-id=' + newFieldsetContainer.data('uiId') + ']').length === 0) {
320  fieldsetContainer = newFieldsetContainer
321  .clone()
322  .removeClass(removedElementClass)
323  .removeClass('ignore-validate');
324  //Enable hidden js scripts in node. These scripts will be performed after inserting into page
325  fieldsetContainer = scriptTagManager.enableScripts(fieldsetContainer);
326  } else {
327  fieldsetContainer = $page.find('[data-ui-id=' + newFieldsetContainer.data('uiId') + ']').first();
328  }
329  sourceContainer = newFieldsetContainer.parents('[data-ui-id*=-tab-content-]').first();
330  destinationContainer = $page.find('[data-ui-id=' + sourceContainer.data('uiId') + ']').first();
331  fieldsetContainer.appendTo(destinationContainer);
332  });
333 
334  var nameDataMapper = function() {
335  return $(this).data('attributeCode');
336  };
337  //add new element elements or reorder
338  $page.find('[data-form=edit-product] [data-role=tabs] .fieldset, #product_info_tabs .fieldset')
339  .removeClass('ignore-validate')
340  .removeClass(removedElementClass)
341  .each(function(i, fieldSet) {
342  var updateFieldsetElements = function(index, newFieldSet) {
343  if ($(fieldSet).attr('id') != $(newFieldSet).attr('id')) {
344  return
345  }
346  var $elements = $(fieldSet).find('>.field:not(.' + removedElementClass + ')');
347  var $newFieldSet = $(newFieldSet);
348  var $newElements = $newFieldSet.find('>.field');
349 
350  $elements.removeClass(removedElementClass);
351 
352  var elementNames = $elements.map(nameDataMapper).toArray();
353 
354  //hide not exists elements
355  $.each(
356  _.difference(elementNames, $newElements.map(nameDataMapper).toArray()),
357  function(index, elementId) {
358  $page.find('#attribute-' + elementId + '-container')
359  .addClass(removedElementClass)
360  .addClass('ignore-validate');
361  }
362  );
363 
364  $newElements.each(function(index, element) {
365  var $element = $(element),
366  elementId = nameDataMapper.apply($element);
367  if (nameDataMapper.apply($elements.get(index)) == elementId) {
368  return true;
369  }
370  var $elementToMove = $('.fieldset>.field[data-attribute-code="' + elementId + '"]');
371  if ($elementToMove.length === 0) {
372  $elementToMove = $element.clone();
373  }
374  if (index === 0) {
375  $elementToMove.prependTo(fieldSet);
376  } else {
377  $elementToMove.insertAfter($elements.get(index - 1))
378  }
379  $elementToMove.trigger('contentUpdated');
380  $elementToMove.removeClass(removedElementClass).removeClass('.ignore-validate');
381  $elements = $(fieldSet).find('>.field:not(.' + removedElementClass + ')');
382  });
383  };
384 
385  $newPage.find('#product_info_tabs .fieldset').each(updateFieldsetElements);
386 
387  fieldsetContainer = $(fieldSet).parents('[data-ui-id*=-tab-content-]').first();
388  var newFieldsetContainer = $newPage.find('[data-ui-id=' + $(fieldsetContainer).data('uiId') + ']');
389  if (newFieldsetContainer.length == 0) {
390  $(fieldsetContainer).find('fieldset .field')
391  .addClass('ignore-validate')
392  .addClass(removedElementClass);
393  $(fieldsetContainer).addClass(removedElementClass);
394  } else {
395  $(newFieldsetContainer).find('fieldset').each(updateFieldsetElements);
396  $(fieldsetContainer).removeClass(removedElementClass);
397  }
398  });
399  $('#product_info_tabs').tabs('refresh');
400  if (!$('#' + activeTabId).closest('li').hasClass(removedElementClass)) {
401  $('#' + activeTabId).trigger('click');
402  } else {
403  $('#product_info_tabs').tabs("option", "active", 0);
404  }
405  });
406 
407  });
408 });
409 </script>
410 <script type="text/x-magento-init">
411  {
412  "*": {
413  "Magento_Catalog/js/product/weight-handler": {},
414  "Magento_Catalog/catalog/apply-to-type-switcher": {}
415  }
416  }
417 </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
taxRateField find('.mselect-list') .on( 'click.mselect-edit'
Definition: edit.phtml:162
if( $form)() ?>< script > require(['jquery' mage mage
Definition: save.phtml:15
jquery extjs ext tree mage adminhtml form
Definition: tree.phtml:41
$block
Definition: block.php:8
$page
Definition: pages.php:8
taxRateField this edit on("click.mselect-delete", ".mselect-delete", function() { if(!confirm('<?=/*@escapeNotVerified */__( 'Do you really want to delete this tax rate?') ?>')) { return;} var that=$(this), select=that.closest('.mselect-list').prev(), rateValue=that.parent().find( 'input[type="checkbox"]').val();$( 'body').trigger( 'processStart');var ajaxOptions={ type:'POST', data:{ tax_calculation_rate_id:rateValue, form_key:$( 'input[name="form_key"]').val() }, dataType:'json', url:'<?=/*@escapeNotVerified */$block->getTaxRateDeleteUrl() ?>', success:function(result, status) { $( 'body').trigger( 'processStop');if(result.success) { that.parent().remove();select.find( 'option').each(function() { if(this.value===rateValue) { $(this).remove();} });select.trigger( 'change.hiddenSelect');} else { if(result.error_message) alert({ content:result.error_message });else alert({ content:'<?=/*@escapeNotVerified */__( 'An error occurred') ?>' });} }, error:function() { $( 'body').trigger( 'processStop');alert({ content:'<?=/*@escapeNotVerified */__( 'An error occurred') ?>' });} };$.ajax(ajaxOptions);}) .on( 'click.mselectAdd'
Definition: edit.phtml:164
endif
Definition: edit.phtml:54
$element
Definition: element.phtml:12