/** * get name restrictions * * @param $entityCode * @return array */ protected function getNamingRestrictions($entityCode) { $restrict = []; $restrictions = $this->restrictionConfig->getRestrictions($entityCode, []); foreach ($restrictions as $restriction) { $groupRestriction = []; foreach ($restriction['val'] as $val) { $message = isset($val['message']) ? __($val['message'])->render() : __('value is not permitted.')->render(); if (!isset($groupRestriction[$restriction['id']])) { $groupRestriction[$restriction['id']] = []; } if (!isset($groupRestriction[$restriction['id']][$message])) { $groupRestriction[$restriction['id']][$message] = []; } $groupRestriction[$restriction['id']][$message][] = $val['real_val']; } foreach ($groupRestriction as $fieldId => $messages) { foreach ($messages as $oneMessage => $restrictedValues) { $restrict[] = ['field' => $this->formConfig->getFieldLabelByCode($entityCode, $fieldId, $fieldId), 'value' => implode(', ', $restrictedValues), 'message' => $oneMessage]; } } if ($this->restrictionConfig->getBoolValue($restriction, 'reserved')) { $restrict[] = ['field' => $this->formConfig->getFieldLabelByCode($entityCode, $restriction['id'], $restriction['id']), 'value' => implode(', ', $this->restrictionConfig->getReservedKeywords()), 'message' => __('These are PHP reserved keywords')]; } if (isset($restriction['class'])) { $magic = $this->restrictionConfig->getMagicRestrictedValues($restriction['class']); if (count($magic)) { $restrict[] = ['field' => $this->formConfig->getFieldLabelByCode($entityCode, $restriction['id'], $restriction['id']), 'value' => implode(', ', $magic), 'message' => __('These values would conflict with the magic getters and setters of the generated model')]; } } } return $restrict; }
/** * 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; }