diff --git a/Helper/Data.php b/Helper/Data.php
index a4383e1..ac1a6c9 100644
--- a/Helper/Data.php
+++ b/Helper/Data.php
@@ -29,6 +29,8 @@ public function __construct(
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Backend\Model\Url $urlBuilder
) {
+ parent::__construct($context);
+
$this->storeManager = $storeManager;
$this->context = $context;
// 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) {
/**
* Get HTML output for override hint UI
*
- * @param \Magento\Config\Block\System\Config\Form $form
+ * @param string $section
* @param array $overridden
* @return string
*/
- public function formatOverriddenScopes(\Magento\Config\Block\System\Config\Form $form, array $overridden) {
- $title = __('This setting is overridden at a more specific scope. Click for details.');
-
- $formatted = ''. $title .''.
+ public function formatOverriddenScopes($section, array $overridden) {
+ $formatted = '
' .
+ '
' . __('This config field is overridden at the following scope(s):') . '
' .
'
';
foreach($overridden as $overriddenScope) {
@@ -152,7 +153,6 @@ public function formatOverriddenScopes(\Magento\Config\Block\System\Config\Form
$scopeLabel = $scopeId;
$url = '#';
- $section = $form->getSectionCode();
switch($scope) {
case 'website':
$url = $this->urlBuilder->getUrl(
@@ -162,8 +162,8 @@ public function formatOverriddenScopes(\Magento\Config\Block\System\Config\Form
'website' => $scopeId
)
);
- $scopeLabel = sprintf(
- 'website %s',
+ $scopeLabel = __(
+ 'Website %2',
$url,
$this->storeManager->getWebsite($scopeId)->getName()
);
@@ -179,18 +179,18 @@ public function formatOverriddenScopes(\Magento\Config\Block\System\Config\Form
'store' => $store->getId()
)
);
- $scopeLabel = sprintf(
- 'store view %s',
+ $scopeLabel = __(
+ 'Store view %2',
$url,
$website->getName() . ' / ' . $store->getName()
);
break;
}
- $formatted .= "- Overridden on $scopeLabel
";
+ $formatted .= '- '. $scopeLabel .'
';
}
- $formatted .= '
';
+ $formatted .= '
';
return $formatted;
}
diff --git a/Model/Plugin.php b/Model/Plugin.php
deleted file mode 100644
index 8470f9d..0000000
--- a/Model/Plugin.php
+++ /dev/null
@@ -1,54 +0,0 @@
-helper = $helper;
- }
-
- /**
- * Intercept core config form block getScopeLabel() method
- * to add additional override hints.
- *
- * @see Magento\Config\Block\System\Config\Form::getScopeLabel()
- * @param \Magento\Config\Block\System\Config\Form $form
- * @param callable $getScopeLabel
- * @param Field $field
- * @return Phrase
- */
- public function aroundGetScopeLabel(\Magento\Config\Block\System\Config\Form $form, \Closure $getScopeLabel, Field $field)
- {
- $currentScopeId = null;
- switch($form->getScope()) {
- case 'websites':
- $currentScopeId = $form->getWebsiteCode();
- break;
- case 'stores':
- $currentScopeId = $form->getStoreCode();
- break;
- }
- $overriddenLevels = $this->helper->getOverriddenLevels($field->getPath(), $form->getScope(), $currentScopeId);
-
- /* @var $returnPhrase Phrase */
- $labelPhrase = $getScopeLabel($field);
-
- if(!empty($overriddenLevels)) {
- $scopeHintText = $labelPhrase . $this->helper->formatOverriddenScopes($form, $overriddenLevels);
-
- // create new phrase, now that constituent strings are translated individually
- $labelPhrase = new Phrase($scopeHintText, $labelPhrase->getArguments());
- }
-
- return $labelPhrase;
- }
-}
\ No newline at end of file
diff --git a/Plugin/Framework/Data/Form/Element/Fieldset.php b/Plugin/Framework/Data/Form/Element/Fieldset.php
new file mode 100644
index 0000000..6d7efc5
--- /dev/null
+++ b/Plugin/Framework/Data/Form/Element/Fieldset.php
@@ -0,0 +1,63 @@
+helper = $helper;
+ $this->request = $request;
+ }
+
+ /**
+ * If field is overwritten at more specific scope(s),
+ * set field hint with this info.
+ *
+ * @param OriginalFieldset $subject
+ * @param callable $proceed
+ * @param string $elementId
+ * @param string $type
+ * @param array $config
+ * @param bool $after
+ * @param bool $isAdvanced
+ * @return \Magento\Framework\Data\Form\Element\AbstractElement
+ */
+ public function aroundAddField(OriginalFieldset $subject, callable $proceed, $elementId, $type, $config, $after = false, $isAdvanced = false) {
+ $path = $config['field_config']['path'] . '/' . $config['field_config']['id'];
+ $scope = $config['scope'];
+ $scopeId = $config['scope_id'];
+ $section = $this->request->getParam('section'); //@todo: don't talk to request directly
+
+ $overriddenLevels = $this->helper->getOverriddenLevels(
+ $path,
+ $scope,
+ $scopeId
+ );
+
+ if(!empty($overriddenLevels)) {
+ $config['comment'] .= $this->helper->formatOverriddenScopes($section, $overriddenLevels);
+ }
+
+ return $proceed($elementId, $type, $config, $after, $isAdvanced);
+ }
+}
\ No newline at end of file
diff --git a/README.md b/README.md
index 3694f10..2a9f310 100644
--- a/README.md
+++ b/README.md
@@ -1,13 +1,27 @@
-# EW/ConfigScopeHints
+# EW_ConfigScopeHints
-This is a Magento 2 port of my [Magento 1 Config Scope Hints module](https://github.com/ericthehacker/magento-configscopehints).
-
-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).
+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).
## Installation
This module can be installed manually or by using Composer (recommended).
+### Composer Installation
+
+Each of these commands should be run from the command line at the Magento 2 root.
+
+```bash
+# add this repository to your composer.json
+$ composer config repositories.magento2-configscopehints git https://github.com/ericthehacker/magento2-configscopehints.git
+
+# require module
+$ composer require ericthehacker/magento2-configscopehints
+
+# enable module
+$ php -f bin/magento module:enable EW_ConfigScopeHints
+$ php -f bin/magento setup:upgrade
+```
+
### Manual Installation
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
```
Finally, enable module by running the following from the command line at the Magento 2 root.
-```
-$ php -f bin/magento module:enable EW_ConfigScopeHints
-$ php -f bin/magento setup:upgrade
-```
-
-### Composer Installation
-
-Each of these commands should be run from the command line at the Magento 2 root.
```bash
-# add this repository to your composer.json
-$ composer config repositories.magento2-configscopehints git https://github.com/ericthehacker/magento2-configscopehints.git
-
-# require module
-$ composer require ericthehacker/magento2-configscopehints:~2.1
-
-# enable module
$ php -f bin/magento module:enable EW_ConfigScopeHints
$ php -f bin/magento setup:upgrade
```
@@ -46,14 +45,28 @@ Sit back and enjoy!
## Usage
-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.
+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.
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.
-Clicking on the notification bulb displays a detailed list of the exact scope(s) that override the value, with links directly to those scopes.
+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.
-![Screenshot of system config scope hints module](https://ericwie.se/assets/img/work/magento2-configscopehints.png?v=1)
+![Screenshot of system config scope hints module](https://ericisaweso.me/images/magento2-configscopehints-v3.png)
## Compatibility and Technical Notes
-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.
+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.
+
+> NOTE: For known compatibility with 2.0.x, check out version [2.1.0][2.1.0] of the module.
+
+## Known Issues
+
+### MAGETWO-62648
+
+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.
+
+This is a known [core bug][MAGETWO-62648].
+
+
+[2.1.0]: https://github.com/ericthehacker/magento2-configscopehints/releases/tag/v2.1.0
+[MAGETWO-62648]: https://github.com/magento/magento2/issues/7943
\ No newline at end of file
diff --git a/etc/di.xml b/etc/di.xml
index 56e2c56..4fbf809 100644
--- a/etc/di.xml
+++ b/etc/di.xml
@@ -1,6 +1,6 @@
-
-
+
+
diff --git a/etc/module.xml b/etc/module.xml
index f3e4fdc..313d310 100644
--- a/etc/module.xml
+++ b/etc/module.xml
@@ -1,5 +1,5 @@
-
+
diff --git a/view/adminhtml/layout/adminhtml_system_config_edit.xml b/view/adminhtml/layout/adminhtml_system_config_edit.xml
index e75b768..1fc2604 100644
--- a/view/adminhtml/layout/adminhtml_system_config_edit.xml
+++ b/view/adminhtml/layout/adminhtml_system_config_edit.xml
@@ -2,6 +2,5 @@
-
diff --git a/view/adminhtml/web/css/configscopehints.less b/view/adminhtml/web/css/configscopehints.less
index 9915afb..0544ecd 100644
--- a/view/adminhtml/web/css/configscopehints.less
+++ b/view/adminhtml/web/css/configscopehints.less
@@ -1,36 +1,17 @@
-a.overridden-hint-list-toggle {
- display: inline-block;
- width: 16px;
- height: 16px;
- line-height: 16px;
- margin-left: 5px;
- text-decoration: none;
+.overridden-hint-wrapper {
+ font-style: italic;
- &:hover, &:active, &:visited, &:focus {
- text-decoration: inherit;
+ .lead-text {
+ &:before {
+ color: #eb5202;
+ content: '\e623';
+ font-family: "Admin Icons";
+ display: inline-block;
+ margin-right: 0.5em;
+ }
}
- > span {
- text-indent: -9999px;
- white-space: nowrap;
- display: inline-block;
+ .overridden-hint-list {
+ list-style-position: inside;
}
-
- &::before {
- color: #eb5202;
- content: '\e623';
- font-family: "Admin Icons";
- }
-}
-
-.overridden-hint-list {
- display: none;
-
- li {
- display: inherit;
- }
-
- &.visible {
- display: block;
- }
-}
+}
\ No newline at end of file
diff --git a/view/adminhtml/web/js/configscopehints.js b/view/adminhtml/web/js/configscopehints.js
deleted file mode 100644
index f9100e5..0000000
--- a/view/adminhtml/web/js/configscopehints.js
+++ /dev/null
@@ -1,24 +0,0 @@
-/*jshint browser:true sub:true*/
-require([
- 'jquery'
-], function ($) {
- 'use strict';
-
- $(document).ready(function() {
- $('.overridden-hint-list-toggle').click(function(event) {
- var toggleLink = $(this);
- toggleLink.toggleClass('visible');
-
- var list = toggleLink.next('.overridden-hint-list');
- list.toggleClass('visible');
-
- if(toggleLink.hasClass('visible')) {
- toggleLink.attr('title', 'Click to close');
- } else {
- toggleLink.attr('title', 'This setting is overridden at a more specific scope. Click for details.');
- }
-
- event.preventDefault();
- });
- });
-});