There is following Notification DataObject
class Notification extends DataObject {
private static $db = array (
'Message' => 'Text',
//...
);
private static $has_one = array(
'Member' => 'Member', //the recipient
//...
);
//...
}
The important part is the has_one relationship with a member. This can't be changed to a many_many relationship.
But, for practical reasons, I want our customer to be able to send a notification to multiple customers at once. Therefore I added the following fields to the notification objects getCMSfields method:
HeaderField::create('SentToHeader', 'Notification senden an...'),
ListboxField::create('Member', '...folgende Mitglieder', $members)->setMultiple(true),
ListboxField::create('Membership', '...Mitglieder folgender Mitgliedschaften', $memberships)->setMultiple(true),
So far, everything is fine.
Now I need to somehow intercept the submit and instead of creating a single notification, create notifications foreach selected member (or for each member in each selected membership). I don't wan't to do this in the notifications onBeforeWrite because I feel like this is a very hacky solution.
Now to my question:
Can I somehow intercept the forms submit event in my model admin and prevent it's default behavior (creating a single new notification) and instead create as many new notification objects as needed?
Thanks in advance