Advertisement
Guest User

Untitled

a guest
Feb 15th, 2014
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.78 KB | None | 0 0
  1. <?php
  2.  
  3. class ContactPage extends ContactFormPage {
  4.  
  5. static $singular_name = 'Contact Page';
  6. static $plural_name = 'Contacts Pages';
  7. static $description = 'Contact Page is used for simple content, form and Google Maps integration.';
  8. static $icon = '';
  9.  
  10. private static $db = array(
  11. 'GoogleAPIKey' => 'Text',
  12. 'Column1' => 'HTMLText',
  13. 'Column2' => 'HTMLText',
  14. 'FormColumn' => 'HTMLText',
  15. 'Mailto' => 'Varchar(100)',
  16. 'SuccessMsg' => 'HTMLText',
  17. 'MapCenteringPoint' => 'Varchar(255)',
  18. 'Zoomlevel' => 'Varchar(2)'
  19. );
  20.  
  21. private static $has_many = array(
  22. 'Addresses' => 'AddressData'
  23. );
  24.  
  25. function getCMSFields() {
  26.  
  27. // Create Tabs
  28.  
  29. $fields = parent::getCMSFields();
  30.  
  31. // Additional tools to GridField
  32.  
  33. $gridFieldConfig = GridFieldConfig_RecordEditor::create()->addComponents(
  34. new GridFieldToggleBoolean('Published'),
  35. new GridFieldAddExistingSearchButton(),
  36. new GridFieldOrderableRows('SortOrder')
  37. );
  38.  
  39. // Checking for additional Paginator with Show All module
  40.  
  41. if(class_exists('GridFieldPaginatorWithShowAll')){
  42.  
  43. $paginatorComponent = new GridFieldPaginatorWithShowAll(30);
  44. $gridFieldConfig->removeComponentsByType('GridFieldPaginator');
  45.  
  46. }else{
  47.  
  48. $gridFieldConfig->getComponentByType('GridFieldPaginator')->setItemsPerPage(50);
  49. }
  50.  
  51. // Setup GridField Column
  52.  
  53. $gridField = new GridField('Addresses', _t('Content.ADDRESSDATA', 'Addresses:'), $this->Addresses(), $gridFieldConfig);
  54. $t = $fields->findOrMakeTab('Root.GoogleMaps', _t('Content.TABGOOGLEMAPS','GoogleMaps'));
  55. $t->push($gridField);
  56.  
  57. $fields->removeFieldFromTab('Root.Main', 'Content');
  58.  
  59. $fields->findOrMakeTab('Root.Column1', _t('Content.TABCOLUMN1','Column 1'));
  60. $fields->addFieldsToTab('Root.Column1', array(
  61. new HtmlEditorField('Column1', _t('Content.COLUMN1','Column 1'))
  62. ));
  63.  
  64. $fields->findOrMakeTab('Root.Column2', _t('Content.TABCOLUMN2','Column 2'));
  65. $fields->addFieldsToTab('Root.Column2', array(
  66. new HtmlEditorField('Column2', _t('Content.COLUMN1','Column 2'))
  67. ));
  68.  
  69. $fields->findOrMakeTab('Root.GoogleMaps', _t('Content.TABGOOGLEMAPS','GoogleMaps'));
  70. $fields->addFieldsToTab('Root.GoogleMaps', array(
  71. new TextField("GoogleAPIKey", _t('Content.GOOGLEAPIKEY','Google API-key')),
  72. new TextField("MapCenteringPoint", _t('Content.MAPCENTERINGPOINT','Map centering point')),
  73. new TextField("Zoomlevel", _t('Content.ZOOMLEVEL','Zoom level (def. 14)'))
  74. ));
  75.  
  76. $fields->findOrMakeTab('Root.Form', _t('Content.TABFORM','Form'));
  77. $fields->addFieldsToTab('Root.Form', array(
  78. new HtmlEditorField('FormColumn', _t('Content.FORMCOLUMN','Text before Form')),
  79. new EmailField("Mailto", _t('Content.MAILTO','Receivers E-mail')),
  80. new HtmlEditorField("SuccessMsg", _t('Content.SUCCESSMSG','Success message to be displayed after form is sent'))
  81. ));
  82.  
  83. return $fields;
  84. }
  85.  
  86. // For LayoutHolder
  87.  
  88. function RenderAsChild() {
  89. $class = $this->ClassName . "_Controller";
  90. $controller = new $class($this);
  91. return $controller->renderForHolderPage();
  92. }
  93.  
  94. // holder end
  95.  
  96. }
  97.  
  98.  
  99. class ContactPage_Controller extends ContactFormPage_Controller {
  100.  
  101. // For LauputHolder
  102. private static $LayoutTemplate = 'ContactPage';
  103.  
  104. function renderForHolderPage() {
  105. $template = $this->stat('LayoutTemplate');
  106. if ($template) return $this->renderWith(array($template));
  107. else return '';
  108. }
  109. // holder end
  110.  
  111.  
  112. public function ContactForm() {
  113. return ContactForm::create("ContactForm","you@example.com","You've received a new contact form!")
  114. ->addFields(
  115. TextField::create("Name","What is your name?")
  116. ->addExtraClass("col-md-6"),
  117. EmailField::create("Email", "What is your email?")
  118. ->addExtraClass("col-md-6")
  119. )
  120. // You can add fields as strings, too.
  121. ->addField("Your message//Textarea")
  122. ->setSuccessMessage("Thanks for submitting the form!")
  123. ->setSuccessURL($this->Link('success'))
  124. ->setOnBeforeSend(function($data, $form) {
  125. // Do stuff here. Return false to refuse the form.
  126. })
  127. ->setEmailTemplate("MyCustomTemplate")
  128. ->addOmittedField("SomeField")
  129. ->setIntroText("Someone submitted a form. Here's the data.")
  130. ->addSpamProtector(
  131. SimpleQuestionSpamProtector::create()
  132. ->addQuestion("What's the opposite of skinny?","fat")
  133. ->addQuestion("Which is bigger, a lake or an ocean?","ocean")
  134. )
  135. ->render()
  136. ->setLayout("horizontal");
  137. }
  138.  
  139. }
  140.  
  141. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement