Skip to content

Commit 3af7896

Browse files
authored
ENGCOM-3786: Issue #19609 FIXED #19880
2 parents 0f24567 + a8606fd commit 3af7896

File tree

2 files changed

+35
-18
lines changed

2 files changed

+35
-18
lines changed

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

Lines changed: 30 additions & 17 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]'),
@@ -158,18 +161,6 @@ public function __construct(
158161
];
159162
}
160163

161-
/**
162-
* @deprecated 100.1.2
163-
* @return SettingChecker
164-
*/
165-
private function getSettingChecker()
166-
{
167-
if ($this->settingChecker === null) {
168-
$this->settingChecker = ObjectManager::getInstance()->get(SettingChecker::class);
169-
}
170-
return $this->settingChecker;
171-
}
172-
173164
/**
174165
* Initialize objects required to render config form
175166
*
@@ -366,9 +357,8 @@ protected function _initElement(
366357

367358
$sharedClass = $this->_getSharedCssClass($field);
368359
$requiresClass = $this->_getRequiresCssClass($field, $fieldPrefix);
360+
$isReadOnly = $this->isReadOnly($field, $path);
369361

370-
$isReadOnly = $this->getElementVisibility()->isDisabled($field->getPath())
371-
?: $this->getSettingChecker()->isReadOnly($path, $this->getScope(), $this->getStringScopeCode());
372362
$formField = $fieldset->addField(
373363
$elementId,
374364
$field->getType(),
@@ -417,7 +407,7 @@ private function getFieldData(\Magento\Config\Model\Config\Structure\Element\Fie
417407
{
418408
$data = $this->getAppConfigDataValue($path);
419409

420-
$placeholderValue = $this->getSettingChecker()->getPlaceholderValue(
410+
$placeholderValue = $this->settingChecker->getPlaceholderValue(
421411
$path,
422412
$this->getScope(),
423413
$this->getStringScopeCode()
@@ -541,7 +531,7 @@ public function getConfigValue($path)
541531
}
542532

543533
/**
544-
* @return \Magento\Backend\Block\Widget\Form|\Magento\Framework\View\Element\AbstractBlock
534+
* @inheritdoc
545535
*/
546536
protected function _beforeToHtml()
547537
{
@@ -718,6 +708,7 @@ protected function _getAdditionalElementTypes()
718708
*
719709
* @TODO delete this methods when {^see above^} is done
720710
* @return string
711+
* @SuppressWarnings(PHPMD.RequestAwareBlockMethod)
721712
*/
722713
public function getSectionCode()
723714
{
@@ -729,6 +720,7 @@ public function getSectionCode()
729720
*
730721
* @TODO delete this methods when {^see above^} is done
731722
* @return string
723+
* @SuppressWarnings(PHPMD.RequestAwareBlockMethod)
732724
*/
733725
public function getWebsiteCode()
734726
{
@@ -740,6 +732,7 @@ public function getWebsiteCode()
740732
*
741733
* @TODO delete this methods when {^see above^} is done
742734
* @return string
735+
* @SuppressWarnings(PHPMD.RequestAwareBlockMethod)
743736
*/
744737
public function getStoreCode()
745738
{
@@ -797,6 +790,26 @@ private function getAppConfig()
797790
return $this->appConfig;
798791
}
799792

793+
/**
794+
* Check Path is Readonly
795+
*
796+
* @param \Magento\Config\Model\Config\Structure\Element\Field $field
797+
* @param string $path
798+
* @return boolean
799+
*/
800+
private function isReadOnly(\Magento\Config\Model\Config\Structure\Element\Field $field, $path)
801+
{
802+
$isReadOnly = $this->settingChecker->isReadOnly(
803+
$path,
804+
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
805+
);
806+
if (!$isReadOnly) {
807+
$isReadOnly = $this->getElementVisibility()->isDisabled($field->getPath())
808+
?: $this->settingChecker->isReadOnly($path, $this->getScope(), $this->getStringScopeCode());
809+
}
810+
return $isReadOnly;
811+
}
812+
800813
/**
801814
* Retrieve deployment config data value by path
802815
*

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)