Skip to content
Permalink
Browse files

Add default validator based on db column

  • Loading branch information...
flack committed Nov 1, 2019
1 parent 357fbf4 commit 91fee2c8b2153cddc2ab92ba00524064cb543b11
Showing with 11 additions and 0 deletions.
  1. +11 −0 src/midcom/datamanager/storage/container/dbacontainer.php
@@ -6,10 +6,13 @@
namespace midcom\datamanager\storage\container;
use midcom_core_dbaobject;
use midgard_reflection_property;
use midcom\datamanager\schema;
use midcom\datamanager\storage\transientnode;
use midcom\datamanager\storage\node;
use midcom\datamanager\storage\blobs;
use midcom\datamanager\storage\property;
use Symfony\Component\Validator\Constraints\Length;
/**
* Experimental storage baseclass
@@ -27,6 +30,8 @@ public function __construct(schema $schema, midcom_core_dbaobject $object, array
$this->object = $object;
$this->schema = $schema;
$rfp = new midgard_reflection_property($object->__mgdschema_class_name__);
foreach ($this->schema->get('fields') as $name => $config) {
if (array_key_exists($name, $defaults)) {
$config['default'] = $defaults[$name];
@@ -37,6 +42,12 @@ public function __construct(schema $schema, midcom_core_dbaobject $object, array
&& (!$this->object->id || $field instanceof transientnode)) {
$field->set_value($config['default']);
}
if ($field instanceof property) {
$type = $rfp->get_midgard_type($config['storage']['location']);
if ($type == MGD_TYPE_STRING) {
$this->schema->get_field($name)['validation'][] = new Length(['max' => 255]);
}
}
$this->fields[$name] = $field;
}

0 comments on commit 91fee2c

Please sign in to comment.
You can’t perform that action at this time.