public function onComponentCreated(ComponentEvent $event) { $actionsEnabled = array(); foreach ($this->actions as $name => $action) { $actionsEnabled[$name] = array_keys($action['transporters']); } $componentSetting = $this->componentSettingManager->findOrCreateComponentSetting($event->getComponent()); $componentSetting->setActionsEnabled($actionsEnabled); $this->componentSettingManager->save($componentSetting); }
/** * Call all transporter for the action of the NotificationInterface * * @param NotificationInterface $notification */ public function callTransporter(NotificationInterface $notification) { $configuration = $this->getConfiguration($notification->getAction()); if (null === $configuration) { return null; } if (isset($configuration['transporters'])) { $notificationComponents = $this->notificationManager->findAllNotificationComponent($notification); $notificationRecipients = $this->notificationManager->findAllRecipientsByNotification($notification); /** @var RecipientInterface $notificationRecipient */ foreach ($notificationRecipients as $notificationRecipient) { $recipientComponent = $notificationRecipient->getComponent(); $settings = $this->componentSettingManager->findOrCreateComponentSetting($recipientComponent); $actionsEnabled = $settings->getActionsEnabled(); if (array_key_exists($notification->getAction(), $actionsEnabled)) { foreach ($configuration['transporters'] as $name => $params) { if (in_array($name, $actionsEnabled[$notification->getAction()])) { $transporterId = $params['id']; if (null !== ($transporter = $this->transporter->getTransporter($transporterId))) { $transporter->setConfiguration(isset($params['config']) ? $params['config'] : array()); $transporter->send($notification, $notificationComponents, $notificationRecipient); } } } } } } }