示例#1
0
 /**
  * build a form
  *
  * @param $configData
  * @return $this
  */
 public function buildForm($configData)
 {
     $form = $this->_formFactory->create();
     $this->setForm($form);
     if (!isset($configData['fieldset']) || !is_array($configData['fieldset'])) {
         return $this;
     }
     $hasTooltip = '';
     if ($this->_scopeConfig->isSetFlag(self::XML_TOOLTIPS_ENABLED_PATH)) {
         $hasTooltip = 'has-tooltip';
     }
     foreach ($configData['fieldset'] as $id => $settings) {
         $fieldset = $form->addFieldset($id, ['legend' => isset($settings['label']) ? __($settings['label']) : '', 'class' => 'fieldset-wide' . (isset($settings['class']) ? ' ' . $settings['class'] : ''), 'collapsable' => (int) $this->formConfig->getBoolValue($settings, 'collapsible')]);
         $index = 0;
         foreach ($settings['field'] as $fieldId => $fieldSettings) {
             $fieldType = $this->formConfig->getFieldType($fieldSettings);
             $fieldConfig = ['name' => $fieldId, 'label' => __($fieldSettings['label']), 'title' => $this->escapeHtml(__($fieldSettings['label']))];
             if ($this->formConfig->getBoolValue($fieldSettings, 'required')) {
                 $fieldConfig['required'] = true;
             }
             if ($this->formConfig->getBoolValue($fieldSettings, 'readonly')) {
                 $fieldConfig['readonly'] = true;
             }
             if ($this->_scopeConfig->isSetFlag(self::XML_TOOLTIPS_ENABLED_PATH)) {
                 if (isset($fieldSettings['tooltip']) && $fieldType != 'hidden') {
                     $fieldConfig['after_element_html'] = $this->getTooltipHtml($this->model->getEntityCode(), $fieldSettings['id']);
                 }
             }
             if (isset($fieldSettings['note'])) {
                 $fieldConfig['note'] = $fieldSettings['note'];
             }
             $fieldConfig['class'] = ($index % 2 == 0 ? 'even' : 'odd') . ' ' . $hasTooltip;
             $fieldConfig['css_class'] = $fieldConfig['class'];
             $index++;
             if (isset($fieldSettings['class'])) {
                 $fieldConfig['class'] .= ' ' . $fieldSettings['class'];
             }
             if (isset($fieldSettings['reloader-class'])) {
                 $fieldConfig['class'] .= ' ' . $fieldSettings['reloader-class'];
             }
             if (in_array($fieldType, ['select', 'multiselect'])) {
                 $fieldConfig['values'] = $this->objectManager->get($fieldSettings['source'])->toOptionArray($fieldType == 'select');
             }
             if ($fieldType == 'textarea') {
                 $fieldConfig['rows'] = $this->formConfig->getTextareaRows($fieldSettings);
             }
             $fieldset->addField($fieldSettings['id'], $fieldType, $fieldConfig);
         }
     }
     return $this;
 }
示例#2
0
 /**
  * get field html
  *
  * @param $fieldset
  * @param $key
  * @param $field
  * @return mixed
  */
 protected function getFieldHtml($fieldset, $key, $field)
 {
     $configData = $this->getConfigData();
     $formName = $this->getFormName();
     $path = 'umc/' . $formName . '/' . $key;
     if (isset($configData[$path])) {
         $data = $configData[$path];
     } else {
         $data = $this->getForm()->getConfigValue($path);
     }
     $settings = ['name' => 'groups[' . $formName . '][fields][' . $key . '][value]', 'label' => __($field['label']), 'value' => $data, 'inherit' => false, 'can_use_default_value' => false, 'can_use_website_value' => false];
     $fieldType = $this->formConfig->getFieldType($field);
     if (in_array($fieldType, ['select', 'multiselect'])) {
         $settings['values'] = $this->objectManager->create($field['source'])->toOptionArray($fieldType == 'select');
     }
     if (isset($field['tooltip'])) {
         $settings['tooltip'] = $field['tooltip'];
     }
     $field = $fieldset->addField($formName . $key, $this->formConfig->getFieldType($field), $settings)->setRenderer($this->fieldRenderer);
     return $field->toHtml();
 }