Permalink
Browse files

Add support for dm2 regex validation

  • Loading branch information...
flack committed Sep 2, 2018
1 parent 983829f commit 08f4ccdd41ecf59cbd42e2e6ca147b11b9298c5c
Showing with 7 additions and 0 deletions.
  1. +7 −0 src/midcom/datamanager/schema.php
@@ -21,6 +21,7 @@
use Symfony\Component\Form\Extension\Core\Type\FormType;
use midcom\datamanager\extension\type\toolbar;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Validator\Constraints\Regex;
/**
* Experimental schema class
@@ -328,6 +329,12 @@ private function resolve_field_options(array $config, $name)
$rule = array_merge($defaults, $rule);
if ($rule['type'] === 'email') {
$validation[] = new Email();
} elseif ($rule['type'] === 'regex') {
$r_options = ['pattern' => $rule['format']];
if (!empty($rule['message'])) {
$r_options['message'] = $rule['message'];
}
$validation[] = new Regex($r_options);
} else {
throw new midcom_error($rule['type'] . ' validation not implemented yet');
}

0 comments on commit 08f4ccd

Please sign in to comment.