Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Newsletter - Adding attachment using DOM/ComplexTableField/FileIFrameField


Go to End
Reply


1647 Views

Avatar
mi3ll

Community Member, 24 Posts

12 September 2009 at 2:12pm

Edited: 13/09/2009 2:44am

EDIT Sorry, just found the ticket related to this issue and now know it hasn't been fixed yet. (Ticket #4501)

I'm having a problem trying to add a field for file attachments to a newsletter, but am having problems with an empty ID being returned. I've tried using complextablefield, dataobjectmanager and a fileiframefield.

Newsletter Version: 0.1.1
Silverstripe Version: 2.3.3

Here is my code:

Newsletter.php (my edits)

	static $has_one = array(
		"Parent" => "NewsletterType",
		"Attachment" => "File",
	);

...

	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 FileIFrameField('Attachment', 'Upload an attachment');
		$attachments->setAllowedExtensions( array( 'pdf', 'jpg', 'png', 'gif', 'doc' ) ); 
		$attachments->setFolderName('attachments'); 

      $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;
	}

Error Inside the Iframe:

[Warning] DataObject::get_by_id passed a non-numeric ID #
GET /cms/admin/newsletter/NewsletterEditForm/field/Attachment/iframe

Line 2566 in C:\wamp\www\cms\sapphire\core\model\DataObject.php
Source

2557 				$tableClasses = ClassInfo::dataClassesFor($callerClass);
2558 				$baseClass = array_shift($tableClasses);
2559 				return DataObject::get_one($callerClass,"`$baseClass`.`ID` = $id");
2560 
2561 				// This simpler code will be used by non-DataObject classes that implement DataObjectInterface
2562 			} else {
2563 				return DataObject::get_one($callerClass,"`ID` = $id");
2564 			}
2565 		} else {
2566 			user_error("DataObject::get_by_id passed a non-numeric ID #$id", E_USER_WARNING);
2567 		}
2568 	}
2569 
2570 	/**
2571 	 * Get the name of the base table for this object
2572 	 */

Trace

    * DataObject::get_by_id passed a non-numeric ID #
      Line 2566 of DataObject.php
    * DataObject::get_by_id(Newsletter,)
      Line 510 of NewsletterAdmin.php
    * NewsletterAdmin->getNewsletterEditForm()
      Line 262 of NewsletterAdmin.php
    * NewsletterAdmin->NewsletterEditForm(HTTPRequest)
      Line 162 of Controller.php
    * Controller->handleAction(HTTPRequest)
      Line 129 of RequestHandler.php
    * RequestHandler->handleRequest(HTTPRequest)
      Line 122 of Controller.php
    * Controller->handleRequest(HTTPRequest)
      Line 277 of Director.php
    * Director::handleRequest(HTTPRequest,Session)
      Line 121 of Director.php
    * Director::direct(/admin/newsletter/NewsletterEditForm/field/Attachment/iframe)
      Line 118 of main.php

Any help is greatly appreciated!