- ### SITE CONFIG ###
- <?php
- class CustomSiteConfig extends DataObjectDecorator {
- function extraStatics() {
- return array(
- 'db' => array(
- ),
- 'has_one' => array(
- ),
- 'has_many' => array(
- 'HeaderSlides' => 'HeaderSlide',
- )
- );
- }
- public function updateCMSFields(FieldSet &$fields) {
- $fields->insertBefore(new Tab('Header', 'Header'), 'Access');
- /* HEADER PHOTOS */
- $manager = new SiteConfig_FileDataObjectManager(
- $this->owner,
- 'HeaderSlides', // relation name
- 'HeaderSlide', // class name of the DataObject
- 'Image', // name of the file relation in the DataObject
- array(
- 'Title' => 'Title',
- 'Date' => 'Date',
- 'Comment' => 'Comment',
- ), // headings
- 'getCMSFields_forPopup' // name of the function for the popup fields
- );
- $manager->setParentClass('SiteConfig');
- $manager->setSourceID($this->owner->ID);
- $manager->setAllowedFileTypes(array('JPG', 'jpg', 'PNG', 'png'));
- $manager->setUploadFolder('Uploads/header');
- /**/
- $fields->addFieldToTab('Root.Header', $manager);
- }
- }
- class SiteConfig_FileDataObjectManager extends DataObjectManager {
- function setSourceID($val) {
- if (is_numeric($val)) {
- $this->sourceID = $val;
- }
- }
- function sourceID() {
- if (isset($this->sourceID) && $this->sourceID !== null && is_numeric($this->sourceID)) {
- return $this->sourceID;
- }
- return parent::sourceID();
- }
- }
- ### HEADER SLIDE ###
- <?php
- class HeaderSlide extends DataObject {
- static $db = array (
- 'Date' => 'Date',
- 'Title' => 'Text',
- );
- static $has_one = array (
- 'Image' => 'Image',
- 'SiteConfig' => 'SiteConfig',
- );
- public function getCMSFields_forPopup() {
- $fields = new FieldSet();
- $fields->push(new DatePickerField('Date'));
- $fields->push(new TextField('Title'));
- $fields->push(new FileUploadField('Image','Upload file'));
- return $fields;
- }
- public function onBeforeWrite() {
- parent::onBeforeWrite();
- }
- }