Silverstripe Version: 4*
I’m trying to create a simple Newsletter in the Admin CMS area. Basically I need a simple form with the additional option to select the groups from group (DB). I added the Newsletter data object and added the relation. When adding a new newsletter I can select the groups, but they are not saved in the relational table. I have been reading the documentation but I can’t find the correct solution.
NewsLetterAdminUI.php
class NewsLetterAdminUI extends ModelAdmin {
private static $managed_models = [
NewsLetter::class
];
private static $url_segment = 'newsletter';
private static $menu_title = 'Newsletter';
private static $menu_icon_class = 'font-icon-news';
NewsLetter.php
class NewsLetter extends DataObject
{
private static $db = [
'Subject' => 'Varchar',
'Content' => 'Text',
'SentDate' => 'Datetime'
];
private static $many_many = [
'Group' => Group::class,
];
private static $summary_fields = [
'ID',
'Subject',
'Content',
'SentDate',
'Group.ID' // I want to list the groups that received the email
];
/* last non working attempt */
public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->insertAfter('Naslov', new TagField(
'Groups',
_t(__CLASS__ . '.Groups', 'Groups'),
Group::get()
));
$fields->removeByName('Root.Edit.Groups'); // trying to remove the Group tab in the edit form
return $fields;
}
Additionally: is there an option “on save”, “on before save”,… where I could add a simple send email function?