diff --git a/Helper/Data.php b/Helper/Data.php index 18edb63..a4383e1 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -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; } /** @@ -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) { @@ -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); } /** @@ -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); @@ -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 %s', $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( @@ -181,4 +194,4 @@ public function formatOverriddenScopes(\Magento\Config\Block\System\Config\Form return $formatted; } -} \ No newline at end of file +} diff --git a/Model/Plugin.php b/Model/Plugin.php index b5f0ebd..8470f9d 100644 --- a/Model/Plugin.php +++ b/Model/Plugin.php @@ -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; } /** @@ -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()); diff --git a/README.md b/README.md index 9be6288..499463a 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. diff --git a/composer.json b/composer.json index a7493c0..02e8f9b 100644 --- a/composer.json +++ b/composer.json @@ -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" } ] -} \ No newline at end of file +} diff --git a/registration.php b/registration.php new file mode 100644 index 0000000..d90a8ab --- /dev/null +++ b/registration.php @@ -0,0 +1,7 @@ +