示例#1
0
 /**
  * Return all the input from the form.
  *
  * @param  FormBuilder $builder
  * @return array
  */
 public function all(FormBuilder $builder)
 {
     $input = [];
     /* @var FieldType $field */
     foreach ($builder->getEnabledFormFields() as $field) {
         $input[$field->getInputName()] = $field->getValidationValue();
     }
     return $input;
 }
 /**
  * Make custom validation messages.
  *
  * @param  FormBuilder $builder
  * @return array
  */
 public function make(FormBuilder $builder)
 {
     $attributes = [];
     /* @var FieldType $field */
     foreach ($builder->getEnabledFormFields() as $field) {
         $label = $field->getLabel();
         if (str_contains($label, '::')) {
             $label = trans($label);
         }
         if ($locale = $field->getLocale()) {
             $label .= ' (' . $locale . ')';
         }
         $attributes[$field->getInputName()] = '"' . $label . '"';
     }
     return $attributes;
 }
示例#3
0
 /**
  * Compile rules from form fields.
  *
  * @param  FormBuilder $builder
  * @return array
  */
 public function compile(FormBuilder $builder)
 {
     $rules = [];
     $entry = $builder->getFormEntry();
     $stream = $builder->getFormStream();
     $locale = $this->config->get('streams::locales.default');
     /* @var FieldType $field */
     foreach ($builder->getEnabledFormFields() as $field) {
         if ($field->isDisabled()) {
             continue;
         }
         if (in_array($field->getField(), $builder->getSkips())) {
             continue;
         }
         $fieldRules = array_filter(array_unique($field->getRules()));
         $fieldRules = $field->extendRules($fieldRules);
         if (!$stream instanceof StreamInterface) {
             $rules[$field->getInputName()] = implode('|', $fieldRules);
             continue;
         }
         if ($assignment = $stream->getAssignment($field->getField())) {
             $type = $assignment->getFieldType();
             if ($type->isRequired()) {
                 $fieldRules[] = 'required';
             }
             if (!isset($fieldRules['unique']) && $assignment->isUnique() && !$assignment->isTranslatable()) {
                 $unique = 'unique:' . $stream->getEntryTableName() . ',' . $field->getColumnName();
                 if ($entry && ($id = $entry->getId())) {
                     $unique .= ',' . $id;
                 }
                 $fieldRules[] = $unique;
             }
             if ($assignment->isTranslatable() && $field->getLocale() !== $locale) {
                 $fieldRules = array_diff($fieldRules, ['required']);
             }
         }
         $rules[$field->getInputName()] = implode('|', array_unique($fieldRules));
     }
     return array_filter($rules);
 }