Esempio n. 1
0
 /**
  * @param bool $useConfigField uses the test_field_use_config field if true
  * @param bool $isConfigDataEmpty if the config data array should be empty or not
  * @param $configDataValue the value that the field path should be set to in the config data
  */
 protected function _setupFieldsInheritCheckbox($useConfigField, $isConfigDataEmpty, $configDataValue)
 {
     \Magento\TestFramework\Helper\Bootstrap::getInstance()->reinitialize([State::PARAM_BAN_CACHE => true]);
     \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\Config\\ScopeInterface')->setCurrentScope(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE);
     \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\App\\AreaList')->getArea(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE)->load(\Magento\Framework\App\Area::PART_CONFIG);
     $fileResolverMock = $this->getMockBuilder('Magento\\Framework\\App\\Config\\FileResolver')->disableOriginalConstructor()->getMock();
     $filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\Filesystem');
     /** @var $directory  \Magento\Framework\Filesystem\Directory\Read */
     $directory = $filesystem->getDirectoryRead(DirectoryList::ROOT);
     $fileIteratorFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\Config\\FileIteratorFactory');
     $fileIterator = $fileIteratorFactory->create($directory, [$directory->getRelativePath(__DIR__ . '/_files/test_section_config.xml')]);
     $fileResolverMock->expects($this->any())->method('get')->will($this->returnValue($fileIterator));
     $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $structureReader = $objectManager->create('Magento\\Config\\Model\\Config\\Structure\\Reader', ['fileResolver' => $fileResolverMock]);
     $structureData = $objectManager->create('Magento\\Config\\Model\\Config\\Structure\\Data', ['reader' => $structureReader]);
     /** @var \Magento\Config\Model\Config\Structure $structure  */
     $structure = $objectManager->create('Magento\\Config\\Model\\Config\\Structure', ['structureData' => $structureData]);
     $this->_section = $structure->getElement('test_section');
     $this->_group = $structure->getElement('test_section/test_group');
     if ($useConfigField) {
         $this->_field = $structure->getElement('test_section/test_group/test_field_use_config');
     } else {
         $this->_field = $structure->getElement('test_section/test_group/test_field');
     }
     $fieldPath = $this->_field->getConfigPath();
     if ($isConfigDataEmpty) {
         $this->_configData = [];
     } else {
         $this->_configData = [$fieldPath => $configDataValue];
     }
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function getConfigPath()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getConfigPath');
     if (!$pluginInfo) {
         return parent::getConfigPath();
     } else {
         return $this->___callPlugins('getConfigPath', func_get_args(), $pluginInfo);
     }
 }
Esempio n. 3
0
 public function testGetConfigPath()
 {
     $this->_model->setData(['config_path' => 'custom_config_path'], 'scope');
     $this->assertEquals('custom_config_path', $this->_model->getConfigPath());
 }
Esempio n. 4
0
 /**
  * Get css class for "shared" functionality
  *
  * @param \Magento\Config\Model\Config\Structure\Element\Field $field
  * @return string
  */
 protected function _getSharedCssClass(\Magento\Config\Model\Config\Structure\Element\Field $field)
 {
     $sharedClass = '';
     if ($field->getAttribute('shared') && $field->getConfigPath()) {
         $sharedClass = ' shared shared-' . str_replace('/', '-', $field->getConfigPath());
         return $sharedClass;
     }
     return $sharedClass;
 }
Esempio n. 5
0
 /**
  * Init form element from config.
  *
  * @SuppressWarnings(PHPMD.CamelCaseMethodName)
  *
  * @param \Magento\Config\Model\Config\Structure\Element\Field $field       Form field.
  * @param \Magento\Framework\Data\Form\Element\Fieldset        $fieldset    Form fieldset.
  * @param string                                               $path        Config path.
  * @param string                                               $fieldPrefix Field name prefix.
  * @param string                                               $labelPrefix Field label prefix.
  */
 protected function _initElement(\Magento\Config\Model\Config\Structure\Element\Field $field, \Magento\Framework\Data\Form\Element\Fieldset $fieldset, $path, $fieldPrefix = '', $labelPrefix = '')
 {
     $inherit = true;
     $data = $this->getConfigValue($path);
     if (array_key_exists($path, $this->_configData)) {
         $data = $this->_configData[$path];
         $inherit = false;
     } elseif ($field->getConfigPath() !== null) {
         $data = $this->getConfigValue($field->getConfigPath());
     }
     $fieldRendererClass = $field->getFrontendModel();
     $fieldRenderer = $this->_fieldRenderer;
     if ($fieldRendererClass) {
         $fieldRenderer = $this->_layout->getBlockSingleton($fieldRendererClass);
     }
     $fieldRenderer->setForm($this);
     $fieldRenderer->setConfigData($this->_configData);
     $elementName = $this->_generateElementName($field->getPath(), $fieldPrefix);
     $elementId = $this->_generateElementId($field->getPath($fieldPrefix));
     if ($field->hasBackendModel()) {
         $backendModel = $field->getBackendModel();
         $backendModel->setPath($path)->setValue($data)->setContainer($this->getContainerCode())->setStore($this->getStoreCode())->afterLoad();
         $data = $backendModel->getValue();
     }
     $dependencies = $field->getDependencies($fieldPrefix, $this->getStoreCode());
     $this->_populateDependenciesBlock($dependencies, $elementId, $elementName);
     $sharedClass = $this->_getSharedCssClass($field);
     $requiresClass = $this->_getRequiresCssClass($field, $fieldPrefix);
     $formField = $fieldset->addField($elementId, $field->getType(), ['name' => $elementName, 'label' => $field->getLabel($labelPrefix), 'comment' => $field->getComment($data), 'tooltip' => $field->getTooltip(), 'hint' => $field->getHint(), 'value' => $data, 'inherit' => $inherit, 'class' => $field->getFrontendClass() . $sharedClass . $requiresClass, 'field_config' => $field->getData(), 'scope' => $this->getScope(), 'scope_id' => $this->getScopeId(), 'scope_label' => $this->getScopeLabel($field), 'can_use_default_value' => $this->canUseDefaultValue($field->showInDefault()), 'can_use_container_value' => $this->canUseContainerValue($field->showInContainer())]);
     $field->populateInput($formField);
     if ($field->hasValidation()) {
         $formField->addClass($field->getValidation());
     }
     if ($field->getType() == 'multiselect') {
         $formField->setCanBeEmpty($field->canBeEmpty());
     }
     if ($field->hasOptions()) {
         $formField->setValues($field->getOptions());
     }
     $formField->setRenderer($fieldRenderer);
 }