I was having a trial with the newsletter module and want to give the ability for clients to add attachments to their e-mails, so I am trying to use the File Data Object Manager to allow this, but I keep getting an Undefined Index: ID error when I click Add Newsletter Attachments. Here is the code I have:
Newsletter.php
static $has_many = array(
"Recipients" => "Newsletter_Recipient",
"SentRecipients" => "Newsletter_SentRecipient",
"Attachments" => "NewsletterAttachment"
);
...
function getCMSFields($controller = null) {
$group = DataObject::get_by_id("Group", $this->Parent()->GroupID);
$sent_status_report = $this->renderWith("Newsletter_SentStatusReport");
//$previewLink = Director::absoluteBaseURL() . 'admin/newsletter/preview/' . $this->ID;
$attachments = new FileDataObjectManager(
$this,
'Attachments',
'NewsletterAttachment',
'Attachment',
array(
'Title' => 'Title',
'Description' => 'Description'
),
'getCMSFields_forPopup'
);
$ret = new FieldSet(
new TabSet("Root",
$mailTab = new Tab(_t('Newsletter.NEWSLETTER', 'Newsletter'),
new TextField("Subject", _t('Newsletter.SUBJECT', 'Subject'), $this->Subject),
new HtmlEditorField("Content", _t('Newsletter.CONTENT', 'Content'))
),
$attachTab = new Tab(_t('Newsletter.ATTACHMENTS', 'Attachments'),
$attachments
),
$sentToTab = new Tab(_t('Newsletter.SENTREPORT', 'Sent Status Report'),
new LiteralField("Sent Status Report", $sent_status_report)
)
)
);
if($this->Status != 'Draft') {
$mailTab->push( new ReadonlyField("SendDate", _t('Newsletter.SENTAT', 'Sent at'), $this->SendDate) );
}
return $ret;
}
NewsletterAttachment.php
<?php
/**
* Single attachment to a newsletter
*
* @package newsletter
*/
class NewsletterAttachment extends DataObject
{
static $db = array (
'Title' => 'Varchar',
'Description' => 'Text',
);
static $has_one = array (
'Attachment' => 'File',
'Newsletter' => 'Newsletter'
);
public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('Title'),
new TextareaField('Description', 'Description', 2),
new FileIFrameField('Attachment')
);
}
}
And here is the more detailed error:
[Notice] Undefined index: ID
GET /cms/admin/newsletter/NewsletterEditForm/field/Attachments/upload/
Line 261 in C:\wamp\www\cms\newsletter\code\NewsletterAdmin.php
Source
252 } else {
253 $form = $this->TypeEditForm();
254 }
255 }
256 if($form) $form->disableDefaultAction();
257 return $form;
258 }
259
260 public function NewsletterEditForm() {
261 $id = $_REQUEST['ID'] ? $_REQUEST['ID'] : $this->currentPageID();
262 if(!is_numeric($id)) {
263 $id = 0;
264 }
265 return $this->getNewsletterEditForm($id);
266 }
267
I've dug around the newsletter code and I think it might be a problem with the unusual way the newsletter gets the edit form??
Any help would be appreciated!