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

Extending newsletter with image etc...


Reply

804 Views

Avatar
Thomashv

9 February 2011 at 9:23pm (Last edited: 9 February 2011 9:24pm), Community Member, 33 Posts

I really have problems with extending the newsletter module with some pictures and a newsbox. When making sites for people that are not very concius about how they place and scale elements in wysiwig editors I need adapt the newsletter module some more. The goal is that the template could be more spesific so that elements are displaying at same places and having the same shapes and sizes for every newsletter. There is a some posts on this in the forum, but they are pretty old and don't seem to be solved. So I hope this can be a complete post that will be solved soon with a little help from you.

I have started to extend the newsletter with the object decorator like this:

in mysite/code/MyNewsletter.php

class MyNewsletter extends DataObjectDecorator {
public function extraStatics() {
return array(
'has_one' => array(
'NewsletterImage' => 'Image'
)
);
}

public function updateCMSFields(FieldSet $fields) {
$fields->addFieldsToTab(
'Root.'._t('Newsletter.NEWSLETTER').'',
array(
new ImageField('NewsletterImage', 'Bilde') // doesn't work
)
);
}
}

in mysite/config.php:

Object::add_extension('Newsletter', 'MyNewsletter');

I have also tried DataObject::add_extension('Newsletter', 'MyNewsletter');
Not quite sure what the differents would be.

In the newsletter/code/NewsletterEmailProcess.php in the function called next i have added folowing to line 88 (marked in red):

$e->populateTemplate(array(
                  'Member' => $member,
                  'FirstName' => $member->FirstName,
                  'NameForEmail'=> $nameForEmail,
                  'NewsletterImage' => $this->newsletter->NewsletterImage
               ));

The ImageField is called, but I get this error inside the feild iframe:

Unknown Email ID: 0
Line 548 in /home/ua00002/subdomains/demo/newsletter/code/NewsletterAdmin.php

Source

539          if($email->Status != 'Draft') {
540             $readonlyFields = $form->Fields()->makeReadonly();
541             $form->setFields($readonlyFields);
542          }
543
544          // user_error( $form->FormAction(), E_USER_ERROR );
545
546          return $form;
547       } else {
548          user_error( 'Unknown Email ID: ' . $myId, E_USER_ERROR );
549       }
550    }
551
552    public function SendProgressBar() {
553       $progressBar = new ProgressBar( 'SendProgressBar', _t('NewsletterAdmin.SENDING','Sending emails...') );
554       return $progressBar->FieldHolder();

Some how the image upload field needs to get the Email ID. Is there anybody who knows how i may parser that ID to the ImageField?