Commit dbee51de authored by Ed Linklater's avatar Ed Linklater

Create proper relationship between SubscriptionPage and MailingList

parent 10f237bd
......@@ -20,6 +20,7 @@ class MailingList extends DataObject {
private static $belongs_many_many = array(
'Newsletters' => "Newsletter",
'SubscriptionPages' => 'SubscriptionPage',
);
private static $singular_name = 'Mailinglist';
......
......@@ -15,13 +15,22 @@ class SubscriptionPage extends Page {
'CustomisedHeading' => 'Text',
'CustomLabel' => 'Text',
'ValidationMessage' => 'Text',
'MailingLists' => 'Text',
'SubmissionButtonText' => 'Varchar',
'SendNotification' => 'Boolean',
'NotificationEmailSubject' => 'Varchar',
'NotificationEmailFrom' => 'Varchar',
"OnCompleteMessage" => "HTMLText",
);
private static $many_many = array(
'MailingLists' => 'MailingList',
);
private static $many_many_extraFields = array(
'MailingLists' => array(
'SortOrder' => 'Int',
),
);
private static $defaults = array(
'Fields' => 'Email',
......@@ -116,26 +125,17 @@ class SubscriptionPage extends Page {
$fieldsSelection->setCellDisabled(array("Email"=>array("Value","Required")));
//Mailing Lists selection
$mailinglists = MailingList::get();
$newsletterSelection = $mailinglists && $mailinglists->count()?
new CheckboxSetField("MailingLists",
$newsletterSelection_config = GridFieldConfig_RelationEditor::create();
$newsletterSelection_config->addComponent(new GridFieldSortableRows('SortOrder'));
$newsletterSelection_config->removeComponent($newsletterSelection_config->getComponentByType('GridFieldAddNewButton'));
$newsletterSelection = new GridField(
'MailingLists',
_t("Newsletter.SubscribeTo", "Newsletters to subscribe to"),
$mailinglists->map('ID', 'FullTitle'),
$mailinglists
):
new LiteralField(
"NoMailingList",
sprintf(
'<p>%s</p>',
sprintf(
'You haven\'t defined any mailing list yet, please go to '
. '<a href=\"%s\">the newsletter administration area</a> '
. 'to define a mailing list.',
singleton('NewsletterAdmin')->Link()
)
)
$this->MailingLists(),
$newsletterSelection_config
);
$subscriptionTab->push(
$newsletterSelection
);
......@@ -193,6 +193,10 @@ class SubscriptionPage extends Page {
function getRequired(){
return (!$this->getField('Required')) ? '{"Email":"1"}' : $this->getField('Required');
}
function MailingLists() {
return $this->getManyManyComponents('MailingLists')->sort('SortOrder');
}
}
/**
......@@ -276,11 +280,8 @@ class SubscriptionPage_Controller extends Page_Controller {
);
$recipientInfoSection->setID("MemberInfoSection");
if($this->MailingLists){
$mailinglists = DataObject::get("MailingList", "ID IN (".$this->MailingLists.")");
}
if(isset($mailinglists) && $mailinglists && $mailinglists->count()>1){
$mailinglists = $this->MailingLists();
if($mailinglists->count() > 1) {
$newsletterSection = new CompositeField(
new LabelField("Newsletters", _t("SubscriptionPage.To", "Subscribe to:"), 4),
new CheckboxSetField("NewsletterSelection","", $mailinglists, $mailinglists->getIDList())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment