Skip to content

Instantly share code, notes, and snippets.

Created November 25, 2014 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/f0bb9e1e0e9c07877949 to your computer and use it in GitHub Desktop.
Save anonymous/f0bb9e1e0e9c07877949 to your computer and use it in GitHub Desktop.
<?php
class ServicePage extends Page {
private static $db = array(
'DominantColor' => 'Text'
);
static $has_one = array(
'ServiceImage' => 'Image'
);
function getCMSFields(){
$fields = parent::getCMSFields();
$config = GridFieldConfig_RecordEditor::create();
$fields->addFieldsToTab('Root.ServiceIcon', array(
UploadField::create('ServiceImage'),
TextField::create('DominantColor')
));
return $fields;
}
function getDominantColor(){
$colour = $this->getField('DominantColor');
if($colour){
return $colour;
}else{
$ParentID = $this->ParentID;
$ParentPage = Page::get()->filter('ID',$ParentID)->First();
if($ParentID == 0){
return False;
}
if($ParentPage->getDominantColor()){
return $ParentPage->getDominantColor();
}
}
}
function ParentServiceImage(){
$image = $this->ServiceImage();
if($this->ServiceImage()){
return $this->ServiceImage();
}else{
$ParentID = $this->ParentID;
$ParentPage = Page::get()->filter('ID',$ParentID)->First();
if($ParentID == 0){
return False;
}
if($ParentPage->ParentServiceImage()){
return $ParentPage->ParentServiceImage();
}
}
}
}
class ServicePage_Controller extends Page_Controller {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment