Jump to:

10994 Posts in 2728 Topics by 1819 members

All other Modules

SilverStripe Forums » All other Modules » Newsletter - Adding attachment using DOM/ComplexTableField/FileIFrameField

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 1539 Views
  • mi3ll
    Avatar
    Community Member
    24 Posts

    Newsletter - Adding attachment using DOM/ComplexTableField/FileIFrameField Link to this post

    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!

    1539 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.