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.

Customising the CMS /

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

Adding methods to NewsletterAdmin via LeftAndMainDecorator


Go to End


2 Posts   1057 Views

Avatar
pbz

Community Member, 5 Posts

10 April 2012 at 2:10pm

Edited: 10/04/2012 2:11pm

I'm doing some work involving the Newsletter module. I basically am trying to create a newsletter template that will send the content of one of my pages, which has uses some custom methods, as part of the email. I have copied over most of the template for said page into the email template (with small modifications), but the custom methods do not work here since they are defined on a page controller (FanClubSubscriptionPage_Controller), whose methods are not available in NewsletterAdmin (where the function which sends the newsletter is located), which extends LeftAndMain. My solution is to create methods by these same names in NewsLetterAdmin by using LeftAndMainDecorator, this does not seem to work, ie the methods are not made available on NewsLetterAdmin.

Is there is a better place to put these custom methods so they are available in both FanClubSubscriptionPage_Controller & NewsletterAdmin? That seems like the ideal solution, but not sure it's possible.

I've experimented with extending NewsletterAdmin, but that seems impractical because a lot of the urls seem to be hard coded in, so an extension does not work properly. I've tried it.

So I am left with thinking using a decorator to add these methods to NewsletterAdmin is the best solution, but I can't get it to work.

MyNewsletterAdmin.php

<?php
class MyNewsletterAdmin extends LeftAndMainDecorator {
	public static function SpecialsAnnouncements() {
		return DataObject::get_one('FoodSpecialsPage')->FoodMenuItems('Announcement=1');
	}

	public static function SaleAnnouncements() {
		return DataObject::get('FoodMenu', 'Sale');
	}

}
?>

and the relevant line in _config.php

DataObject::add_extension('NewsletterAdmin', 'MyNewsletterAdmin');

Thanks for any suggestions.
Jason

Avatar
pbz

Community Member, 5 Posts

10 April 2012 at 3:03pm

So apparently the problem is not what I thought it was, or at least not only what I thought it was. Dug a bit more and found that since the newsletter module uses the built-in email functionality, the templates only have available to them whatever values are made so via populateTemplate, so currently I have hacked a couple lines into NewsletterEmail->_construct.

I can't see a better way to do this really, but if anyone has any suggestions I'd be happy to hear them.