Symfony3 - MISD Phone Number Bundle format

snoop168

Is it possible to set the format returned by the entity containing a phone number property when using MISD Phone-Number-Bundle? For example I have a property $phoneNumber

When I call $this->getPhoneNumber() it returns the string formatted:

Country Code: 1 National Number: ########## Country Code Source:
but I want it in the format (or similar):
1 (###) ###-####

The reason I want to change this is because in that entity I am implementing the __toString() method and want the string returned to be a combination of 2 properties one being the "nickName" and other being the phone number in this type of format or similar NickName - 1 (###) ###-#### The purpose of this is to display them in a drop down form element setup in a form type I created.

snoop168

I think I solved my own problem... My __toString() method looks like this and seems to do what I want.

use libphonenumber\PhoneNumberUtil;
//...
public function __toString()
{
    $phoneNumberUtil = PhoneNumberUtil::getInstance();
    $number = $phoneNumberUtil->format($this->phoneNumber, \libphonenumber\PhoneNumberFormat::NATIONAL);     

    return $this->nickName . " - " . $number;
}

Anyone see any issues or better ways to do this?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related