Jump to:

10848 Posts in 2516 Topics by 1792 members

All other Modules

SilverStripe Forums » All other Modules » Newsletter Image Upload

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 959 Views
  • stevanovich
    Avatar
    Community Member
    59 Posts

    Newsletter Image Upload Link to this post

    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)
                )
             )
          );

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

  • stevanovich
    Avatar
    Community Member
    59 Posts

    Re: Newsletter Image Upload Link to this post

    anyone??? :o)

  • zri
    Avatar
    Community Member
    3 Posts

    Re: Newsletter Image Upload Link to this post

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

  • Comonox
    Avatar
    Community Member
    2 Posts

    Re: Newsletter Image Upload Link to this post

    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!

  • MarcusDalgren
    Avatar
    Community Member
    288 Posts

    Re: Newsletter Image Upload Link to this post

    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!

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