Skip to content

Commit 80ed204

Browse files
author
Pascal Querner
committed
feat?: backend: disable field when ENV data is available
1 parent a20171a commit 80ed204

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
@@ -372,6 +372,7 @@ public function initFields($fieldset, $group, $section, $fieldPrefix = '', $labe
372372
'name' => $name,
373373
'label' => $label,
374374
'comment' => $comment,
375+
'disabled' => $this->isDisabled($path),
375376
'tooltip' => $tooltip,
376377
'hint' => $hint,
377378
'value' => $data,
@@ -622,6 +623,20 @@ public function getScope()
622623
return $scope;
623624
}
624625

626+
/**
627+
* Render element as disabled, if overwritten by ENV variable
628+
*
629+
* @param string $data
630+
* @return bool
631+
*/
632+
public function isDisabled($path): bool
633+
{
634+
/** @var Mage_Core_Helper_EnvironmentConfigLoader $environmentConfigLoaderHelper */
635+
$environmentConfigLoaderHelper = Mage::helper('core/environmentConfigLoader');
636+
$path = $this->getScope() . '/' . $path;
637+
return $environmentConfigLoaderHelper->hasPath($path);
638+
}
639+
625640
/**
626641
* Retrieve label for scope
627642
*

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

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,39 @@ public function overrideEnvironment(Varien_Simplexml_Config $xmlConfig)
9898
}
9999
}
100100

101+
public function hasPath(string $wantedPath): bool
102+
{
103+
$env = $this->getEnv();
104+
$config = [];
105+
106+
foreach ($env as $configKey => $value) {
107+
if (!$this->isConfigKeyValid($configKey)) {
108+
continue;
109+
}
110+
111+
list($configKeyParts, $scope) = $this->getConfigKey($configKey);
112+
113+
switch ($scope) {
114+
case static::CONFIG_KEY_DEFAULT:
115+
list($unused1, $unused2, $section, $group, $field) = $configKeyParts;
116+
$path = $this->buildPath($section, $group, $field);
117+
$nodePath = $this->buildNodePath($scope, $path);
118+
$config[$nodePath] = $value;
119+
break;
120+
121+
case static::CONFIG_KEY_WEBSITES:
122+
case static::CONFIG_KEY_STORES:
123+
list($unused1, $unused2, $storeCode, $section, $group, $field) = $configKeyParts;
124+
$path = $this->buildPath($section, $group, $field);
125+
$nodePath = $this->buildNodePath($scope, $path);
126+
$config[$nodePath] = $value;
127+
break;
128+
}
129+
}
130+
$hasConfig = array_key_exists($wantedPath, $config);
131+
return $hasConfig;
132+
}
133+
101134
public function getAsArray(string $wantedScope): array
102135
{
103136
$env = $this->getEnv();
@@ -124,8 +157,6 @@ public function getAsArray(string $wantedScope): array
124157
case static::CONFIG_KEY_STORES:
125158
list($unused1, $unused2, $storeCode, $section, $group, $field) = $configKeyParts;
126159
$path = $this->buildPath($section, $group, $field);
127-
$storeCode = strtolower($storeCode);
128-
$scope = strtolower($scope);
129160
$config[$path] = $value;
130161
break;
131162
}

0 commit comments

Comments
 (0)