Skip to content

Instantly share code, notes, and snippets.

@Zauberfisch
Created July 22, 2015 20:10
Show Gist options
  • Save Zauberfisch/ae1d1645e62d7f19b85c to your computer and use it in GitHub Desktop.
Save Zauberfisch/ae1d1645e62d7f19b85c to your computer and use it in GitHub Desktop.
Custom SilverStripe PhoneNumberField
<?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