From d994479638edbb82d42c95fdc231f125ebeae43a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Gertz?= Date: Mon, 28 Dec 2020 08:32:16 +0100 Subject: [PATCH] Cleanup --- Form/Extension/Type/HiddenEntityType.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Form/Extension/Type/HiddenEntityType.php b/Form/Extension/Type/HiddenEntityType.php index 3e85cc6..2dfabf7 100644 --- a/Form/Extension/Type/HiddenEntityType.php +++ b/Form/Extension/Type/HiddenEntityType.php @@ -61,11 +61,6 @@ class HiddenEntityType extends HiddenType implements DataTransformerInterface { * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options): void { - #$this->entityClass = sprintf('App\Entity\%s', ucfirst($builder->getName())); - #var_dump($builder->getName()); - #$this->entityClass = sprintf('App\Entity\%s', ucfirst($builder->getName())); - //$this->dataClass[$builder->getName()] = $options['data_class']; - //Set class from options['class'] $this->class = $options['class']; @@ -80,6 +75,12 @@ class HiddenEntityType extends HiddenType implements DataTransformerInterface { $builder->addModelTransformer(clone $this); } + /** + * Transform data to string + * + * @param mixed $data The data object + * @return string The object id + */ public function transform($data): string { // Modified from comments to use instanceof so that base classes or interfaces can be specified if ($data === null || !$data instanceof $this->class) { @@ -91,6 +92,12 @@ class HiddenEntityType extends HiddenType implements DataTransformerInterface { return $res; } + /** + * Reverse transformation from string to data object + * + * @param string $data The object id + * @return mixed The data object + */ public function reverseTransform($data) { if (!$data) { return null; @@ -105,7 +112,7 @@ class HiddenEntityType extends HiddenType implements DataTransformerInterface { } if ($res === null) { - throw new TransformationFailedException(sprintf('A %s with id "%s" does not exist!', $this->class, $data)); + throw new TransformationFailedException(sprintf('A %s with id %s does not exist!', $this->class, $data)); } return $res; -- 2.41.1