Beispiel #1
0
 /**
  * generate all tooltips
  *
  * @return \Umc\Base\Model\Tooltip[]
  */
 public function getTooltips()
 {
     if (!$this->_scopeConfig->isSetFlag(AbstractTab::XML_TOOLTIPS_ENABLED_PATH)) {
         return [];
     }
     if (is_null($this->tooltips)) {
         $this->tooltips = [];
         foreach ($this->formConfig->getConfig('form') as $entityId => $entitySettings) {
             if (isset($entitySettings['fieldset'])) {
                 foreach ($entitySettings['fieldset'] as $fieldsetSettings) {
                     if (isset($fieldsetSettings['field'])) {
                         foreach ($fieldsetSettings['field'] as $fieldId => $fieldSettings) {
                             if (isset($fieldSettings['tooltip']) && isset($fieldSettings['label'])) {
                                 /** @var \Umc\Base\Model\Tooltip  $tooltip */
                                 $tooltip = $this->factory->create();
                                 $tooltip->setTitle(__($fieldSettings['label']));
                                 $tooltip->setMessage(__($fieldSettings['tooltip']));
                                 $tooltip->setId($entityId . '_' . $fieldId);
                                 $this->tooltips[] = $tooltip;
                             }
                         }
                     }
                 }
             }
         }
     }
     return $this->tooltips;
 }
Beispiel #2
0
 /**
  * setup validation test
  */
 protected function setupValidationTest()
 {
     $this->filePath = dirname(realpath(__DIR__)) . '/_files/';
     $this->formConfigSource = (include $this->filePath . 'form_config_entity.php');
     $this->formConfig->expects($this->any())->method('getConfig')->willReturn($this->formConfigSource['config']['form']['umc_entity']);
     $this->restrictionConfigSource = (include $this->filePath . 'restriction.php');
     $this->restrictionConfig->expects($this->any())->method('getRestrictions')->willReturn($this->restrictionConfigSource['config']['entity']['umc_entity']['restriction']);
 }
Beispiel #3
0
 /**
  * tests Module->validate()
  * validation should fail due to required field
  */
 public function testValidateRequired()
 {
     $this->setupValidationTest();
     $this->module->setNamespace('');
     $map = [array($this->formConfigSource['config']['form']['umc_module']['fieldset']['general']['field']['namespace'], true)];
     $this->formConfig->method('getBoolValue')->will($this->returnValue($map));
     $expected = ['modulenamespace' => [new Phrase('Field %1 is required', ['Module namespace'])]];
     $this->assertEquals($expected, $this->module->validate());
 }
Beispiel #4
0
 /**
  * get form fields
  *
  * @return array
  */
 public function getFields()
 {
     $entities = [$this->moduleInstance->getEntityCode() => __('MODULE'), $this->settingsInstance->getEntityCode() => __('SETTINGS'), $this->entityInstance->getEntityCode() => __('ENTITY'), $this->attributeInstance->getEntityCode() => __('ATTRIBUTE')];
     $data = [];
     foreach ($entities as $entityCode => $entityLabel) {
         $data[] = ['__colspan' => $entityLabel];
         $config = $this->formConfig->getConfig('form/' . $entityCode, true, []);
         foreach ($config['fieldset'] as $fieldset) {
             $data[] = ['__colspan' => $fieldset['label']];
             foreach ($fieldset['field'] as $field) {
                 if ($field['type'] != 'hidden') {
                     $data[] = ['field' => $field['label'], 'type' => $field['type'], 'description' => isset($field['tooltip']) ? $field['tooltip'] : ''];
                 }
             }
         }
     }
     return $data;
 }
Beispiel #5
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();
 }
Beispiel #6
0
 /**
  * prepare the form
  *
  * @return $this
  */
 protected function _prepareForm()
 {
     $configData = $this->formConfig->getConfig('form/' . $this->model->getEntityCode(), true, []);
     $this->buildForm($configData);
     return $this;
 }
Beispiel #7
0
 /**
  * get attribute dependencies as json
  *
  * @return string
  */
 public function getAttributeDepends()
 {
     return $this->formConfig->getDepends($this->attribute->getEntityCode());
 }
Beispiel #8
0
 /**
  * validate field
  *
  * @param $fieldId
  * @param $fieldSettings
  * @return array
  */
 protected function validateField($fieldId, $fieldSettings)
 {
     $errors = [];
     if ($this->formConfig->getBoolValue($fieldSettings, 'required')) {
         $value = trim($this->getData($fieldId));
         if (strlen(trim($value)) == 0) {
             $errors[] = __('Field %1 is required', $fieldSettings['label']);
         }
     }
     $restrictions = $this->restrictionConfig->getRestrictions($this->getEntityCode());
     if (isset($restrictions[$fieldId])) {
         if ($this->restrictionConfig->getBoolValue($restrictions[$fieldId], 'reserved')) {
             $reserved = $this->restrictionConfig->getReservedKeywords();
             if (in_array(strtolower($this->getData($fieldId)), $reserved)) {
                 $errors[] = __('You cannot use "%1" here. It is a PHP reserved keyword', $this->getData($fieldId));
             }
         }
         if (isset($restrictions[$fieldId]['class'])) {
             $magic = $this->restrictionConfig->getMagicRestrictedValues($restrictions[$fieldId]['class']);
             if (in_array(strtolower($this->getData($fieldId)), $magic)) {
                 $errors[] = __('You cannot use "%1" here. it will conflict with the magic getter or setters of the model', $this->getData($fieldId));
             }
         }
         if (isset($restrictions[$fieldId]['val'])) {
             foreach ($restrictions[$fieldId]['val'] as $value) {
                 if ($this->getData($fieldId) == $value['real_val']) {
                     if (isset($value['depend'])) {
                         foreach ($value['depend'] as $dependField => $dependency) {
                             if ($dependency['type'] == 'parent') {
                                 $source = $this->getParent();
                             } elseif ($dependency['type'] == 'grandparent') {
                                 $source = $this->getParent()->getParent();
                             } else {
                                 $source = $this;
                             }
                             $restrictedValues = [];
                             foreach ($dependency['depend_val'] as $val) {
                                 $restrictedValues[] = $val['value'];
                             }
                             if (in_array($source->getDataUsingMethod($dependField), $restrictedValues)) {
                                 if (isset($value['message'])) {
                                     $error = __($value['message']);
                                 } else {
                                     $error = __('"%1" value is not permitted.', $value['real_val']);
                                 }
                                 $errors[] = $error;
                             }
                         }
                     } else {
                         if (isset($value['message'])) {
                             $error = __($value['message']);
                         } else {
                             $error = __('"%1" value is not permitted.', $value['real_val']);
                         }
                         $errors[] = $error;
                     }
                 }
             }
         }
     }
     return $errors;
 }