Created
July 22, 2015 20:10
-
-
Save Zauberfisch/ae1d1645e62d7f19b85c to your computer and use it in GitHub Desktop.
Custom SilverStripe PhoneNumberField
This file contains hidden or 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