Created
December 1, 2017 04:37
-
-
Save benald/6e0c49dd5278611039e15c66420ab71d to your computer and use it in GitHub Desktop.
SilverStripe 3.5 Article.php DataObject, for use with ArticlePages.php, FiltersPage.php
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 Article extends DataObject { | |
private static $db = array ( | |
'Title' => 'Varchar', | |
'HideTitle' => 'Boolean', | |
'Date' => 'Date', | |
'Teaser' => 'Text', | |
'Author' => 'Varchar', | |
'Content' => 'HTMLText', | |
'ShowOnHome' => 'Boolean' | |
); | |
private static $has_one = array ( | |
'ArticlesPage' => 'ArticlesPage', | |
'ArticleImage' => 'Image', | |
'Banner' => 'Image', | |
'NewsUrl' => 'Link', | |
'NewsLink' => 'FlexiLink', | |
'NewsDoc' => 'File', | |
'Type' => 'Type', | |
'Approach' => 'Approach', | |
'Service' => 'Service', | |
'Industry' => 'Industry' | |
); | |
private static $summary_fields = array ( | |
'GridThumbnail' => '', | |
'Title' => 'Article Title', | |
'Author' => 'Author', | |
'ShowOnHome' => 'Show On Home Page?' | |
); | |
public function getGridThumbnail() { | |
if($this->ArticleImage()->exists()) { | |
return $this->ArticleImage()->SetWidth(100); | |
} | |
return '(no image)'; | |
} | |
public function getCMSFields() { | |
$fields = FieldList::create( | |
TextField::create('Title'), | |
CheckboxField::create('HideTitle','Hide Page Title'), | |
CheckboxField::create('ShowOnHome','Feature on Home Page'), | |
DateField::create('Date','Article Date')->setConfig('showcalendar', true)->setConfig('dateformat', 'd MMMM yyyy'), | |
TextareaField::create('Teaser'), | |
TextField::create('Author','Author'), | |
$banner = UploadField::create('Banner', 'Overide Default Banner'), | |
$photo = UploadField::create('ArticleImage'), | |
DropdownField::create( | |
'TypeID', | |
'Type', | |
Type::get()->map('ID','Title') | |
)->setEmptyString('-- None --'), | |
DropdownField::create( | |
'IndustryID', | |
'Industry', | |
Industry::get()->map('ID','Title') | |
)->setEmptyString('-- None --'), | |
DropdownField::create( | |
'ApproachID', | |
'Approach', | |
Approach::get()->map('ID','Title') | |
)->setEmptyString('-- None --'), | |
DropdownField::create( | |
'ServiceID', | |
'Service', | |
Service::get()->map('ID','Title') | |
)->setEmptyString('-- None --'), | |
$document = UploadField::create('NewsDoc','Document, optional (PDF only)'), | |
LinkField::create('NewsUrl'), | |
FlexiLinkField::create('NewsLink'), | |
HTMLEditorField::create('Content') | |
); | |
$photo->getValidator()->setAllowedExtensions(array('png','jpg','jpeg')); | |
$photo->setFolderName('photos'); | |
$document->getValidator()->setAllowedExtensions(array('pdf')); | |
$document->setFolderName('articles'); | |
$banner->setFolderName('Banner'); | |
$banner->getValidator()->setAllowedExtensions(array('png','jpeg','jpg')); | |
return $fields; | |
} | |
public function Link() { | |
return $this->ArticlesPage()->Link('article/'.$this->ID); | |
} | |
public function LinkingMode() { | |
return Controller::curr()->getRequest()->param('ID') == $this->ID ? 'current' : 'link'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment