-
-
Save muskie9/5bd087629b91f887b04a to your computer and use it in GitHub Desktop.
Custom SilverStripe PhoneNumberField
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
class MyDataObject extends DataObject { | |
private static $db = [ | |
'FoobarCountryCode' => 'Varchar', | |
'FoobarAreaCode' => 'Varchar', | |
'FoobarPhoneNumber' => 'Varchar', | |
'FoobarExtension' => 'Varchar', | |
]; | |
public function getCMSFields() { | |
return new FieldList([ | |
new MyPhoneNumberField('Foobar', 'Enter your phone number'), | |
]); | |
} | |
} | |
*/ | |
class MyPhoneNumberField extends PhoneNumberField { | |
public function saveInto(DataObjectInterface $record) { | |
list( $countryCode, $areaCode, $phoneNumber, $extension ) = $this->parseValue(); | |
$fieldName = $this->name; | |
$record->{"{$fieldName}CountryCode"} = $countryCode; | |
$record->{"{$fieldName}AreaCode"} = $areaCode; | |
$record->{"{$fieldName}PhoneNumber"} = $phoneNumber; | |
$record->{"{$fieldName}Extension"} = $extension; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment