- 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);
- }