Skip to content

Commit

Permalink
Merge pull request #179 from nicodemuz/master
Browse files Browse the repository at this point in the history
Allow empty PhoneNumber object to be transformed in form
  • Loading branch information
odolbeau authored Nov 8, 2024
2 parents ac4ea98 + 8831c87 commit 2d5ff5f
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 2d5ff5f

Please sign in to comment.