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 Image Upload


Reply


5 Posts   1077 Views

Avatar
stevanovich

Community Member, 60 Posts

5 November 2010 at 4:31am

Okay I have spent sometime trying to fine an answer to my problem but cannot seem to find one. I need to upload an image to a newsletter draft in the cms, I don't want to use tinymce as I want to position them using the template. Any help greatly appreciated.

This the code I have tried to add to the newsletter.php but get a error saying:

[User Error] Unknown Email ID: 0
GET /admin/newsletter/NewsletterEditForm/field/MainImage/iframe

Line 548 in /var/www/web56/web/newsletter/code/NewsletterAdmin.php

newsletter.php
===============

/**
* Single newsletter instance. Each Newsletter belongs to a NewsletterType.
*
* @package newsletter
*/
class Newsletter extends DataObject {

   static $db = array(
      "Status" => "Enum('Draft, Send', 'Draft')",
      "Content" => "HTMLText",
      "Subject" => "Varchar(255)",
      "SentDate" => "Datetime",
      
   );

   static $has_one = array(
         "MainImage" => "Image",   
      "Parent" => "NewsletterType",
      
   );

   static $has_many = array(
      "Recipients" => "Newsletter_Recipient",
      "SentRecipients" => "Newsletter_SentRecipient",

   );

   /**
    * Returns a FieldSet with which to create the CMS editing form.
    * You can use the extend() method of FieldSet to create customised forms for your other
    * data objects.
    *
    * @param Controller
    * @return FieldSet
    */
   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;

      $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')),
               new ImageField("MainImage", _t('Newsletter.IMAGE', 'Photo')),
            
               new LiteralField('PreviewNewsletter', "<a href=\"$previewLink\" target=\"_blank\">" . _t('PREVIEWNEWSLETTER', 'Preview this newsletter') . "</a>")
            ),
            $sentToTab = new Tab(_t('Newsletter.SENTREPORT', 'Sent Status Report'),
               new LiteralField("Sent Status Report", $sent_status_report)
            )
         )
      );

===============

Avatar
stevanovich

Community Member, 60 Posts

19 November 2010 at 11:28pm

anyone??? :o)

Avatar
zri

Community Member, 3 Posts

3 February 2011 at 9:40am

Edited: 03/02/2011 9:40am

I would really like to know about this too, cause I am having the same problem.

Avatar
Comonox

Community Member, 2 Posts

9 August 2011 at 12:45am

Hello and Welcome to my first post on silverstripe.org :)

IMHO this problem is caused because an image is uploaded by using an URL like "/admin/newsletter/NewsletterEditForm/field/ArticleImage/upload". Unfortunately /admin/newsletter is an action in NewsletterAdmin, so that NewsletterEditForm is always called and NewsletterAdmin requires an EmailId.
If you use Uplodify you can do the following to solve this problem:

1. Create File NewsletterDecorator.php
NewsletterDecorator:

class NewsletterDecorator extends DataObjectDecorator{

   public function NewsletterID(){
      $params = Director::urlParams();
      $ID = $params['ID'];
      return $ID;
   }

   public function extraStatics(){
       return array(
'has_one' => array(
'ArticleImage'      => 'ImageFile'
)
);
   }

   public function updateCMSFields(FieldSet &$fields) {
      $uploadify = new NewsletterImageUploadField ("ArticleImage", "Artikelbild");
      $uploadify->addParam('ID',$this->NewsletterID());
      $uploadify->setVar('refreshlink','/admin/newsletter/NewsletterEditForm/field/ArticleImage/refresh?ID='.$this->NewsletterID() );

      $fields->addFieldToTab("Root.Newsletter",$uploadify);

   }
}

2. Create File NewsletterImageUploadField
NewsletterImageUploadField:

class NewsletterImageUploadField extends ImageUploadField{

   public function NewsletterID(){
      return NewsletterDecorator::NewsletterID();
   }
}

3. Copy AttachedFields.ss from include-directory of the module to your theme-include-directory and change $Link(removefile) to $Link(removefile)?ID=$NewsletterID. Do the same with other not working links

Maybe this way might be a little complicated and since i am only starting at Silverstripe i am allways happy to get to know better solutions!

Avatar
MarcusDalgren

Community Member, 288 Posts

9 August 2011 at 1:20am

Unfortunately the newsletter module is kind of broken and has been broken for a very long time. There are other ways of fixing this but all of them are pretty messy so this fix is as good as any of the others. Nice work figuring it out!