Skip to content

Commit 052ad0b

Browse files
authored
Merge pull request #38 from evs-xsarus/feature/product-show-attribute-code
No ticket. Show attribute code on admin product edit.
2 parents 861b56a + 01897ca commit 052ad0b

File tree

6 files changed

+93
-0
lines changed

6 files changed

+93
-0
lines changed

Plugin/UIScopeLabel.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
namespace AvS\ScopeHint\Plugin;
3+
4+
use Magento\Catalog\Api\Data\ProductAttributeInterface;
5+
use Magento\Eav\Api\Data\AttributeInterface;
6+
use Magento\Framework\App\Config\ScopeConfigInterface;
7+
use Magento\Framework\Stdlib\ArrayManager;
8+
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Eav as EavModifier;
9+
10+
class UIScopeLabel
11+
{
12+
private const CONFIG_SHOW_ATTRIBUTE_CODE = 'dev/debug/show_attribute_code_in_adminhtml';
13+
14+
/**
15+
* @var ArrayManager
16+
*/
17+
private $arrayManager;
18+
19+
/**
20+
* @var ScopeConfigInterface
21+
*/
22+
private $scopeConfig;
23+
24+
public function __construct(
25+
ArrayManager $arrayManager,
26+
ScopeConfigInterface $scopeConfig,
27+
) {
28+
$this->arrayManager = $arrayManager;
29+
$this->scopeConfig = $scopeConfig;
30+
}
31+
32+
/**
33+
* @param EavModifier $subject
34+
* @param array $result
35+
* @param ProductAttributeInterface $attribute
36+
* @return array
37+
*/
38+
public function afterSetupAttributeMeta(EavModifier $subject, $result, ProductAttributeInterface $attribute)
39+
{
40+
if (!$this->scopeConfig->isSetFlag(self::CONFIG_SHOW_ATTRIBUTE_CODE)) {
41+
return $result;
42+
}
43+
44+
$configPath = ltrim(EavModifier::META_CONFIG_PATH, ArrayManager::DEFAULT_PATH_DELIMITER);
45+
$scopeLabel = $this->arrayManager->get(
46+
$configPath . ArrayManager::DEFAULT_PATH_DELIMITER . 'scopeLabel',
47+
$result
48+
);
49+
50+
if ($attribute->getFrontendInput() !== AttributeInterface::FRONTEND_INPUT) {
51+
$scopeLabel = $attribute->getAttributeCode() . ' ' . (string)$scopeLabel;
52+
$result = $this->arrayManager->merge(
53+
$configPath,
54+
$result,
55+
['scopeLabel' => trim($scopeLabel)]
56+
);
57+
}
58+
59+
return $result;
60+
}
61+
}

etc/adminhtml/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,11 @@
1414
sortOrder="1"
1515
disabled="false"/>
1616
</type>
17+
18+
<type name="Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Eav">
19+
<plugin name="avs_scopehint_plugin_add_attribute_code"
20+
type="AvS\ScopeHint\Plugin\UIScopeLabel"
21+
sortOrder="1"
22+
disabled="false"/>
23+
</type>
1724
</config>

etc/adminhtml/system.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
<label>Display path for each option in system configuration</label>
99
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
1010
</field>
11+
<field id="show_attribute_code_in_adminhtml" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
12+
<label>Display attribute code for each field in the product edit</label>
13+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
14+
</field>
1115
</group>
1216
</section>
1317
</system>

etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<dev>
66
<debug>
77
<show_path_in_adminhtml>1</show_path_in_adminhtml>
8+
<show_attribute_code_in_adminhtml>1</show_attribute_code_in_adminhtml>
89
</debug>
910
</dev>
1011
</default>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//
2+
// Imports
3+
// ---------------------------------------------
4+
5+
@import './extend/_additional.less';
6+
7+
8+
//
9+
// Common styles
10+
// ---------------------------------------------
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//
2+
// [ Additional styles ]
3+
// ---------------------------------------------
4+
5+
6+
// Give attribute code enough room in the product edit.
7+
8+
.admin__field-label > label > span {
9+
width: 100%;
10+
}

0 commit comments

Comments
 (0)