Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
extend.phtml
Go to the documentation of this file.
1 <?php
7 // @codingStandardsIgnoreFile
8 
10 $elementHtml = $block->getParentElementHtml();
11 
12 $attributeCode = $block->getAttribute()
13  ->getAttributeCode();
14 
15 $switchAttributeCode = "{$attributeCode}_type";
17  ->getData($switchAttributeCode);
18 
19 $isElementReadonly = $block->getElement()
20  ->getReadonly();
21 ?>
22 
23 <?php if (!($attributeCode === 'price' && $block->getCanReadPrice() === false)) { ?>
24  <div class="<?= /* @escapeNotVerified */ $attributeCode ?> "><?= /* @escapeNotVerified */ $elementHtml ?></div>
25 <?php } ?>
26 
27 <?= $block->getExtendedElement($switchAttributeCode)->toHtml() ?>
28 
29 <?php if (!$isElementReadonly && $block->getDisableChild()) { ?>
30  <script>
31  require(['prototype'], function () {
32  function <?= /* @escapeNotVerified */ $switchAttributeCode ?>_change() {
33  var $attribute = $('<?= /* @escapeNotVerified */ $attributeCode ?>');
34  if ($('<?= /* @escapeNotVerified */ $switchAttributeCode ?>').value == '<?= /* @escapeNotVerified */ $block::DYNAMIC ?>') {
35  if ($attribute) {
36  $attribute.disabled = true;
37  $attribute.value = '';
38  $attribute.removeClassName('required-entry');
39  }
40  if ($('dynamic-price-warning')) {
41  $('dynamic-price-warning').show();
42  }
43  } else {
44  if ($attribute) {
45  <?php if ($attributeCode === 'price' && !$block->getCanEditPrice() && $block->getCanReadPrice()
46  && $block->getProduct()->isObjectNew()) { ?>
47  <?php $defaultProductPrice = $block->getDefaultProductPrice() ?: "''"; ?>
48  $attribute.value = <?= /* @escapeNotVerified */ $defaultProductPrice ?>;
49  <?php } else { ?>
50  $attribute.disabled = false;
51  $attribute.addClassName('required-entry');
52  <?php } ?>
53  }
54  if ($('dynamic-price-warning')) {
55  $('dynamic-price-warning').hide();
56  }
57  }
58  }
59 
60  <?php if (!($attributeCode === 'price' && !$block->getCanEditPrice()
61  && !$block->getProduct()->isObjectNew())) { ?>
62  $('<?= /* @escapeNotVerified */ $switchAttributeCode ?>').observe('change', <?= /* @escapeNotVerified */ $switchAttributeCode ?>_change);
63  <?php } ?>
64  Event.observe(window, 'load', function(){
65  <?= /* @escapeNotVerified */ $switchAttributeCode ?>_change();
66  });
67  });
68  </script>
69 <?php } ?>
$switchAttributeValue
Definition: extend.phtml:16
$isElementReadonly
Definition: extend.phtml:19
$block
Definition: block.php:8
$elementHtml
Definition: extend.phtml:10
$attributeCode
Definition: extend.phtml:12
$switchAttributeCode
Definition: extend.phtml:15