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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

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

Extending newsletter with image etc...


Go to End


1223 Views

Avatar
Thomashv

Community Member, 35 Posts

9 February 2011 at 9:23pm

Edited: 09/02/2011 9:24pm

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?