phone-number-bundle
phone-number-bundle copied to clipboard
Unable to transform value for property path phone_number
Entity entries: /** * @ORM\Column(type="phone_number", nullable=true) * @AssertPhoneNumber(defaultRegion="US", message="Please specify a valid phone number") */ private $phoneNumber;
DBAL Mapping: doctrine: dbal: types: phone_number: Misd\PhoneNumberBundle\Doctrine\DBAL\Types\PhoneNumberType
Form: ->add('phoneNumber', PhoneNumberType::class, array('default_region' => 'US', 'format' => PhoneNumberFormat::NATIONAL, 'required' => false))
But still I get the below error, Can someone let me know how to resolve this? I wrote few lines of code to convert the string to PhoneNumber obj then the form loads fine but my question is do we need to explicitly convert this? Is this not to be handled automatically? if($user->getphoneNumber()!="") { $util = $this->container->get('libphonenumber.phone_number_util'); $phoneNUmber = $util->parse($user->getphoneNumber(), "US"); $user->setphoneNumber($phoneNUmber); } else { $phoneNUmber = new \libphonenumber\PhoneNumber; $user->setphoneNumber($phoneNUmber); }
Uncaught PHP Exception Symfony\Component\Form\Exception\TransformationFailedException: "Unable to transform value for property path "phone_number": Expected a \libphonenumber\PhoneNumber." at /var/www/example/webapp/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 1149 {"exception":"[object] (Symfony\Component\Form\Exception\TransformationFailedException(code: 0): Unable to transform value for property path "phone_number": Expected a \libphonenumber\PhoneNumber. at /var/www/example/webapp/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php:1149, Symfony\Component\Form\Exception\TransformationFailedException(code: 0): Expected a \libphonenumber\PhoneNumber. at /var/www/example/webapp/vendor/misd/phone-number-bundle/Form/DataTransformer/PhoneNumberToStringTransformer.php:62)
Please format the code using the appropriate tags, otherwise it's difficult to read your message. Btw, as the error says the form type expects the value as a PhoneNumber
object in the backend side. It will then take that object, format it according to the defined options and will render the input in the "view" (HTML)
Hi There,
I have poster the same question on stackoverflow. Can you please refer to the solution I posted on stackoverflow.com?
https://stackoverflow.com/questions/40463113/symfony2-misd-phonnumberbundle-unable-to-transform-value-for-property-path-p
Thanks
Dhananjay
From: Rikijs [email protected] Sent: 08 March 2018 00:48 To: misd-service-development/phone-number-bundle [email protected] Cc: dhananjay88 [email protected]; Author [email protected] Subject: Re: [misd-service-development/phone-number-bundle] Unable to transform value for property path phone_number (#103)
Hello! dhananjay88 how did you resolve your problem? Where did you place your snippet? I am hitting the same error, yet i have done everything in the docs. Maybe there should be mention of common errors and solutions.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/misd-service-development/phone-number-bundle/issues/103#issuecomment-371252095 , or mute the thread https://github.com/notifications/unsubscribe-auth/AVaEBEyvrQegpRc6y6lfSuS4aVaQ-wTLks5tcDJIgaJpZM4KrB8j . https://github.com/notifications/beacon/AVaEBPhaMEGaHuo3UNqs8QhY2KUPdalOks5tcDJIgaJpZM4KrB8j.gif
Thank you for your answer.