diff --git a/app/code/Magento/Config/Block/System/Config/Form.php b/app/code/Magento/Config/Block/System/Config/Form.php index 0a634659420ad6438db986961c95404390d05ce4..f0ad7e4a28b1a365b6596f7175ae34434e09e59c 100644 --- a/app/code/Magento/Config/Block/System/Config/Form.php +++ b/app/code/Magento/Config/Block/System/Config/Form.php @@ -325,7 +325,6 @@ class Form extends \Magento\Backend\Block\Widget\Form\Generic * @param string $fieldPrefix * @param string $labelPrefix * @return void - * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ protected function _initElement( \Magento\Config\Model\Config\Structure\Element\Field $field, @@ -334,39 +333,9 @@ class Form extends \Magento\Backend\Block\Widget\Form\Generic $fieldPrefix = '', $labelPrefix = '' ) { - $inherit = true; - $data = $this->getAppConfigDataValue($path); - - $placeholderValue = $this->getSettingChecker()->getPlaceholderValue( - $path, - $this->getScope(), - $this->getStringScopeCode() - ); - - if ($placeholderValue) { - $data = $placeholderValue; - } - if ($data === null) { - if (array_key_exists($path, $this->_configData)) { - $data = $this->_configData[$path]; - $inherit = false; + $inherit = !array_key_exists($path, $this->_configData); + $data = $this->getFieldData($field, $path); - if ($field->hasBackendModel()) { - $backendModel = $field->getBackendModel(); - $backendModel->setPath($path) - ->setValue($data) - ->setWebsite($this->getWebsiteCode()) - ->setStore($this->getStoreCode()) - ->afterLoad(); - $data = $backendModel->getValue(); - } - - } elseif ($field->getConfigPath() !== null) { - $data = $this->getConfigValue($field->getConfigPath()); - } else { - $data = $this->getConfigValue($path); - } - } $fieldRendererClass = $field->getFrontendModel(); if ($fieldRendererClass) { $fieldRenderer = $this->_layout->getBlockSingleton($fieldRendererClass); @@ -424,6 +393,50 @@ class Form extends \Magento\Backend\Block\Widget\Form\Generic $formField->setRenderer($fieldRenderer); } + /** + * Get data of field by path + * + * @param \Magento\Config\Model\Config\Structure\Element\Field $field + * @param string $path + * @return mixed|null|string + */ + private function getFieldData(\Magento\Config\Model\Config\Structure\Element\Field $field, $path) + { + $data = $this->getAppConfigDataValue($path); + + $placeholderValue = $this->getSettingChecker()->getPlaceholderValue( + $path, + $this->getScope(), + $this->getStringScopeCode() + ); + + if ($placeholderValue) { + $data = $placeholderValue; + } + if ($data === null) { + if (array_key_exists($path, $this->_configData)) { + $data = $this->_configData[$path]; + + if ($field->hasBackendModel()) { + $backendModel = $field->getBackendModel(); + $backendModel->setPath($path) + ->setValue($data) + ->setWebsite($this->getWebsiteCode()) + ->setStore($this->getStoreCode()) + ->afterLoad(); + $data = $backendModel->getValue(); + } + + } elseif ($field->getConfigPath() !== null) { + $data = $this->getConfigValue($field->getConfigPath()); + } else { + $data = $this->getConfigValue($path); + } + } + + return $data; + } + /** * Retrieve Scope string code *