Created
November 25, 2014 15:45
-
-
Save anonymous/f0bb9e1e0e9c07877949 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 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