-
-
Save hailwood/0126c5facb856611b257 to your computer and use it in GitHub Desktop.
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 TeamMember extends DataObject { | |
public static $default_sort = 'SortOrder'; | |
private static $db = [ | |
'Title' => 'Varchar', | |
'ShortName' => 'Varchar', | |
'Position' => 'Varchar', | |
'Content' => 'HTMLText', | |
'Phone' => 'Varchar', | |
'Email' => 'Varchar', | |
'SortOrder' => 'Int', | |
'Displayed' => 'Boolean' | |
]; | |
private static $has_one = [ | |
'Image' => 'Image' | |
]; | |
private static $belongs_many_many = [ | |
'OurPeoplePages' => 'OurPeoplePage', | |
'ContactPages' => 'ContactPage', | |
]; | |
private static $field_labels = [ | |
'Title' => 'Name', | |
'ShortName' => 'Short Name', | |
'Position' => 'Position', | |
'Email' => 'Email', | |
'Phone' => 'Phone', | |
'Image' => 'Image', | |
'ImageID' => 'The Image ID', | |
'Displayed' => 'Display team member on site', | |
'Content' => 'Content' | |
]; | |
private static $summary_fields = [ | |
'Name', | |
'Position', | |
'Published' | |
]; | |
public function getCMSFields() { | |
$fields = parent::getCMSFields(); | |
$fields->addFieldToTab('Root.Main', TextField::create('Title')); | |
$fields->addFieldToTab('Root.Main', TextField::create('ShortName')); | |
$fields->addFieldToTab('Root.Main', TextField::create('Position')); | |
$fields->addFieldToTab('Root.Main', EmailField::create('Email')); | |
$fields->addFieldToTab('Root.Main', TextField::create('Phone')); | |
$fields->addFieldToTab('Root.Main', $uploadField = UploadField::create('Image')); | |
$fields->addFieldToTab('Root.Main', CheckboxField::create('Displayed')); | |
$fields->addFieldToTab('Root.Main', $contentField = HtmlEditorField::create('Content')); | |
/** @var UploadField $uploadField */ | |
$uploadField->setFolderName('TeamMembers'); | |
$fields->removeFieldFromTab('Root.Main', 'SortOrder'); | |
$contentField->setRows(15); | |
return $fields; | |
} | |
public function getCMSValidator() { | |
return new RequiredFields(['Title', 'ShortName', 'Position']); | |
} | |
public function Name() { | |
return $this->Title; | |
} | |
public function Published() { | |
return $this->Displayed ? 'Yes' : 'No'; | |
} | |
public function canView($member = null) { | |
return true; | |
} | |
public function canEdit($member = null) { | |
return true; | |
} | |
public function canDelete($member = null) { | |
return true; | |
} | |
public function canCreate($member = null) { | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment