Example #1
0
 /**
  * Initialize form element
  *
  * @param \Magento\Config\Model\Config\Structure\Element\Field $field
  * @param \Magento\Framework\Data\Form\Element\Fieldset $fieldset
  * @param string $path
  * @param string $fieldPrefix
  * @param string $labelPrefix
  * @return void
  */
 protected function _initElement(\Magento\Config\Model\Config\Structure\Element\Field $field, \Magento\Framework\Data\Form\Element\Fieldset $fieldset, $path, $fieldPrefix = '', $labelPrefix = '')
 {
     $inherit = true;
     $data = null;
     if (array_key_exists($path, $this->_configData)) {
         $data = $this->_configData[$path];
         $inherit = false;
     } elseif ($field->getConfigPath() !== null) {
         $data = $this->getConfigValue($field->getConfigPath());
     } else {
         $data = $this->getConfigValue($path);
     }
     $fieldRendererClass = $field->getFrontendModel();
     if ($fieldRendererClass) {
         $fieldRenderer = $this->_layout->getBlockSingleton($fieldRendererClass);
     } else {
         $fieldRenderer = $this->_fieldRenderer;
     }
     $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)->setWebsite($this->getWebsiteCode())->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_website_value' => $this->canUseWebsiteValue($field->showInWebsite())]);
     $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);
 }
Example #2
0
 public function testGetBackendModelCreatesBackendModel()
 {
     $this->_backendFactoryMock->expects($this->once())->method('create')->with('Magento\\Framework\\Model\\Name')->will($this->returnValue('backend_model_object'));
     $this->_model->setData(['backend_model' => 'Magento\\Framework\\Model\\Name'], 'scope');
     $this->assertEquals('backend_model_object', $this->_model->getBackendModel());
 }
 /**
  * {@inheritdoc}
  */
 public function getBackendModel()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getBackendModel');
     if (!$pluginInfo) {
         return parent::getBackendModel();
     } else {
         return $this->___callPlugins('getBackendModel', func_get_args(), $pluginInfo);
     }
 }