Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function getIterator()
 {
     foreach (parent::getIterator() as $key => $message) {
         if ($message instanceof MessageInterface) {
             $message = $this->service->getNotification($message);
         }
         (yield $key => $message);
     }
 }
 protected function setUp()
 {
     parent::setUp();
     $this->service = new NotificationService($this->backend, false);
     // Register some notification types
     $formatterRegistry = $this->service->getFormatterRegistry();
     $formatterRegistry->registerType('friend:something', '\\MakinaCorpus\\APubSub\\Notification\\Formatter\\RawFormatter');
     $formatterRegistry->registerType('friend:friended', '\\MakinaCorpus\\APubSub\\Notification\\Formatter\\RawFormatter');
     $formatterRegistry->registerType('content');
     $formatterRegistry->registerType('disabled');
 }
 /**
  * {inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $registry = $this->service->getFormatterRegistry();
     $typeList = $registry->getTypeList();
     $label_disabled = $this->t("Disabled");
     $label_enabled = '<strong>' . $this->t("Enabled") . '</strong>';
     $options = [];
     foreach ($typeList as $type) {
         try {
             $options[$type]['type'] = $type;
             $options[$type]['status'] = $label_enabled;
             $options[$type]['status'] = true ? $label_enabled : $label_disabled;
             // FIXME
         } catch (Exception $e) {
             // @todo ?
         }
     }
     $form['types'] = ['#type' => 'tableselect', '#header' => ['type' => $this->t("Type"), 'status' => $this->t("Status")], '#options' => $options];
     $form['actions'] = ['#type' => 'actions'];
     $form['actions']['enable'] = ['#type' => 'submit', '#value' => $this->t("Enable"), '#submit' => ['::enableSubmit']];
     $form['actions']['disable'] = ['#type' => 'submit', '#value' => $this->t("Disable"), '#submit' => ['::disableSubmit']];
     return $form;
 }
Exemplo n.º 4
0
 /**
  * Handle any event
  *
  * If this method does not fit to your need, you are advised to extend this
  * class and modify this method to suit your own needs
  *
  * @param string $resourceType
  * @param string $action
  * @param Event $event
  */
 protected function onEvent($resourceType, $action, Event $event)
 {
     $idList = null;
     $data = null;
     $key = $resourceType . ':' . $action;
     $sendOnDefaultChan = true;
     $additionalChanId = [];
     if ($event instanceof ResourceEvent) {
         $data = $event->getArguments();
         $idList = $event->getResourceIdList();
         $additionalChanId = $event->getChanIdList();
         $sendOnDefaultChan = $event->shouldKeepDefaultChan();
     } else {
         if ($event instanceof GenericEvent) {
             $data = $event->getArguments();
             // Attempt to do a best guess at the resource identifier
             if (isset($event['id'])) {
                 $idList = [$event['id']];
             } else {
                 $subject = $event->getSubject();
                 if (is_scalar($subject)) {
                     $idList = [$subject];
                 } else {
                     if (method_exists($subject, 'getId')) {
                         $idList = [$subject->getId()];
                     } else {
                         if (property_exists($subject, 'id')) {
                             $idList = [$subject->id];
                         }
                     }
                 }
             }
         }
     }
     if (isset($idList)) {
         // Proceed with pre-configured overrides
         if ($sendOnDefaultChan && isset($this->chanBlockingOverrides[$key])) {
             $additionalChanId = array_merge($additionalChanId, $this->chanBlockingOverrides[$key]);
             // FIXME override should not be blocking default chans
             // @TODO add a blocking boolean tag attribute (false by default)
             // $sendOnDefaultChan = false;
         }
         if ($additionalChanId) {
             foreach ($idList as $id) {
                 if ($sendOnDefaultChan) {
                     $additionalChanId[] = $this->service->getChanId($resourceType, $id);
                 }
                 $this->service->notifyChannel($additionalChanId, $resourceType, $id, $action, $data);
             }
         } else {
             if ($sendOnDefaultChan) {
                 foreach ($idList as $id) {
                     $this->service->notify($resourceType, $id, $action, $data);
                 }
             }
         }
         // We might end up sending nothing, as soon as any of the listeners
         // explicitly forbid to send on the default chan, and we have no
         // additional chans.
     }
 }
Exemplo n.º 5
0
 /**
  * {inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $this->service->getSubscriber($this->currentUser()->id())->fetch()->update([Field::MSG_UNREAD => false]);
 }