Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class HomePage extends Page {
- private static $db = array(
- 'VideoCaption' => 'HTMLText',
- 'VideoUrl' => 'Text',
- 'TopRowContent' => 'HTMLText',
- 'WhereRightColumnContent' => 'HTMLText',
- 'BottomRowContent' => 'HTMLText',
- 'HeaderMenuSetID' => 'int',
- 'FooterMenuSetID' => 'int',
- );
- private static $has_one = array(
- 'VideoRowBackground' => 'Image',
- 'VideoPreviewThumbnail' => 'Image',
- 'TopRowBackground' => 'Image',
- );
- function getCMSFields() {
- $fields = parent::getCMSFields();
- $fields ->addFieldToTab('Root.TopRow', new HtmlEditorField('TopRowContent','Content'));
- $fields ->addFieldsToTab('Root.TopRow', new UploadField('TopRowBackground','Row Background Image'));
- $fields ->addFieldToTab('Root.VideoRow', new HtmlEditorField('VideoCaption','Video Caption'));
- $fields ->addFieldToTab('Root.VideoRow', new TextField('VideoUrl','Vimeo Url'));
- $fields ->addFieldsToTab('Root.VideoRow', new UploadField('VideoPreviewThumbnail','Video Preview Thumbnail'));
- $fields ->addFieldsToTab('Root.VideoRow', new UploadField('VideoRowBackground','Row Background Image'));
- $fields ->addFieldToTab('Root.Main', new HtmlEditorField('WhereRightColumnContent','Right Column Content'));
- $fields ->addFieldToTab('Root.BottomRow', new HtmlEditorField('BottomRowContent','Bottom Row Center Column Content'));
- return $fields;
- }
- function getSettingsFields() {
- $fields = parent::getSettingsFields();
- $ddHeaderField = new DropdownField("NewHeaderMenuSetID","Which Menu Set to use for the Header?",
- $this->getExistingMenuSets(), $this->HeaderMenuSetID);
- $ddHeaderField->setEmptyString("Header not linked to a Menu");
- $ddHeaderField->setHasEmptyDefault(true);
- $fields->addFieldToTab('Root.Settings', $ddHeaderField);
- $ddFooterField = new DropdownField("NewFooterMenuSetID","Which Menu Set to use for the Footer?",
- $this->getExistingMenuSets(), $this->FooterMenuSetID);
- $ddFooterField->setEmptyString("Footer not linked to a Menu");
- $ddFooterField->setHasEmptyDefault(true);
- $fields->addFieldToTab('Root.Settings', $ddFooterField);
- return $fields;
- }
- public function getExistingMenuSets()
- {
- if ($MenuSets = DataObject::get('MenuSet'))
- {
- return $MenuSets->map('ID', 'Title');
- }
- else
- {
- return array ('none defined');
- }
- }
- public function onBeforeWrite()
- {
- parent::onBeforeWrite();
- if ($this->NewHeaderMenuSetID != 0) {
- $this->HeaderMenuSetID = $this->NewHeaderMenuSetID;
- } else {
- $this->HeaderMenuSetID = 0;
- }
- if ($this->NewFooterMenuSetID != 0) {
- $this->FooterMenuSetID = $this->NewFooterMenuSetID;
- } else {
- $this->FooterMenuSetID = 0;
- }
- parent::onBeforeWrite();
- }
- }
- class HomePage_Controller extends Page_Controller {
- private static $allowed_actions = array('Form','Faq');
- public function Form() {
- $nameField = new TextField('Name');
- $nameField->setFieldHolderTemplate('FormField_holder_notitle');
- $nameField->setValue('NAME');
- $emailField = new EmailField('Email');
- $emailField->setvalue('EMAIL@EMAIL.COM');
- $emailField->setFieldHolderTemplate('FormField_holder_notitle');
- $fields = new FieldList(
- $nameField,
- $emailField
- );
- $actions = new FieldList(
- new FormAction('submit', 'SUBMIT')
- );
- $form = new Form($this, 'Form', $fields, $actions);
- return $form;
- }
- public function FaqList() {
- $faq = Faq::get()->sort("RAND()")->limit(5);
- return $faq;
- }
- public function init() {
- parent::init();
- // You can include any CSS or JS required by your project here.
- // See: http://doc.silverstripe.org/framework/en/reference/requirements
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement