Skip to content

Commit 3ec6f3e

Browse files
author
Pascal Querner
committed
feat?: backend: disable field when ENV data is available
1 parent 4bda412 commit 3ec6f3e

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

app/code/core/Mage/Adminhtml/Block/System/Config/Form.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ public function initFields($fieldset, $group, $section, $fieldPrefix = '', $labe
380380
'name' => $name,
381381
'label' => $label,
382382
'comment' => $comment,
383+
'disabled' => $this->isDisabled($path),
383384
'tooltip' => $tooltip,
384385
'hint' => $hint,
385386
'value' => $data,
@@ -629,6 +630,20 @@ public function getScope()
629630
return $scope;
630631
}
631632

633+
/**
634+
* Render element as disabled, if overwritten by ENV variable
635+
*
636+
* @param string $data
637+
* @return bool
638+
*/
639+
public function isDisabled($path): bool
640+
{
641+
/** @var Mage_Core_Helper_EnvironmentConfigLoader $environmentConfigLoaderHelper */
642+
$environmentConfigLoaderHelper = Mage::helper('core/environmentConfigLoader');
643+
$path = $this->getScope() . '/' . $path;
644+
return $environmentConfigLoaderHelper->hasPath($path);
645+
}
646+
632647
/**
633648
* Retrieve label for scope
634649
*

app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,39 @@ public function overrideEnvironment(Varien_Simplexml_Config $xmlConfig)
105105
}
106106
}
107107

108+
public function hasPath(string $wantedPath): bool
109+
{
110+
$env = $this->getEnv();
111+
$config = [];
112+
113+
foreach ($env as $configKey => $value) {
114+
if (!$this->isConfigKeyValid($configKey)) {
115+
continue;
116+
}
117+
118+
list($configKeyParts, $scope) = $this->getConfigKey($configKey);
119+
120+
switch ($scope) {
121+
case static::CONFIG_KEY_DEFAULT:
122+
list($unused1, $unused2, $section, $group, $field) = $configKeyParts;
123+
$path = $this->buildPath($section, $group, $field);
124+
$nodePath = $this->buildNodePath($scope, $path);
125+
$config[$nodePath] = $value;
126+
break;
127+
128+
case static::CONFIG_KEY_WEBSITES:
129+
case static::CONFIG_KEY_STORES:
130+
list($unused1, $unused2, $storeCode, $section, $group, $field) = $configKeyParts;
131+
$path = $this->buildPath($section, $group, $field);
132+
$nodePath = $this->buildNodePath($scope, $path);
133+
$config[$nodePath] = $value;
134+
break;
135+
}
136+
}
137+
$hasConfig = array_key_exists($wantedPath, $config);
138+
return $hasConfig;
139+
}
140+
108141
public function getAsArray(string $wantedScope): array
109142
{
110143
$env = $this->getEnv();
@@ -131,8 +164,6 @@ public function getAsArray(string $wantedScope): array
131164
case static::CONFIG_KEY_STORES:
132165
list($unused1, $unused2, $storeCode, $section, $group, $field) = $configKeyParts;
133166
$path = $this->buildPath($section, $group, $field);
134-
$storeCode = strtolower($storeCode);
135-
$scope = strtolower($scope);
136167
$config[$path] = $value;
137168
break;
138169
}

0 commit comments

Comments
 (0)