├── COPYING.txt
├── Plugin
└── Backend
│ └── Magento
│ └── Config
│ └── Model
│ └── Config
│ └── Structure
│ └── Element
│ └── Field
│ ├── DisplayHintAndValue.php
│ ├── DisplayOverrideValue.php
│ └── FieldPlugin.php
├── README.md
├── composer.json
├── etc
├── acl.xml
├── adminhtml
│ ├── di.xml
│ └── system.xml
├── config.xml
└── module.xml
├── registration.php
└── view
└── adminhtml
├── layout
└── adminhtml_system_config_edit.xml
├── templates
├── config_field_info.phtml
└── override_tooltip.phtml
└── web
└── js
└── copy-config-field-info.js
/COPYING.txt:
--------------------------------------------------------------------------------
1 | Copyright © 2022-present Anass touati
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 | SOFTWARE.
20 |
--------------------------------------------------------------------------------
/Plugin/Backend/Magento/Config/Model/Config/Structure/Element/Field/DisplayHintAndValue.php:
--------------------------------------------------------------------------------
1 | config, true)) {
38 | return $result;
39 | }
40 | return $result . $this->getAdditionalHTML($result, $subject);
41 | }
42 |
43 | /**
44 | * HTML Renderer
45 | *
46 | * @param string $comment
47 | * @param MagentoField $field
48 | * @return string
49 | */
50 | public function getAdditionalHTML(string $comment, MagentoField $field): string
51 | {
52 | $block = $this->blockFactory->createBlock(Template::class);
53 | $fieldPath = $this->getConfigPath($field);
54 | $block
55 | ->setTemplate('AnassTouatiCoder_InstantConfigurationCopy::config_field_info.phtml')
56 | ->setBreakLine(strlen($comment))
57 | ->addData($this->config)
58 | ->setPath($fieldPath);
59 |
60 | if (in_array($field->getType(), self::ALLOWED_FIELD_TYPE_LIST)) {
61 | $block->setFieldId($this->getFieldHTMLId($field))
62 | ->setFieldType($field->getType());
63 | }
64 |
65 | return $block->toHtml();
66 | }
67 |
68 | /**
69 | * {@inheritdoc }
70 | */
71 | protected function initConfig(): void
72 | {
73 | $this->config = [
74 | 'display_path' => $this->scopeConfig->isSetFlag(self::XML_CONFIG_PATH_ENABLE_HINTS_PATH),
75 | 'display_value' => $this->scopeConfig->isSetFlag(self::XML_CONFIG_PATH_SYSTEM_FIELD_VALUE)
76 | ];
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/Plugin/Backend/Magento/Config/Model/Config/Structure/Element/Field/DisplayOverrideValue.php:
--------------------------------------------------------------------------------
1 | escaper = $escaper;
51 | $this->storeManager = $storeManager;
52 | $this->request = $request;
53 | parent::__construct($scopeConfig, $blockFactory);
54 | }
55 |
56 | /**
57 | * Main entry
58 | *
59 | * @param MagentoField $subject
60 | * @param string $result
61 | * @return string
62 | */
63 | public function afterGetLabel(MagentoField $subject, $result)
64 | {
65 | if (!$this->config['display_tooltip']) {
66 | return $result;
67 | }
68 |
69 | return $result . $this->getToolTipHTML($subject, $result);
70 | }
71 |
72 | /**
73 | * Get Tooltip html output
74 | *
75 | * @param MagentoField $field
76 | * @return string
77 | */
78 | private function getToolTipHTML(MagentoField $field, $label)
79 | {
80 | $tooltip = '';
81 | $lines = [];
82 |
83 | foreach ($this->storeManager->getWebsites(false) as $website) {
84 | if ($this->getWebsiteParam() || $this->getStoreParam()) {
85 | continue;
86 | }
87 | // Only show website specific values in default scope
88 | if ($scopeLine = $this->getScopeHint($field, self::SCOPE_TYPE_WEBSITES, $website)) {
89 | $lines[] = $scopeLine;
90 | }
91 | }
92 | foreach ($this->storeManager->getStores(false) as $store) {
93 | if ($this->getStoreParam()) {
94 | continue;
95 | }
96 | if (($websiteId = $this->getWebsiteParam()) && ($store->getWebsiteId() != $websiteId)) {
97 | continue;
98 | }
99 | // show store specific values in default scope and in parent website scope
100 | if ($scopeLine = $this->getScopeHint($field, self::SCOPE_TYPE_STORES, $store)) {
101 | $lines[] = $scopeLine;
102 | }
103 | }
104 | if (count($lines) > 0) {
105 | $tooltipContent = implode('
', $lines);
106 | $tooltip = $this->blockFactory->createBlock(Template::class)
107 | ->setFieldLabel($label)
108 | ->setTemplate('AnassTouatiCoder_InstantConfigurationCopy::override_tooltip.phtml')
109 | ->setToolTipContent($tooltipContent)
110 | ->toHtml();
111 | }
112 |
113 | return $tooltip;
114 | }
115 |
116 | /**
117 | * {@inheritdoc }
118 | */
119 | protected function initConfig(): void
120 | {
121 | $this->config = [
122 | 'display_tooltip' => $this->scopeConfig->isSetFlag(self::XML_CONFIG_PATH_SYSTEM_OVERRIDE_VALUES)
123 | ];
124 | }
125 |
126 | /**
127 | * Get scope data
128 | *
129 | * @param MagentoField $field
130 | * @param string $scopeType
131 | * @param $scope
132 | * @return Phrase|string
133 | */
134 | private function getScopeHint(MagentoField $field, string $scopeType, $scope)
135 | {
136 | $path = $this->getConfigPath($field);
137 | $scopeLine = '';
138 | if ($websiteId = $this->getWebsiteParam()) {
139 | $currentValue = $this->scopeConfig->getValue(
140 | $path,
141 | ScopeInterface::SCOPE_WEBSITE,
142 | $websiteId
143 | );
144 | } else {
145 | $currentValue = $this->scopeConfig->getValue($path);
146 | }
147 | $scopeValue = $this->scopeConfig->getValue($path, $scopeType, $scope->getId());
148 |
149 | if (is_array($currentValue) || is_array($scopeValue)) {
150 | return $scopeLine;
151 | }
152 |
153 | $currentValue = (string)$currentValue;
154 | $scopeValue = (string)$scopeValue;
155 |
156 | if ($scopeValue !== $currentValue) {
157 | $scopeValue = $this->escaper->escapeHtml($scopeValue);
158 |
159 | switch ($scopeType) {
160 | case self::SCOPE_TYPE_STORES:
161 | return __(
162 | 'Store %1
:
"%2"',
163 | $scope->getCode(),
164 | $this->getValueLabel($field, $scopeValue)
165 | );
166 | case self::SCOPE_TYPE_WEBSITES:
167 | return __(
168 | 'Website %1
:
"%2"',
169 | $scope->getCode(),
170 | $this->getValueLabel($field, $scopeValue)
171 | );
172 | }
173 | }
174 | return $scopeLine;
175 | }
176 |
177 | /**
178 | * Get Value
179 | *
180 | * @param MagentoField $field
181 | * @param string $scopeValue
182 | * @return string|Phrase
183 | */
184 | private function getValueLabel(MagentoField $field, string $scopeValue)
185 | {
186 | $scopeValue = trim($scopeValue);
187 | if ($field->hasOptions()) {
188 | if ($field->getType() === 'multiselect' && strpos($scopeValue, ',') !== false) {
189 | return implode(
190 | ', ',
191 | array_map(
192 | function ($key) use ($field) {
193 | return $this->getValueLabel($field, $key);
194 | },
195 | explode(',', $scopeValue)
196 | )
197 | );
198 | }
199 | foreach ($field->getOptions() as $option) {
200 | if (is_array($option) && $option['value'] == $scopeValue) {
201 | return $option['label'];
202 | }
203 | }
204 | }
205 | return $scopeValue;
206 | }
207 |
208 | /**
209 | * Get Website ID parameter from request
210 | *
211 | * @return string|null
212 | */
213 | private function getWebsiteParam(): ?string
214 | {
215 | return $this->request->getParam('website');
216 | }
217 |
218 | /**
219 | * Get store ID parameter from request
220 | *
221 | * @return string|null
222 | */
223 | private function getStoreParam(): ?string
224 | {
225 | return $this->request->getParam('store');
226 | }
227 | }
228 |
--------------------------------------------------------------------------------
/Plugin/Backend/Magento/Config/Model/Config/Structure/Element/Field/FieldPlugin.php:
--------------------------------------------------------------------------------
1 | scopeConfig = $scopeConfig;
49 | $this->blockFactory = $blockFactory;
50 | $this->initConfig();
51 | }
52 |
53 | /**
54 | * Get active HTML Renderer
55 | *
56 | * @return void
57 | */
58 | abstract protected function initConfig(): void;
59 |
60 | /**
61 | * Get field config path
62 | *
63 | * @param MagentoField $field
64 | * @return string|null
65 | */
66 | protected function getConfigPath(MagentoField $field): ?string
67 | {
68 | return $field->getConfigPath() ?: $field->getPath();
69 | }
70 |
71 | /**
72 | * Get Field HTML ID
73 | *
74 | * @param MagentoField $field
75 | * @return array|string|string[]
76 | */
77 | protected function getFieldHTMLId(MagentoField $field)
78 | {
79 | return str_replace('/', '_', $field->getPath());
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
Text, Textarea, Select and 34 | Multiselect
]]>Text, Textarea, Select and 43 | Multiselect
]]>