Skip to content

Commit

Permalink
Allow empty PhoneNumber object to be transformed in form
Browse files Browse the repository at this point in the history
  • Loading branch information
nicodemuz authored Sep 25, 2024
1 parent bd34462 commit 90b1e23
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Form/DataTransformer/PhoneNumberToArrayTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public function transform(mixed $value): array
throw new TransformationFailedException('Expected a \libphonenumber\PhoneNumber.');
}

if (!$value->hasCountryCode() && !$value->hasNationalNumber()) {
return ['country' => '', 'number' => ''];
}

$util = PhoneNumberUtil::getInstance();

if (false === \in_array($util->getRegionCodeForNumber($value), $this->countryChoices)) {
Expand Down

0 comments on commit 90b1e23

Please sign in to comment.