1. ### SITE CONFIG ###
  2. <?php
  3. class CustomSiteConfig extends DataObjectDecorator {
  4. function extraStatics() {
  5. return array(
  6. 'db' => array(
  7. ),
  8. 'has_one' => array(
  9. ),
  10. 'has_many' => array(
  11. 'HeaderSlides' => 'HeaderSlide',
  12. )
  13. );
  14. }
  15. public function updateCMSFields(FieldSet &$fields) {
  16. $fields->insertBefore(new Tab('Header', 'Header'), 'Access');
  17. /* HEADER PHOTOS */
  18. $manager = new SiteConfig_FileDataObjectManager(
  19. $this->owner,
  20. 'HeaderSlides', // relation name
  21. 'HeaderSlide', // class name of the DataObject
  22. 'Image', // name of the file relation in the DataObject
  23. array(
  24. 'Title' => 'Title',
  25. 'Date' => 'Date',
  26. 'Comment' => 'Comment',
  27. ), // headings
  28. 'getCMSFields_forPopup' // name of the function for the popup fields
  29. );
  30. $manager->setParentClass('SiteConfig');
  31. $manager->setSourceID($this->owner->ID);
  32. $manager->setAllowedFileTypes(array('JPG', 'jpg', 'PNG', 'png'));
  33. $manager->setUploadFolder('Uploads/header');
  34. /**/
  35. $fields->addFieldToTab('Root.Header', $manager);
  36. }
  37. }
  38. class SiteConfig_FileDataObjectManager extends DataObjectManager {
  39. function setSourceID($val) {
  40. if (is_numeric($val)) {
  41. $this->sourceID = $val;
  42. }
  43. }
  44. function sourceID() {
  45. if (isset($this->sourceID) && $this->sourceID !== null && is_numeric($this->sourceID)) {
  46. return $this->sourceID;
  47. }
  48. return parent::sourceID();
  49. }
  50. }
  51. ### HEADER SLIDE ###
  52. <?php
  53. class HeaderSlide extends DataObject {
  54. static $db = array (
  55. 'Date' => 'Date',
  56. 'Title' => 'Text',
  57. );
  58. static $has_one = array (
  59. 'Image' => 'Image',
  60. 'SiteConfig' => 'SiteConfig',
  61. );
  62. public function getCMSFields_forPopup() {
  63. $fields = new FieldSet();
  64. $fields->push(new DatePickerField('Date'));
  65. $fields->push(new TextField('Title'));
  66. $fields->push(new FileUploadField('Image','Upload file'));
  67. return $fields;
  68. }
  69. public function onBeforeWrite() {
  70. parent::onBeforeWrite();
  71. }
  72. }