示例#1
0
 /**
  * Get original configPath (not changed by PayPal configuration inheritance)
  *
  * @param \Magento\Config\Model\Config\Structure\Element\Field $subject
  * @param \Closure $proceed
  * @return string|null
  */
 public function aroundGetConfigPath(\Magento\Config\Model\Config\Structure\Element\Field $subject, \Closure $proceed)
 {
     $configPath = $proceed();
     if (!isset($configPath) && $this->_request->getParam('section') == 'payment') {
         $configPath = preg_replace('@^(' . implode('|', \Magento\Paypal\Model\Config\StructurePlugin::getPaypalConfigCountries(true)) . ')/@', 'payment/', $subject->getPath());
     }
     return $configPath;
 }
 /**
  * @param string $subjectPath
  * @param string $expectedConfigPath
  * @dataProvider aroundGetConfigPathDataProvider
  */
 public function testAroundGetConfigPath($subjectPath, $expectedConfigPath)
 {
     $callback = function () {
         return null;
     };
     $this->request->expects($this->once())->method('getParam')->with('section')->will($this->returnValue('payment'));
     $this->subject->expects($this->once())->method('getPath')->will($this->returnValue($subjectPath));
     $this->assertEquals($expectedConfigPath, $this->model->aroundGetConfigPath($this->subject, $callback));
 }
示例#3
0
 public function testGetValidation()
 {
     $this->_model->setData([], 'scope');
     $this->assertNull($this->_model->getValidation());
     $this->_model->setData(['validate' => 'validate'], 'scope');
     $this->assertEquals('validate', $this->_model->getValidation());
 }
示例#4
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];
     }
 }
示例#5
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);
     }
 }
 /**
  * Intercept core config form block getScopeLabel() method
  * to add additional override hints.
  *
  * @see Magento\Config\Block\System\Config\Form::getScopeLabel()
  * @param \Magento\Config\Block\System\Config\Form $form
  * @param callable $getScopeLabel
  * @param Field $field
  * @return Phrase
  */
 public function aroundGetScopeLabel(\Magento\Config\Block\System\Config\Form $form, \Closure $getScopeLabel, Field $field)
 {
     $currentScopeId = null;
     switch ($form->getScope()) {
         case 'websites':
             $currentScopeId = $form->getWebsiteCode();
             break;
         case 'stores':
             $currentScopeId = $form->getStoreCode();
             break;
     }
     $overriddenLevels = $this->helper->getOverriddenLevels($field->getPath(), $form->getScope(), $currentScopeId);
     /* @var $returnPhrase Phrase */
     $labelPhrase = $getScopeLabel($field);
     if (!empty($overriddenLevels)) {
         $scopeHintText = $labelPhrase . $this->helper->formatOverriddenScopes($form, $overriddenLevels);
         // create new phrase, now that constituent strings are translated individually
         $labelPhrase = new Phrase($scopeHintText, $labelPhrase->getArguments());
     }
     return $labelPhrase;
 }
示例#7
0
 /**
  * Get css class for "requires" functionality
  *
  * @param \Magento\Config\Model\Config\Structure\Element\Field $field
  * @param string $fieldPrefix
  * @return string
  */
 protected function _getRequiresCssClass(\Magento\Config\Model\Config\Structure\Element\Field $field, $fieldPrefix)
 {
     $requiresClass = '';
     $requiredPaths = array_merge($field->getRequiredFields($fieldPrefix), $field->getRequiredGroups($fieldPrefix));
     if (!empty($requiredPaths)) {
         $requiresClass = ' requires';
         foreach ($requiredPaths as $requiredPath) {
             $requiresClass .= ' requires-' . $this->_generateElementId($requiredPath);
         }
         return $requiresClass;
     }
     return $requiresClass;
 }
示例#8
0
 /**
  * Set correct scope if isSingleStoreMode = true
  *
  * @param \Magento\Config\Model\Config\Structure\Element\Field $fieldConfig
  * @param \Magento\Framework\App\Config\ValueInterface $dataObject
  * @return void
  */
 protected function _checkSingleStoreMode(\Magento\Config\Model\Config\Structure\Element\Field $fieldConfig, $dataObject)
 {
     $isSingleStoreMode = $this->_storeManager->isSingleStoreMode();
     if (!$isSingleStoreMode) {
         return;
     }
     if (!$fieldConfig->showInDefault()) {
         $websites = $this->_storeManager->getWebsites();
         $singleStoreWebsite = array_shift($websites);
         $dataObject->setScope('websites');
         $dataObject->setWebsiteCode($singleStoreWebsite->getCode());
         $dataObject->setScopeCode($singleStoreWebsite->getCode());
         $dataObject->setScopeId($singleStoreWebsite->getId());
     }
 }
示例#9
0
 /**
  * Field constructor.
  *
  * @param StoreManagerInterface $storeManager     The store Manager
  * @param Manager               $moduleManager    The module Manager
  * @param BackendFactory        $backendFactory   The backend model factory
  * @param SourceFactory         $sourceFactory    The source model factory
  * @param CommentFactory        $commentFactory   The comment factory
  * @param BlockFactory          $blockFactory     The block factory
  * @param Mapper                $dependencyMapper The dependency manager
  * @param Visibility            $visibility       The visibility manager
  */
 public function __construct(StoreManagerInterface $storeManager, Manager $moduleManager, BackendFactory $backendFactory, SourceFactory $sourceFactory, CommentFactory $commentFactory, BlockFactory $blockFactory, Mapper $dependencyMapper, Visibility $visibility)
 {
     parent::__construct($storeManager, $moduleManager, $backendFactory, $sourceFactory, $commentFactory, $blockFactory, $dependencyMapper);
     $this->visibility = $visibility;
 }
示例#10
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);
 }