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