Skip to content

Issue #19609 FIXED #19880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 14, 2019
47 changes: 30 additions & 17 deletions app/code/Magento/Config/Block/System/Config/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class Form extends \Magento\Backend\Block\Widget\Form\Generic
* @param \Magento\Config\Block\System\Config\Form\Fieldset\Factory $fieldsetFactory
* @param \Magento\Config\Block\System\Config\Form\Field\Factory $fieldFactory
* @param array $data
* @param SettingChecker|null $settingChecker
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
Expand All @@ -143,13 +144,15 @@ public function __construct(
\Magento\Config\Model\Config\Structure $configStructure,
\Magento\Config\Block\System\Config\Form\Fieldset\Factory $fieldsetFactory,
\Magento\Config\Block\System\Config\Form\Field\Factory $fieldFactory,
array $data = []
array $data = [],
SettingChecker $settingChecker = null
) {
parent::__construct($context, $registry, $formFactory, $data);
$this->_configFactory = $configFactory;
$this->_configStructure = $configStructure;
$this->_fieldsetFactory = $fieldsetFactory;
$this->_fieldFactory = $fieldFactory;
$this->settingChecker = $settingChecker ?: ObjectManager::getInstance()->get(SettingChecker::class);

$this->_scopeLabels = [
self::SCOPE_DEFAULT => __('[GLOBAL]'),
Expand All @@ -158,18 +161,6 @@ public function __construct(
];
}

/**
* @deprecated 100.1.2
* @return SettingChecker
*/
private function getSettingChecker()
{
if ($this->settingChecker === null) {
$this->settingChecker = ObjectManager::getInstance()->get(SettingChecker::class);
}
return $this->settingChecker;
}

/**
* Initialize objects required to render config form
*
Expand Down Expand Up @@ -366,9 +357,8 @@ protected function _initElement(

$sharedClass = $this->_getSharedCssClass($field);
$requiresClass = $this->_getRequiresCssClass($field, $fieldPrefix);
$isReadOnly = $this->isReadOnly($field, $path);

$isReadOnly = $this->getElementVisibility()->isDisabled($field->getPath())
?: $this->getSettingChecker()->isReadOnly($path, $this->getScope(), $this->getStringScopeCode());
$formField = $fieldset->addField(
$elementId,
$field->getType(),
Expand Down Expand Up @@ -417,7 +407,7 @@ private function getFieldData(\Magento\Config\Model\Config\Structure\Element\Fie
{
$data = $this->getAppConfigDataValue($path);

$placeholderValue = $this->getSettingChecker()->getPlaceholderValue(
$placeholderValue = $this->settingChecker->getPlaceholderValue(
$path,
$this->getScope(),
$this->getStringScopeCode()
Expand Down Expand Up @@ -541,7 +531,7 @@ public function getConfigValue($path)
}

/**
* @return \Magento\Backend\Block\Widget\Form|\Magento\Framework\View\Element\AbstractBlock
* @inheritdoc
*/
protected function _beforeToHtml()
{
Expand Down Expand Up @@ -718,6 +708,7 @@ protected function _getAdditionalElementTypes()
*
* @TODO delete this methods when {^see above^} is done
* @return string
* @SuppressWarnings(PHPMD.RequestAwareBlockMethod)
*/
public function getSectionCode()
{
Expand All @@ -729,6 +720,7 @@ public function getSectionCode()
*
* @TODO delete this methods when {^see above^} is done
* @return string
* @SuppressWarnings(PHPMD.RequestAwareBlockMethod)
*/
public function getWebsiteCode()
{
Expand All @@ -740,6 +732,7 @@ public function getWebsiteCode()
*
* @TODO delete this methods when {^see above^} is done
* @return string
* @SuppressWarnings(PHPMD.RequestAwareBlockMethod)
*/
public function getStoreCode()
{
Expand Down Expand Up @@ -797,6 +790,26 @@ private function getAppConfig()
return $this->appConfig;
}

/**
* Check Path is Readonly
*
* @param \Magento\Config\Model\Config\Structure\Element\Field $field
* @param string $path
* @return boolean
*/
private function isReadOnly(\Magento\Config\Model\Config\Structure\Element\Field $field, $path)
{
$isReadOnly = $this->settingChecker->isReadOnly(
$path,
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
);
if (!$isReadOnly) {
$isReadOnly = $this->getElementVisibility()->isDisabled($field->getPath())
?: $this->settingChecker->isReadOnly($path, $this->getScope(), $this->getStringScopeCode());
}
return $isReadOnly;
}

/**
* Retrieve deployment config data value by path
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ protected function setUp()
\Magento\Config\Block\System\Config\Form\Fieldset\Factory::class
);
$this->_fieldFactoryMock = $this->createMock(\Magento\Config\Block\System\Config\Form\Field\Factory::class);
$settingCheckerMock = $this->getMockBuilder(SettingChecker::class)
->disableOriginalConstructor()
->getMock();
$this->_coreConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);

$this->_backendConfigMock = $this->createMock(\Magento\Config\Model\Config::class);
Expand Down Expand Up @@ -153,6 +156,7 @@ protected function setUp()
'fieldsetFactory' => $this->_fieldsetFactoryMock,
'fieldFactory' => $this->_fieldFactoryMock,
'context' => $context,
'settingChecker' => $settingCheckerMock,
];

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

$elementVisibilityMock = $this->getMockBuilder(ElementVisibilityInterface::class)
->getMockForAbstractClass();
$elementVisibilityMock->expects($this->once())
$elementVisibilityMock->expects($this->any())
->method('isDisabled')
->willReturn($isDisabled);

Expand Down