mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
Abstracted fields onto BlogRole from subscribe form, added some documentation about what it does
This commit is contained in:
parent
d971db30d0
commit
fe23b0cef9
@ -2,6 +2,9 @@
|
||||
|
||||
class BlogRole extends DataObjectDecorator {
|
||||
|
||||
/**
|
||||
* Extend the member table with some extra fields.
|
||||
*/
|
||||
function extraDBFields() {
|
||||
return array(
|
||||
'db' => array(
|
||||
@ -10,6 +13,27 @@ class BlogRole extends DataObjectDecorator {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* These fields are used for the newsletter subscription form.
|
||||
*/
|
||||
function subscribeFields() {
|
||||
return new FieldSet(
|
||||
new TextField('FirstName', 'Your first name'),
|
||||
new TextField('Surname', 'Your surname'),
|
||||
new EmailField('Email', 'Your email')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* These are the required fields for the newsletter subscription form.
|
||||
*/
|
||||
function subscribeRequiredFields() {
|
||||
return new RequiredFields(array(
|
||||
'FirstName',
|
||||
'Email'
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ class ConfirmNewsletterSignup extends Controller {
|
||||
Requirements::themedCSS('typography');
|
||||
Requirements::themedCSS('form');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action for signing up a member to a given group in NewsletterSignupForm.
|
||||
* Used as mysite.com/confirm-subscription/member/123 (where 123 is a md5 hash to find the member)
|
||||
|
@ -3,9 +3,8 @@
|
||||
class NewsletterSignupForm extends Form {
|
||||
|
||||
/**
|
||||
* Gets a NewsletterType which is associated with the BlogHolder, the
|
||||
* controller of this sign up form. It then uses the relationship getter
|
||||
* to find the Group of a NewsletterType.
|
||||
* Get the group code of the newsletter associated with the
|
||||
* BlogHolder instance that this form was created from.
|
||||
*/
|
||||
function get_group_code() {
|
||||
if($controller = $this->controller) {
|
||||
@ -17,26 +16,32 @@ class NewsletterSignupForm extends Form {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the NewsletterSignupForm.
|
||||
* Take the fields and required fields from the extension role.
|
||||
*/
|
||||
function __construct($controller, $name) {
|
||||
$member = singleton('Member');
|
||||
|
||||
$fields = $member->subscribeFields();
|
||||
|
||||
$validator = $member->subscribeRequiredFields();
|
||||
|
||||
$fields = new FieldSet(
|
||||
new TextField('FirstName', 'Your first name'),
|
||||
new TextField('Surname', 'Your surname'),
|
||||
new EmailField('Email', 'Your email')
|
||||
);
|
||||
|
||||
$validator = new RequiredFields(array(
|
||||
'FirstName',
|
||||
'Email'
|
||||
));
|
||||
|
||||
$actions = new FieldSet(
|
||||
new FormAction('subscribe', 'Subscribe')
|
||||
);
|
||||
|
||||
|
||||
parent::__construct($controller, $name, $fields, $actions, $validator);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* NewsletterSignupForm action.
|
||||
* Requires that the email address be submitted in the form.
|
||||
*
|
||||
* Checks if there is a member in the system by submitted email, and checks if
|
||||
* that member has already signed up. If member has, then form gives message and
|
||||
* redirects back. If not, then it carries on with the process.
|
||||
*/
|
||||
function subscribe($data, $form) {
|
||||
$SQL_email = $data['Email'];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user