From f986e3cfb6a58e263abd7f915610af567d850a7c Mon Sep 17 00:00:00 2001 From: Eric Wiese Date: Thu, 29 Dec 2016 09:43:42 -0600 Subject: [PATCH 1/8] POC config override hint value display --- Helper/Data.php | 69 +++++++++++++------ .../layout/adminhtml_system_config_edit.xml | 1 + view/adminhtml/web/css/configscopehints.less | 10 ++- view/adminhtml/web/js/configscopehints.js | 9 +++ 4 files changed, 67 insertions(+), 22 deletions(-) create mode 100644 view/adminhtml/web/js/configscopehints.js diff --git a/Helper/Data.php b/Helper/Data.php index ac1a6c9..0e190f8 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -6,6 +6,9 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper { + const STORE_VIEW_SCOPE_CODE = 'stores'; + const WEBSITE_SCOPE_CODE = 'websites'; + /** @var \Magento\Framework\App\Helper\Context */ protected $context; @@ -46,17 +49,17 @@ public function __construct( * @return array */ public function getScopeTree() { - $tree = array('websites' => array()); + $tree = array(self::WEBSITE_SCOPE_CODE => array()); $websites = $this->storeManager->getWebsites(); /* @var $website Website */ foreach($websites as $website) { - $tree['websites'][$website->getId()] = array('stores' => array()); + $tree[self::WEBSITE_SCOPE_CODE][$website->getId()] = array(self::STORE_VIEW_SCOPE_CODE => array()); /* @var $store Store */ foreach($website->getStores() as $store) { - $tree['websites'][$website->getId()]['stores'][] = $store->getId(); + $tree[self::WEBSITE_SCOPE_CODE][$website->getId()][self::STORE_VIEW_SCOPE_CODE][] = $store->getId(); } } @@ -66,15 +69,29 @@ public function getScopeTree() { /** * Wrapper method to get config value at path, scope, and scope code provided * - * @param $path - * @param $contextScope - * @param $contextScopeId - * @return mixed + * @param string $path + * @param string $contextScope + * @param string|int $contextScopeId + * @return string */ protected function _getConfigValue($path, $contextScope, $contextScopeId) { return $this->context->getScopeConfig()->getValue($path, $contextScope, $contextScopeId); } + /** + * Gets human-friendly display value for given config path + * + * @param string $path + * @param string $contextScope + * @param string|int $contextScopeId + * @return string + */ + public function getConfigDisplayValue($path, $contextScope, $contextScopeId) { + $value = $this->_getConfigValue($path, $contextScope, $contextScopeId); + + return $value; //@todo + } + /** * Gets array of scopes and scope IDs where path value is different * than supplied context scope and context scope ID. @@ -97,34 +114,40 @@ public function getOverriddenLevels($path, $contextScope, $contextScopeId) { $overridden = array(); switch($contextScope) { - case 'websites': - $stores = array_values($tree['websites'][$contextScopeId]['stores']); + case self::WEBSITE_SCOPE_CODE: + $stores = array_values($tree[self::WEBSITE_SCOPE_CODE][$contextScopeId][self::STORE_VIEW_SCOPE_CODE]); foreach($stores as $storeId) { - $value = $this->_getConfigValue($path, 'stores', $storeId); + $value = $this->_getConfigValue($path, self::STORE_VIEW_SCOPE_CODE, $storeId); if($value != $currentValue) { $overridden[] = array( 'scope' => 'store', - 'scope_id' => $storeId + 'scope_id' => $storeId, + 'value' => $value, + 'display_value' => $this->getConfigDisplayValue($path, self::STORE_VIEW_SCOPE_CODE, $storeId) ); } } break; case 'default': - foreach($tree['websites'] as $websiteId => $website) { - $websiteValue = $this->_getConfigValue($path, 'websites', $websiteId); + foreach($tree[self::WEBSITE_SCOPE_CODE] as $websiteId => $website) { + $websiteValue = $this->_getConfigValue($path, self::WEBSITE_SCOPE_CODE, $websiteId); if($websiteValue != $currentValue) { $overridden[] = array( 'scope' => 'website', - 'scope_id' => $websiteId + 'scope_id' => $websiteId, + 'value' => $websiteValue, + 'display_value' => $this->getConfigDisplayValue($path, self::WEBSITE_SCOPE_CODE, $websiteId) ); } - foreach($website['stores'] as $storeId) { - $value = $this->_getConfigValue($path, 'stores', $storeId); + foreach($website[self::STORE_VIEW_SCOPE_CODE] as $storeId) { + $value = $this->_getConfigValue($path, self::STORE_VIEW_SCOPE_CODE, $storeId); if($value != $currentValue && $value != $websiteValue) { $overridden[] = array( 'scope' => 'store', - 'scope_id' => $storeId + 'scope_id' => $storeId, + 'value' => $value, + 'display_value' => $this->getConfigDisplayValue($path, self::STORE_VIEW_SCOPE_CODE, $storeId) ); } } @@ -145,11 +168,13 @@ public function getOverriddenLevels($path, $contextScope, $contextScopeId) { public function formatOverriddenScopes($section, array $overridden) { $formatted = '
' . '

' . __('This config field is overridden at the following scope(s):') . '

' . - '
'; + $formatted .= ''; return $formatted; } diff --git a/view/adminhtml/layout/adminhtml_system_config_edit.xml b/view/adminhtml/layout/adminhtml_system_config_edit.xml index 1fc2604..e75b768 100644 --- a/view/adminhtml/layout/adminhtml_system_config_edit.xml +++ b/view/adminhtml/layout/adminhtml_system_config_edit.xml @@ -2,5 +2,6 @@ +