Skip to content

Commit 718ea91

Browse files
ENGCOM-3786: Issue #19609 FIXED #19880
- Merge Pull Request #19880 from maheshWebkul721/magento2:issue-19609 - Merged commits: 1. 1bae0d8 2. 7a2d534 3. fad225b 4. a1de67a 5. b5f866f 6. 2055291 7. f6b8e49 8. 8f4dcc1 9. d397810
2 parents bdf7c3e + d397810 commit 718ea91

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

app/code/Magento/Config/Block/System/Config/Form.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ class Form extends \Magento\Backend\Block\Widget\Form\Generic
134134
* @param \Magento\Config\Block\System\Config\Form\Fieldset\Factory $fieldsetFactory
135135
* @param \Magento\Config\Block\System\Config\Form\Field\Factory $fieldFactory
136136
* @param array $data
137+
* @param SettingChecker|null $settingChecker
137138
*/
138139
public function __construct(
139140
\Magento\Backend\Block\Template\Context $context,
@@ -143,13 +144,15 @@ public function __construct(
143144
\Magento\Config\Model\Config\Structure $configStructure,
144145
\Magento\Config\Block\System\Config\Form\Fieldset\Factory $fieldsetFactory,
145146
\Magento\Config\Block\System\Config\Form\Field\Factory $fieldFactory,
146-
array $data = []
147+
array $data = [],
148+
SettingChecker $settingChecker = null
147149
) {
148150
parent::__construct($context, $registry, $formFactory, $data);
149151
$this->_configFactory = $configFactory;
150152
$this->_configStructure = $configStructure;
151153
$this->_fieldsetFactory = $fieldsetFactory;
152154
$this->_fieldFactory = $fieldFactory;
155+
$this->settingChecker = $settingChecker ?: ObjectManager::getInstance()->get(SettingChecker::class);
153156

154157
$this->_scopeLabels = [
155158
self::SCOPE_DEFAULT => __('[GLOBAL]'),
@@ -366,9 +369,8 @@ protected function _initElement(
366369

367370
$sharedClass = $this->_getSharedCssClass($field);
368371
$requiresClass = $this->_getRequiresCssClass($field, $fieldPrefix);
372+
$isReadOnly = $this->getReadOnly($field, $path);
369373

370-
$isReadOnly = $this->getElementVisibility()->isDisabled($field->getPath())
371-
?: $this->getSettingChecker()->isReadOnly($path, $this->getScope(), $this->getStringScopeCode());
372374
$formField = $fieldset->addField(
373375
$elementId,
374376
$field->getType(),
@@ -417,7 +419,7 @@ private function getFieldData(\Magento\Config\Model\Config\Structure\Element\Fie
417419
{
418420
$data = $this->getAppConfigDataValue($path);
419421

420-
$placeholderValue = $this->getSettingChecker()->getPlaceholderValue(
422+
$placeholderValue = $this->settingChecker->getPlaceholderValue(
421423
$path,
422424
$this->getScope(),
423425
$this->getStringScopeCode()
@@ -797,6 +799,25 @@ private function getAppConfig()
797799
return $this->appConfig;
798800
}
799801

802+
/**
803+
* Check Path is Readonly
804+
*
805+
* @param \Magento\Config\Model\Config\Structure\Element\Field $field
806+
* @param string $path
807+
* @return boolean
808+
*/
809+
private function getReadOnly(\Magento\Config\Model\Config\Structure\Element\Field $field, $path)
810+
{
811+
$isReadOnly = $this->settingChecker->isReadOnly(
812+
$path, ScopeConfigInterface::SCOPE_TYPE_DEFAULT
813+
);
814+
if (!$isReadOnly) {
815+
$isReadOnly = $this->getElementVisibility()->isDisabled($field->getPath())
816+
?: $this->settingChecker->isReadOnly($path, $this->getScope(), $this->getStringScopeCode());
817+
}
818+
return $isReadOnly;
819+
}
820+
800821
/**
801822
* Retrieve deployment config data value by path
802823
*

app/code/Magento/Config/Test/Unit/Block/System/Config/FormTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ protected function setUp()
102102
\Magento\Config\Block\System\Config\Form\Fieldset\Factory::class
103103
);
104104
$this->_fieldFactoryMock = $this->createMock(\Magento\Config\Block\System\Config\Form\Field\Factory::class);
105+
$settingCheckerMock = $this->getMockBuilder(SettingChecker::class)
106+
->disableOriginalConstructor()
107+
->getMock();
105108
$this->_coreConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
106109

107110
$this->_backendConfigMock = $this->createMock(\Magento\Config\Model\Config::class);
@@ -153,6 +156,7 @@ protected function setUp()
153156
'fieldsetFactory' => $this->_fieldsetFactoryMock,
154157
'fieldFactory' => $this->_fieldFactoryMock,
155158
'context' => $context,
159+
'settingChecker' => $settingCheckerMock,
156160
];
157161

158162
$objectArguments = $helper->getConstructArguments(\Magento\Config\Block\System\Config\Form::class, $data);
@@ -532,7 +536,7 @@ public function testInitFields(
532536

533537
$elementVisibilityMock = $this->getMockBuilder(ElementVisibilityInterface::class)
534538
->getMockForAbstractClass();
535-
$elementVisibilityMock->expects($this->once())
539+
$elementVisibilityMock->expects($this->any())
536540
->method('isDisabled')
537541
->willReturn($isDisabled);
538542

0 commit comments

Comments
 (0)