From 44ea82c5ef4eb2a80ceabe50046be8858a4a464a Mon Sep 17 00:00:00 2001 From: vasu Date: Sun, 16 Dec 2012 19:05:44 +0400 Subject: [PATCH] problem with import aliases & export to object --- core/Form/Form.class.php | 18 ++++++++++-------- core/Form/FormUtils.class.php | 6 ++++++ core/Form/PlainForm.class.php | 2 +- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/core/Form/Form.class.php b/core/Form/Form.class.php index f94abc892e..351d39a8af 100644 --- a/core/Form/Form.class.php +++ b/core/Form/Form.class.php @@ -427,19 +427,13 @@ private function importPrimitive($scope, BasePrimitive $prm) **/ private function checkImportResult(BasePrimitive $prm, $result) { - if ( - $prm instanceof PrimitiveAlias - && $result !== null - ) - $this->markGood($prm->getInner()->getName()); - $name = $prm->getName(); - if (null === $result) { + if ($result === null) { if ($prm->isRequired()) $this->errors[$name] = self::MISSING; - } elseif (true === $result) { + } elseif ($result === true) { unset($this->errors[$name]); } elseif ($error = $prm->getCustomError()) { @@ -448,6 +442,14 @@ private function checkImportResult(BasePrimitive $prm, $result) } else $this->errors[$name] = self::WRONG; + + if ( + $prm instanceof PrimitiveAlias + && $this->primitiveExists($prm->getInner()->getName()) + && $result === true + ) { + unset($this->errors[$prm->getInner()->getName()]); + } return $this; } diff --git a/core/Form/FormUtils.class.php b/core/Form/FormUtils.class.php index d877b6dcdc..f107671524 100644 --- a/core/Form/FormUtils.class.php +++ b/core/Form/FormUtils.class.php @@ -68,6 +68,12 @@ final class FormUtils extends StaticFactory foreach ($form->getPrimitiveList() as $name => $prm) { if (isset($list[$name])) { $proto->exportPrimitive($name, $prm, $object, $ignoreNull); + + } elseif ( + $prm instanceof PrimitiveAlias + && isset($list[$prm->getInner()->getName()]) + ) { + $proto->exportPrimitive($prm->getInner()->getName(), $prm->getInner(), $object, $ignoreNull); } } } else { diff --git a/core/Form/PlainForm.class.php b/core/Form/PlainForm.class.php index 303ec94c9d..1fdd2a9664 100644 --- a/core/Form/PlainForm.class.php +++ b/core/Form/PlainForm.class.php @@ -53,7 +53,7 @@ public function add(BasePrimitive $prm) Assert::isFalse( isset($this->primitives[$name]), - 'i am already exists!' + 'primitive name "'.$name.'" already exists!' ); $this->primitives[$name] = $prm;