Last active
August 23, 2018 23:40
-
-
Save rotassator/57fc82f7c903d7f18974 to your computer and use it in GitHub Desktop.
SilverStripe: DataObject model example
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 | |
/** | |
* DataObjectExample | |
* | |
* Example description. | |
*/ | |
class DataObjectExample extends DataObject | |
{ | |
/** @var array Database fields */ | |
private static $db = []; | |
/** @var array Related models with one related item */ | |
private static $has_one = []; | |
/** @var array Related models with many related items */ | |
private static $has_many = []; | |
/** @var array Related models with many-many relationship */ | |
private static $many_many = []; | |
/** @var array Field defaults */ | |
private static $defaults = []; | |
/** @var array Fields to display on model admin */ | |
private static $summary_fields = []; | |
/** @var array Search options */ | |
private static $searchable_fields = []; | |
/** @var array Custom field labels */ | |
private static $field_labels = []; | |
/** @var string Default sort order */ | |
private static $default_sort = []; | |
/** | |
* Validate fields | |
* @return RequiredFields List of required fields | |
*/ | |
public function getCMSValidator() | |
{ | |
return new RequiredFields([]); | |
} | |
/** | |
* Customise CMS admin field list | |
* @return FieldList Customised CMS tab set | |
*/ | |
public function getCMSFields() | |
{ | |
$fields = parent::getCMSFields(); | |
return $fields; | |
} | |
/** | |
* Determine if member can view | |
* @param Member $member Member being checked | |
* @return bool True if member has access; false if not | |
* @codeCoverageIgnore | |
*/ | |
public function canView($member = null) | |
{ | |
return $this->canEdit($member); | |
} | |
/** | |
* Determine if member can edit | |
* @param Member $member Member being checked | |
* @return bool True if member has access; false if not | |
* @codeCoverageIgnore | |
*/ | |
public function canEdit($member = null) | |
{ | |
return Permission::check('CMS_ACCESS_CMSMain', 'any', $member); | |
} | |
/** | |
* Determine if member can delete | |
* @param Member $member Member being checked | |
* @return bool True if member has access; false if not | |
* @codeCoverageIgnore | |
*/ | |
public function canDelete($member = null) | |
{ | |
return $this->canEdit($member); | |
} | |
/** | |
* Determine if member can create | |
* @param Member $member Member being checked | |
* @return bool True if member has access; false if not | |
* @codeCoverageIgnore | |
*/ | |
public function canCreate($member = null) | |
{ | |
return $this->canEdit($member); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment