Skip to content

Commit

Permalink
Merge pull request #5 from ericthehacker/feature/m2.1-support
Browse files Browse the repository at this point in the history
Magento 2.1.x support
  • Loading branch information
ericthehacker authored Dec 29, 2016
2 parents c751801 + f6b8dfe commit 83f8471
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 149 deletions.
24 changes: 12 additions & 12 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = '<a class="overridden-hint-list-toggle" title="'. $title .'" href="#"><span>'. $title .'</span></a>'.
public function formatOverriddenScopes($section, array $overridden) {
$formatted = '<div class="overridden-hint-wrapper">' .
'<p class="lead-text">' . __('This config field is overridden at the following scope(s):') . '</p>' .
'<ul class="overridden-hint-list">';

foreach($overridden as $overriddenScope) {
Expand All @@ -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(
Expand All @@ -162,8 +162,8 @@ public function formatOverriddenScopes(\Magento\Config\Block\System\Config\Form
'website' => $scopeId
)
);
$scopeLabel = sprintf(
'website <a href="%s">%s</a>',
$scopeLabel = __(
'Website <a href="%1">%2</a>',
$url,
$this->storeManager->getWebsite($scopeId)->getName()
);
Expand All @@ -179,18 +179,18 @@ public function formatOverriddenScopes(\Magento\Config\Block\System\Config\Form
'store' => $store->getId()
)
);
$scopeLabel = sprintf(
'store view <a href="%s">%s</a>',
$scopeLabel = __(
'Store view <a href="%1">%2</a>',
$url,
$website->getName() . ' / ' . $store->getName()
);
break;
}

$formatted .= "<li class='$scope'>Overridden on $scopeLabel</li>";
$formatted .= '<li class="' . $scope . '">'. $scopeLabel .'</li>';
}

$formatted .= '</ul>';
$formatted .= '</ul></div>';

return $formatted;
}
Expand Down
54 changes: 0 additions & 54 deletions Model/Plugin.php

This file was deleted.

63 changes: 63 additions & 0 deletions Plugin/Framework/Data/Form/Element/Fieldset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace EW\ConfigScopeHints\Plugin\Framework\Data\Form\Element;

use \Magento\Framework\Data\Form\Element\Fieldset as OriginalFieldset;

class Fieldset
{
/**
* @var \EW\ConfigScopeHints\Helper\Data
*/
protected $helper;
/**
* @var \Magento\Framework\App\RequestInterface
*/
protected $request;

/**
* Fieldset constructor.
* @param \EW\ConfigScopeHints\Helper\Data $helper
* @param \Magento\Framework\App\RequestInterface $request
*/
public function __construct(
\EW\ConfigScopeHints\Helper\Data $helper,
\Magento\Framework\App\RequestInterface $request
)
{
$this->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);
}
}
59 changes: 36 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
```
Expand All @@ -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
4 changes: 2 additions & 2 deletions etc/di.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<type name="Magento\Config\Block\System\Config\Form">
<plugin name="configScopeHints" type="EW\ConfigScopeHints\Model\Plugin" sortOrder="100" />
<type name="Magento\Framework\Data\Form\Element\Fieldset">
<plugin name="ew_configscopehints" type="EW\ConfigScopeHints\Plugin\Framework\Data\Form\Element\Fieldset" sortOrder="100" />
</type>
</config>
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="EW_ConfigScopeHints" setup_version="2.1.1">
<module name="EW_ConfigScopeHints" setup_version="3.0.0">
<sequence>
<module name="Magento_Config"/>
</sequence>
Expand Down
1 change: 0 additions & 1 deletion view/adminhtml/layout/adminhtml_system_config_edit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
<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">
<head>
<css src="EW_ConfigScopeHints::css/configscopehints.css"/>
<script src="EW_ConfigScopeHints::js/configscopehints.js"/>
</head>
</page>
45 changes: 13 additions & 32 deletions view/adminhtml/web/css/configscopehints.less
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
24 changes: 0 additions & 24 deletions view/adminhtml/web/js/configscopehints.js

This file was deleted.

0 comments on commit 83f8471

Please sign in to comment.