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.
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?
Hi thnx for help. I checked and tried singular/plural. No change. I can select the groups, but they don’t get saved. Do I need to set something else in the relation? Should I extend the Group object and define the relation from other side too? And perhaps the function that concats the selected groups for the summary view?
Thank you. It works nicely
There is only one small additional task. I need to hide the “Group” tab when editing the form.
Is there a simple explanation or a manual on how the “paths” to tabs and fields work?
Thank you. It removes the tab.
Is there something in the documentation where I could learn the “root.main…” ? What root means? What main means? And if there are any others?