Skip to content

Commit 83f8471

Browse files
Merge pull request #5 from ericthehacker/feature/m2.1-support
Magento 2.1.x support
2 parents c751801 + f6b8dfe commit 83f8471

File tree

9 files changed

+127
-149
lines changed

9 files changed

+127
-149
lines changed

Helper/Data.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public function __construct(
2929
\Magento\Store\Model\StoreManagerInterface $storeManager,
3030
\Magento\Backend\Model\Url $urlBuilder
3131
) {
32+
parent::__construct($context);
33+
3234
$this->storeManager = $storeManager;
3335
$this->context = $context;
3436
// Ideally we would just retrieve the urlBuilder using $this->content->getUrlBuilder(), but since it retrieves
@@ -136,14 +138,13 @@ public function getOverriddenLevels($path, $contextScope, $contextScopeId) {
136138
/**
137139
* Get HTML output for override hint UI
138140
*
139-
* @param \Magento\Config\Block\System\Config\Form $form
141+
* @param string $section
140142
* @param array $overridden
141143
* @return string
142144
*/
143-
public function formatOverriddenScopes(\Magento\Config\Block\System\Config\Form $form, array $overridden) {
144-
$title = __('This setting is overridden at a more specific scope. Click for details.');
145-
146-
$formatted = '<a class="overridden-hint-list-toggle" title="'. $title .'" href="#"><span>'. $title .'</span></a>'.
145+
public function formatOverriddenScopes($section, array $overridden) {
146+
$formatted = '<div class="overridden-hint-wrapper">' .
147+
'<p class="lead-text">' . __('This config field is overridden at the following scope(s):') . '</p>' .
147148
'<ul class="overridden-hint-list">';
148149

149150
foreach($overridden as $overriddenScope) {
@@ -152,7 +153,6 @@ public function formatOverriddenScopes(\Magento\Config\Block\System\Config\Form
152153
$scopeLabel = $scopeId;
153154

154155
$url = '#';
155-
$section = $form->getSectionCode();
156156
switch($scope) {
157157
case 'website':
158158
$url = $this->urlBuilder->getUrl(
@@ -162,8 +162,8 @@ public function formatOverriddenScopes(\Magento\Config\Block\System\Config\Form
162162
'website' => $scopeId
163163
)
164164
);
165-
$scopeLabel = sprintf(
166-
'website <a href="%s">%s</a>',
165+
$scopeLabel = __(
166+
'Website <a href="%1">%2</a>',
167167
$url,
168168
$this->storeManager->getWebsite($scopeId)->getName()
169169
);
@@ -179,18 +179,18 @@ public function formatOverriddenScopes(\Magento\Config\Block\System\Config\Form
179179
'store' => $store->getId()
180180
)
181181
);
182-
$scopeLabel = sprintf(
183-
'store view <a href="%s">%s</a>',
182+
$scopeLabel = __(
183+
'Store view <a href="%1">%2</a>',
184184
$url,
185185
$website->getName() . ' / ' . $store->getName()
186186
);
187187
break;
188188
}
189189

190-
$formatted .= "<li class='$scope'>Overridden on $scopeLabel</li>";
190+
$formatted .= '<li class="' . $scope . '">'. $scopeLabel .'</li>';
191191
}
192192

193-
$formatted .= '</ul>';
193+
$formatted .= '</ul></div>';
194194

195195
return $formatted;
196196
}

Model/Plugin.php

Lines changed: 0 additions & 54 deletions
This file was deleted.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace EW\ConfigScopeHints\Plugin\Framework\Data\Form\Element;
4+
5+
use \Magento\Framework\Data\Form\Element\Fieldset as OriginalFieldset;
6+
7+
class Fieldset
8+
{
9+
/**
10+
* @var \EW\ConfigScopeHints\Helper\Data
11+
*/
12+
protected $helper;
13+
/**
14+
* @var \Magento\Framework\App\RequestInterface
15+
*/
16+
protected $request;
17+
18+
/**
19+
* Fieldset constructor.
20+
* @param \EW\ConfigScopeHints\Helper\Data $helper
21+
* @param \Magento\Framework\App\RequestInterface $request
22+
*/
23+
public function __construct(
24+
\EW\ConfigScopeHints\Helper\Data $helper,
25+
\Magento\Framework\App\RequestInterface $request
26+
)
27+
{
28+
$this->helper = $helper;
29+
$this->request = $request;
30+
}
31+
32+
/**
33+
* If field is overwritten at more specific scope(s),
34+
* set field hint with this info.
35+
*
36+
* @param OriginalFieldset $subject
37+
* @param callable $proceed
38+
* @param string $elementId
39+
* @param string $type
40+
* @param array $config
41+
* @param bool $after
42+
* @param bool $isAdvanced
43+
* @return \Magento\Framework\Data\Form\Element\AbstractElement
44+
*/
45+
public function aroundAddField(OriginalFieldset $subject, callable $proceed, $elementId, $type, $config, $after = false, $isAdvanced = false) {
46+
$path = $config['field_config']['path'] . '/' . $config['field_config']['id'];
47+
$scope = $config['scope'];
48+
$scopeId = $config['scope_id'];
49+
$section = $this->request->getParam('section'); //@todo: don't talk to request directly
50+
51+
$overriddenLevels = $this->helper->getOverriddenLevels(
52+
$path,
53+
$scope,
54+
$scopeId
55+
);
56+
57+
if(!empty($overriddenLevels)) {
58+
$config['comment'] .= $this->helper->formatOverriddenScopes($section, $overriddenLevels);
59+
}
60+
61+
return $proceed($elementId, $type, $config, $after, $isAdvanced);
62+
}
63+
}

README.md

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
1-
# EW/ConfigScopeHints
1+
# EW_ConfigScopeHints
22

3-
This is a Magento 2 port of my [Magento 1 Config Scope Hints module](https://github.com/ericthehacker/magento-configscopehints).
4-
5-
This module shows information in the System Configuration when a field is overridden at more specific scope(s), along with information about these scope(s).
3+
This module shows information in the Store Configuration backend UI when a config field is overridden at more specific scope(s), along with information about these scope(s).
64

75
## Installation
86

97
This module can be installed manually or by using Composer (recommended).
108

9+
### Composer Installation
10+
11+
Each of these commands should be run from the command line at the Magento 2 root.
12+
13+
```bash
14+
# add this repository to your composer.json
15+
$ composer config repositories.magento2-configscopehints git https://github.com/ericthehacker/magento2-configscopehints.git
16+
17+
# require module
18+
$ composer require ericthehacker/magento2-configscopehints
19+
20+
# enable module
21+
$ php -f bin/magento module:enable EW_ConfigScopeHints
22+
$ php -f bin/magento setup:upgrade
23+
```
24+
1125
### Manual Installation
1226

1327
First, download contents of this repo into `app/code/EW/ConfigScopeHints` using a command similar to the following in the Magento 2 root.
@@ -21,23 +35,8 @@ $ rm master.zip # clean up zip file
2135
```
2236

2337
Finally, enable module by running the following from the command line at the Magento 2 root.
24-
```
25-
$ php -f bin/magento module:enable EW_ConfigScopeHints
26-
$ php -f bin/magento setup:upgrade
27-
```
28-
29-
### Composer Installation
30-
31-
Each of these commands should be run from the command line at the Magento 2 root.
3238

3339
```bash
34-
# add this repository to your composer.json
35-
$ composer config repositories.magento2-configscopehints git https://github.com/ericthehacker/magento2-configscopehints.git
36-
37-
# require module
38-
$ composer require ericthehacker/magento2-configscopehints:~2.1
39-
40-
# enable module
4140
$ php -f bin/magento module:enable EW_ConfigScopeHints
4241
$ php -f bin/magento setup:upgrade
4342
```
@@ -46,14 +45,28 @@ Sit back and enjoy!
4645

4746
## Usage
4847

49-
After installing the module, when viewing a system configuration field, an alert icon will be shown next to the field scope when the field's value is overridden at a more specific level.
48+
After installing the module, when viewing a system configuration field, an alert icon and message will be shown below the field value if it has been overridden at a more specific scope.
5049

5150
The icon is only shown when the value is overridden at a more specific scope than the current one – that is, if viewing at the default scope, overrides at the website or store view level are shown, but if viewing at the website level, only overrides below the currently selected website are shown.
5251

53-
Clicking on the notification bulb displays a detailed list of the exact scope(s) that override the value, with links directly to those scopes.
52+
Along with the alert message, a detailed list of the exact scope(s) that override the value, with links directly to the store config for the current section at those scopes.
5453

55-
![Screenshot of system config scope hints module](https://ericwie.se/assets/img/work/magento2-configscopehints.png?v=1)
54+
![Screenshot of system config scope hints module](https://ericisaweso.me/images/magento2-configscopehints-v3.png)
5655

5756
## Compatibility and Technical Notes
5857

59-
This module was written and tested against version [2.0.0-rc](https://github.com/magento/magento2/releases/tag/2.0.0-rc). The hints are accomplished using intercepters, so there should be no compatibility concerns ([unlike Magento 1](https://github.com/ericthehacker/magento-configscopehints#rewrites)). This version is post-RC, so the intercepters API should stable at this point.
58+
Version 3.0.0 of this module has been tested against Magento 2.1.x. It's likely compatible with 2.0.x as well, but this is untested.
59+
60+
> NOTE: For known compatibility with 2.0.x, check out version [2.1.0][2.1.0] of the module.
61+
62+
## Known Issues
63+
64+
### MAGETWO-62648
65+
66+
When used on Magento 2.1.3, the module can produce a false positive when viewing a website scope. If a given config value has been overridden at this website scope, any children store views which have "Use Website" set for the value will incorrectly show as being overridden.
67+
68+
This is a known [core bug][MAGETWO-62648].
69+
70+
71+
[2.1.0]: https://github.com/ericthehacker/magento2-configscopehints/releases/tag/v2.1.0
72+
[MAGETWO-62648]: https://github.com/magento/magento2/issues/7943

etc/di.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
3-
<type name="Magento\Config\Block\System\Config\Form">
4-
<plugin name="configScopeHints" type="EW\ConfigScopeHints\Model\Plugin" sortOrder="100" />
3+
<type name="Magento\Framework\Data\Form\Element\Fieldset">
4+
<plugin name="ew_configscopehints" type="EW\ConfigScopeHints\Plugin\Framework\Data\Form\Element\Fieldset" sortOrder="100" />
55
</type>
66
</config>

etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
2-
<module name="EW_ConfigScopeHints" setup_version="2.1.1">
2+
<module name="EW_ConfigScopeHints" setup_version="3.0.0">
33
<sequence>
44
<module name="Magento_Config"/>
55
</sequence>

view/adminhtml/layout/adminhtml_system_config_edit.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
33
<head>
44
<css src="EW_ConfigScopeHints::css/configscopehints.css"/>
5-
<script src="EW_ConfigScopeHints::js/configscopehints.js"/>
65
</head>
76
</page>
Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,17 @@
1-
a.overridden-hint-list-toggle {
2-
display: inline-block;
3-
width: 16px;
4-
height: 16px;
5-
line-height: 16px;
6-
margin-left: 5px;
7-
text-decoration: none;
1+
.overridden-hint-wrapper {
2+
font-style: italic;
83

9-
&:hover, &:active, &:visited, &:focus {
10-
text-decoration: inherit;
4+
.lead-text {
5+
&:before {
6+
color: #eb5202;
7+
content: '\e623';
8+
font-family: "Admin Icons";
9+
display: inline-block;
10+
margin-right: 0.5em;
11+
}
1112
}
1213

13-
> span {
14-
text-indent: -9999px;
15-
white-space: nowrap;
16-
display: inline-block;
14+
.overridden-hint-list {
15+
list-style-position: inside;
1716
}
18-
19-
&::before {
20-
color: #eb5202;
21-
content: '\e623';
22-
font-family: "Admin Icons";
23-
}
24-
}
25-
26-
.overridden-hint-list {
27-
display: none;
28-
29-
li {
30-
display: inherit;
31-
}
32-
33-
&.visible {
34-
display: block;
35-
}
36-
}
17+
}

view/adminhtml/web/js/configscopehints.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)