|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Ecomteck |
| 4 | + * |
| 5 | + * NOTICE OF LICENSE |
| 6 | + * |
| 7 | + * This source file is subject to the Ecomteck.com license that is |
| 8 | + * available through the world-wide-web at this URL: |
| 9 | + * https://ecomteck.com/LICENSE.txt |
| 10 | + * |
| 11 | + * DISCLAIMER |
| 12 | + * |
| 13 | + * Do not edit or add to this file if you wish to upgrade this extension to newer |
| 14 | + * version in the future. |
| 15 | + * |
| 16 | + * @category Ecomteck |
| 17 | + * @package Ecomteck_CustomAttributeManagement |
| 18 | + * @copyright Copyright (c) 2018 Ecomteck (https://ecomteck.com/) |
| 19 | + * @license https://ecomteck.com/LICENSE.txt |
| 20 | + */ |
| 21 | +namespace Ecomteck\CustomAttributeManagement\Block\Adminhtml\Form\Renderer\Fieldset; |
| 22 | + |
| 23 | +/** |
| 24 | + * EAV entity attribute form fieldset element renderer |
| 25 | + * |
| 26 | + */ |
| 27 | +class Element extends \Magento\Backend\Block\Widget\Form\Renderer\Fieldset\Element |
| 28 | +{ |
| 29 | + /** |
| 30 | + * Retrieve data object related with form |
| 31 | + * |
| 32 | + * @return \Magento\Framework\DataObject |
| 33 | + */ |
| 34 | + public function getDataObject() |
| 35 | + { |
| 36 | + return $this->getElement()->getForm()->getDataObject(); |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * Check "Use default" checkbox display availability |
| 41 | + * |
| 42 | + * @return bool |
| 43 | + */ |
| 44 | + public function canDisplayUseDefault() |
| 45 | + { |
| 46 | + $element = $this->getElement(); |
| 47 | + if ($element) { |
| 48 | + if ($element->getScope() != 'global' |
| 49 | + && $element->getScope() != null |
| 50 | + && $this->getDataObject() |
| 51 | + && $this->getDataObject()->getId() |
| 52 | + && $this->getDataObject()->getWebsite() |
| 53 | + && $this->getDataObject()->getWebsite()->getId() |
| 54 | + && $this->getDataObject()->getWebsite()->getId() == $this->getRequest()->getParam('website') |
| 55 | + ) { |
| 56 | + return true; |
| 57 | + } |
| 58 | + } |
| 59 | + return false; |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * Check default value usage fact |
| 64 | + * |
| 65 | + * @return bool |
| 66 | + */ |
| 67 | + public function usedDefault() |
| 68 | + { |
| 69 | + $key = $this->getElement()->getId(); |
| 70 | + if (strpos($key, 'default_value_') === 0) { |
| 71 | + $key = 'default_value'; |
| 72 | + } |
| 73 | + $storeValue = $this->getDataObject()->getData('scope_' . $key); |
| 74 | + return $storeValue === null; |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * Disable field in default value using case |
| 79 | + * |
| 80 | + * @return $this |
| 81 | + */ |
| 82 | + public function checkFieldDisable() |
| 83 | + { |
| 84 | + if ($this->canDisplayUseDefault() && $this->usedDefault()) { |
| 85 | + $this->getElement()->setDisabled(true); |
| 86 | + } |
| 87 | + return $this; |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * Retrieve label of attribute scope |
| 92 | + * |
| 93 | + * GLOBAL | WEBSITE | STORE |
| 94 | + * |
| 95 | + * @return string |
| 96 | + */ |
| 97 | + public function getScopeLabel() |
| 98 | + { |
| 99 | + $html = ''; |
| 100 | + $element = $this->getElement(); |
| 101 | + if ($this->_storeManager->isSingleStoreMode()) { |
| 102 | + return $html; |
| 103 | + } |
| 104 | + |
| 105 | + if ($element->getScope() == 'global' || $element->getScope() === null) { |
| 106 | + $html = __('[GLOBAL]'); |
| 107 | + } elseif ($element->getScope() == 'website') { |
| 108 | + $html = __('[WEBSITE]'); |
| 109 | + } elseif ($element->getScope() == 'store') { |
| 110 | + $html = __('[STORE VIEW]'); |
| 111 | + } |
| 112 | + |
| 113 | + return $html; |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * Retrieve element label html |
| 118 | + * |
| 119 | + * @return string |
| 120 | + */ |
| 121 | + public function getElementLabelHtml() |
| 122 | + { |
| 123 | + return $this->getElement()->getLabelHtml(); |
| 124 | + } |
| 125 | + |
| 126 | + /** |
| 127 | + * Retrieve element html |
| 128 | + * |
| 129 | + * @return string |
| 130 | + */ |
| 131 | + public function getElementHtml() |
| 132 | + { |
| 133 | + return $this->getElement()->getElementHtml(); |
| 134 | + } |
| 135 | +} |
0 commit comments