2008-10-03 00:05:45 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parent class of all test pages
|
|
|
|
*/
|
|
|
|
class TestPage extends Page {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* We can only create subclasses of TestPage
|
|
|
|
*/
|
2012-04-12 05:04:39 +02:00
|
|
|
function canCreate($member = null) {
|
2012-08-29 09:44:26 +02:00
|
|
|
// Don't allow creation other than through requireDefaultRecords
|
|
|
|
return false;
|
2008-10-03 00:05:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function requireDefaultRecords(){
|
|
|
|
if($this->class == 'TestPage') return;
|
|
|
|
|
|
|
|
$class = $this->class;
|
|
|
|
if(!DataObject::get_one($class)) {
|
2012-08-29 09:44:26 +02:00
|
|
|
// Try to create common parent
|
|
|
|
$parent = SiteTree::get()
|
|
|
|
->filter('URLSegment', 'feature-test-pages')
|
|
|
|
->First();
|
|
|
|
|
|
|
|
if(!$parent) {
|
|
|
|
$parent = new Page(array(
|
|
|
|
'Title' => 'Feature Test Pages',
|
|
|
|
'Content' => 'A collection of pages for testing various features in the SilverStripe CMS',
|
|
|
|
'ShowInMenus' => 0
|
|
|
|
));
|
|
|
|
$parent->write();
|
|
|
|
$parent->doPublish();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create actual page
|
2008-10-03 00:05:45 +02:00
|
|
|
$page = new $class();
|
2012-08-29 09:44:26 +02:00
|
|
|
$page->Title = str_replace("TestPage","",$class);
|
|
|
|
$page->ShowInMenus = 0;
|
|
|
|
if($parent) $page->ParentID = $parent->ID;
|
2008-10-03 00:05:45 +02:00
|
|
|
$page->write();
|
2012-08-29 09:44:26 +02:00
|
|
|
$page->publish('Stage', 'Live');
|
2008-10-03 00:05:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parent class of all test page controllers
|
|
|
|
*/
|
|
|
|
class TestPage_Controller extends Page_Controller {
|
2008-11-13 22:32:37 +01:00
|
|
|
static $allowed_actions = array(
|
|
|
|
'Form',
|
|
|
|
'save',
|
|
|
|
);
|
|
|
|
|
2008-10-03 00:38:34 +02:00
|
|
|
/**
|
|
|
|
* This form is exactly like the CMS form. It gives us an opportunity to test the fields outside of the CMS context
|
|
|
|
*/
|
|
|
|
function Form() {
|
|
|
|
$fields = $this->getCMSFields();
|
2012-06-29 14:27:32 +02:00
|
|
|
$actions = new FieldList(
|
2009-08-24 08:59:08 +02:00
|
|
|
new FormAction("save", "Save"),
|
2012-06-29 14:27:32 +02:00
|
|
|
$gohome = new FormAction("gohome", "Go home")
|
2009-08-24 08:59:08 +02:00
|
|
|
);
|
2012-06-29 14:27:32 +02:00
|
|
|
$gohome->setAttribute('src', 'frameworktest/images/test-button.png');
|
2008-10-03 00:38:34 +02:00
|
|
|
$form = new Form($this, "Form", $fields, $actions);
|
|
|
|
$form->loadDataFrom($this->dataRecord);
|
|
|
|
return $form;
|
|
|
|
}
|
2008-10-03 00:05:45 +02:00
|
|
|
|
2008-10-03 00:38:34 +02:00
|
|
|
function save($data, $form) {
|
|
|
|
$form->saveInto($this->dataRecord);
|
|
|
|
$this->dataRecord->write();
|
|
|
|
Director::redirectBack();
|
|
|
|
}
|
2008-11-13 22:32:37 +01:00
|
|
|
|
2009-08-24 08:59:08 +02:00
|
|
|
function gohome() {
|
|
|
|
Director::redirect("./");
|
|
|
|
}
|
2009-08-25 07:49:13 +02:00
|
|
|
|
|
|
|
function EmailForm() {
|
2012-06-29 14:27:32 +02:00
|
|
|
return new Form($this, "EmailForm", new FieldList(
|
2009-08-25 07:49:13 +02:00
|
|
|
new TextField("Email", "Email address")
|
2012-06-29 14:27:32 +02:00
|
|
|
), new FieldList(
|
2009-08-25 07:49:13 +02:00
|
|
|
new FormAction("sendEmail", "Send test email to this address")
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
function email() {
|
|
|
|
return array(
|
|
|
|
'Content' => '<p>Use this form to send a test email</p>',
|
|
|
|
'Form' => $this->EmailForm()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function sendEmail($data, $form) {
|
|
|
|
$email = new Email();
|
|
|
|
$email->setTo($data['Email']);
|
|
|
|
$email->setFrom($data['Email']);
|
|
|
|
$email->setSubject('A subject with some umlauts: öäüß');
|
|
|
|
$email->setBody('A body with some umlauts: öäüß');
|
|
|
|
$email->send();
|
|
|
|
|
|
|
|
echo "<p>email sent to " . $data['Email'] . "</p>";
|
|
|
|
}
|
2008-10-03 00:05:45 +02:00
|
|
|
}
|
2012-04-12 05:04:39 +02:00
|
|
|
?>
|