Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » FDOM and Newsletter Module

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 1380 Views
  • mi3ll
    Avatar
    Community Member
    23 Posts

    FDOM and Newsletter Module Link to this post

    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!

  • UncleCheese
    Avatar
    4085 Posts

    Re: FDOM and Newsletter Module Link to this post

    That's some crappy code in the newsletter module. Submit this to Silverstripe.

    $id = $_REQUEST['ID'] ? $_REQUEST['ID'] : $this->currentPageID();

    should be

    $id = (isset($_REQUEST['ID']) && is_numeric($_REQUEST['ID'])) ? $_REQUEST['ID'] : $this->currentPageID();

  • mi3ll
    Avatar
    Community Member
    23 Posts

    Re: FDOM and Newsletter Module Link to this post

    Thanks for the quick reply UncleCheese! That fixed that error, but now it seems that the NewsletterEditForm does not receive an ID??

    Here is the error I receive now when I click the Add Newsletter Attachment Button, any help is very much appreciated!

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

    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/Attachments/upload)
    Line 118 of main.php

    By the way, thanks for that new feature, the intelligent constructor! It works on File DataObject Managers and the like as well I hope?

  • UncleCheese
    Avatar
    4085 Posts

    Re: FDOM and Newsletter Module Link to this post

    I seem to remember that the relationship to the holder has to come first. Try reversing your has_one so it reads:

    static $has_one = array (
    'Newsletter' => 'Newsletter'
    'Attachment' => 'File',
    );

  • mi3ll
    Avatar
    Community Member
    23 Posts

    Re: FDOM and Newsletter Module Link to this post

    I tried the fix but unfortunately I am still getting the same error... I also tried with a complextablefield but I get the same problem...

  • UncleCheese
    Avatar
    4085 Posts

    Re: FDOM and Newsletter Module Link to this post

    What is NewsletterAdmin?

  • mi3ll
    Avatar
    Community Member
    23 Posts

    Re: FDOM and Newsletter Module Link to this post

    It's the Administration Interface class for the Newsletters (extends LeftAndMain). I think since I can't get this working I will try with a single file attachment... Thanks for the help UncleCheese!

    EDIT I tried the FileIFrameField and got the same problem, I think it's something to do with the Newsletter module, so I will try to ask for help in the other forums.

    1380 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.