diff --git a/Form/DataTransformer/CustomFieldsGroupToIdTransformer.php b/Form/DataTransformer/CustomFieldsGroupToIdTransformer.php new file mode 100644 index 000000000..662ef42f1 --- /dev/null +++ b/Form/DataTransformer/CustomFieldsGroupToIdTransformer.php @@ -0,0 +1,66 @@ +om = $om; + } + + /** + * Transforms an custom_field_group to a string (id) + * + * @param CustomFieldsGroup|null $customFieldsGroup + * @return string + */ + public function transform($customFieldsGroup) + { + if (null === $customFieldsGroup) { + return ""; + } + + return $customFieldsGroup->getId(); + } + + /** + * Transforms a string (id) to an object (CustomFieldsGroup). + * + * @param string $id + * @return CustomFieldsGroup|null + * @throws TransformationFailedException if object (report) is not found. + */ + public function reverseTransform($id) + { + if (!$id) { + return null; + } + + $customFieldsGroup = $this->om + ->getRepository('ChillCustomFieldsBundle:customFieldsGroup')->find($id) + ; + + if (null === $customFieldsGroup) { + throw new TransformationFailedException(sprintf( + 'Le group avec le numéro "%s" ne peut pas être trouvé!', + $id + )); + } + + return $customFieldsGroup; + } +} \ No newline at end of file