Created
November 22, 2014 09:28
-
-
Save dljoseph/374f9a046578edf6fa27 to your computer and use it in GitHub Desktop.
SilverStripe 3.1.x DataObject
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 $singular_name = 'MyDataObject'; | |
private static $plural_name = 'MyDataObjects'; | |
private static $db = array( | |
'Sort' => 'Int' | |
); | |
private static $default_sort = 'Sort'; | |
private static $has_one = array( | |
); | |
private static $has_many = array( | |
); | |
private static $many_many = array( | |
); | |
private static $summary_fields = array( | |
); | |
private static $field_labels = array( | |
); | |
public function getCMSFields(){ | |
$fields = parent::getCMSFields(); | |
$fields->removeByName('Sort'); | |
return $fields; | |
} | |
protected function onBeforeWrite(){ | |
if (!$this->Sort) { | |
$this->Sort = MyDataObject::get()->max('Sort') + 1; | |
} | |
parent::onBeforeWrite(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment