Skip to content

Commit

Permalink
Merge pull request #1 from erikhansen/feature/magento-2-rc-support
Browse files Browse the repository at this point in the history
Magento 2.0.0-RC support
  • Loading branch information
ericthehacker committed Nov 16, 2015
2 parents 9a58cc8 + 0cca279 commit ad7cd67
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 34 deletions.
49 changes: 31 additions & 18 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,37 @@
use \Magento\Store\Model\Website;
use \Magento\Store\Model\Store;

class Data extends \Magento\Framework\App\Helper\AbstractHelper
class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
/** @var \Magento\Framework\App\Helper\Context */
protected $_context;
protected $context;

/** @var \Magento\Store\Model\StoreManagerInterface */
protected $_storeManger;
protected $storeManager;

/**
* Url Builder
*
* @var \Magento\Backend\Model\Url
*/
protected $urlBuilder;

/**
* @param \Magento\Framework\App\Helper\Context $context
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Backend\Model\Url $urlBuilder
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Store\Model\StoreManagerInterface $storeManager
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Backend\Model\Url $urlBuilder
) {
$this->_storeManger = $storeManager;
$this->_context = $context;
$this->storeManager = $storeManager;
$this->context = $context;
// Ideally we would just retrieve the urlBuilder using $this->content->getUrlBuilder(), but since it retrieves
// an instance of \Magento\Framework\Url instead of \Magento\Backend\Model\Url, we must explicitly request it
// via DI.
$this->urlBuilder = $urlBuilder;
}

/**
Expand All @@ -32,7 +46,7 @@ public function __construct(
public function getScopeTree() {
$tree = array('websites' => array());

$websites = $this->_storeManger->getWebsites();
$websites = $this->storeManager->getWebsites();

/* @var $website Website */
foreach($websites as $website) {
Expand All @@ -56,7 +70,7 @@ public function getScopeTree() {
* @return mixed
*/
protected function _getConfigValue($path, $contextScope, $contextScopeId) {
return $this->_context->getScopeConfig()->getValue($path, $contextScope, $contextScopeId);
return $this->context->getScopeConfig()->getValue($path, $contextScope, $contextScopeId);
}

/**
Expand All @@ -69,7 +83,7 @@ protected function _getConfigValue($path, $contextScope, $contextScopeId) {
* @param $contextScopeId
* @return array
*/
public function getOverridenLevels($path, $contextScope, $contextScopeId) {
public function getOverriddenLevels($path, $contextScope, $contextScopeId) {
$tree = $this->getScopeTree();

$currentValue = $this->_getConfigValue($path, $contextScope, $contextScopeId);
Expand Down Expand Up @@ -141,29 +155,28 @@ public function formatOverriddenScopes(\Magento\Config\Block\System\Config\Form
$section = $form->getSectionCode();
switch($scope) {
case 'website':
$url = $this->_context->getUrlBuilder()->getUrl(
$url = $this->urlBuilder->getUrl(
'*/*/*',
array(
'section'=>$section,
'website'=>$scopeId
'section' => $section,
'website' => $scopeId
)
);
$scopeLabel = sprintf(
'website <a href="%s">%s</a>',
$url,
$this->_storeManger->getWebsite($scopeId)->getName()
$this->storeManager->getWebsite($scopeId)->getName()
);

break;
case 'store':
$store = $this->_storeManger->getStore($scopeId);
$store = $this->storeManager->getStore($scopeId);
$website = $store->getWebsite();
$url = $this->_context->getUrlBuilder()->getUrl(
$url = $this->urlBuilder->getUrl(
'*/*/*',
array(
'section' => $section,
'website' => $website->getCode(),
'store' => $store->getCode()
'store' => $store->getId()
)
);
$scopeLabel = sprintf(
Expand All @@ -181,4 +194,4 @@ public function formatOverriddenScopes(\Magento\Config\Block\System\Config\Form

return $formatted;
}
}
}
8 changes: 4 additions & 4 deletions Model/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
class Plugin
{
/** @var \EW\ConfigScopeHints\Helper\Data */
protected $_helper;
protected $helper;

/**
* @param \EW\ConfigScopeHints\Helper\Data $helper
*/
public function __construct(\EW\ConfigScopeHints\Helper\Data $helper) {
$this->_helper = $helper;
$this->helper = $helper;
}

/**
Expand All @@ -37,13 +37,13 @@ public function aroundGetScopeLabel(\Magento\Config\Block\System\Config\Form $fo
$currentScopeId = $form->getStoreCode();
break;
}
$overriddenLevels = $this->_helper->getOverridenLevels($field->getPath(), $form->getScope(), $currentScopeId);
$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);
$scopeHintText = $labelPhrase . $this->helper->formatOverriddenScopes($form, $overriddenLevels);

// create new phrase, now that constituent strings are translated individually
$labelPhrase = new Phrase($scopeHintText, $labelPhrase->getArguments());
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Each of these commands should be run from the command line at the Magento 2 root
First, add this repository to your `composer.json` by running the following.
```
# add this repository to your composer.json
$ composer config repositories.magento2-configscopehints vcs https://github.com/ericthehacker/magento2-configscopehints.git
$ composer config repositories.magento2-configscopehints git https://github.com/ericthehacker/magento2-configscopehints.git
# require module
$ composer require ericthehacker/magento2-configscopehints
Expand All @@ -56,4 +56,4 @@ Clicking on the notification bulb displays a detailed list of the exact scope(s)

## Compatibility and Technical Notes

This module was written and tested against version [0.74.0-beta4](https://github.com/magento/magento2/releases/tag/0.74.0-beta4). 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-RC2, so the intercepters API should stable at this point.
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.
23 changes: 13 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,26 @@
"name": "ericthehacker/magento2-configscopehints",
"description": "Magento 2 store config override hints module",
"require": {
"magento/magento-composer-installer": "*"
"magento/framework": "*"
},
"type": "magento2-module",
"version": "2.0",
"extra": {
"map": [
[
"*",
"EW/ConfigScopeHints"
]
]
"version": "2.1",
"autoload": {
"files": [ "registration.php" ],
"psr-4": {
"EW\\ConfigScopeHints\\": ""
}
},
"authors": [
{
"name": "Eric Wiese",
"homepage": "https://ericwie.se/",
"role": "Developer"
},
{
"name": "Erik Hansen",
"homepage": "https://www.classyllama.com/",
"role": "Developer"
}
]
}
}
7 changes: 7 additions & 0 deletions registration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'EW_ConfigScopeHints',
__DIR__
);

0 comments on commit ad7cd67

Please sign in to comment.