ソースを参照

Flag branch
Purpose is to make use of Event Subscribers to track friendship heartbeats

logicp 7 年 前
コミット
5b0a174e77
2 ファイル変更91 行追加0 行削除
  1. 6 0
      heartbeat.services.yml
  2. 85 0
      src/EventSubscriber/HeartbeatEventSubscriber.php

+ 6 - 0
heartbeat.services.yml

@@ -14,3 +14,9 @@ services:
   heartbeat:
     class: Drupal\heartbeat\HeartbeatService
     arguments: ['@entity_type.manager', '@entity.query', '@heartbeatstream']
+  heartbeat.event:
+    class: Drupal\heartbeat\EventSubscriber\HeartbeatEventSubscriber
+    arguments: ['@flag', '@heartbeat.heartbeattype', '@heartbeatstream', '@heartbeat']
+    tags:
+      - { name: event_subscriber }
+

+ 85 - 0
src/EventSubscriber/HeartbeatEventSubscriber.php

@@ -0,0 +1,85 @@
+<?php
+
+namespace Drupal\heartbeat\EventSubscriber;
+
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+use Symfony\Component\EventDispatcher\Event;
+use Drupal\flag\FlagService;
+use Drupal\heartbeat\HeartbeatTypeServices;
+use Drupal\heartbeat\HeartbeatStreamServices;
+use Drupal\heartbeat\HeartbeatService;
+
+/**
+ * Class HeartbeatEventSubscriber.
+ *
+ * @package Drupal\heartbeat
+ */
+class HeartbeatEventSubscriber implements EventSubscriberInterface {
+
+  /**
+   * Drupal\flag\FlagService definition.
+   *
+   * @var \Drupal\flag\FlagService
+   */
+  protected $flagService;
+  /**
+   * Drupal\heartbeat\HeartbeatTypeServices definition.
+   *
+   * @var \Drupal\heartbeat\HeartbeatTypeServices
+   */
+  protected $heartbeatTypeService;
+  /**
+   * Drupal\heartbeat\HeartbeatStreamServices definition.
+   *
+   * @var \Drupal\heartbeat\HeartbeatStreamServices
+   */
+  protected $heartbeatStreamService;
+  /**
+   * Drupal\heartbeat\HeartbeatService definition.
+   *
+   * @var \Drupal\heartbeat\HeartbeatService
+   */
+  protected $heartbeatService;
+
+  /**
+   * Constructor.
+   */
+  public function __construct(FlagService $flag, HeartbeatTypeServices $heartbeat_heartbeattype, HeartbeatStreamServices $heartbeatstream, HeartbeatService $heartbeat) {
+    $this->flagService = $flag;
+    $this->heartbeatTypeService = $heartbeat_heartbeattype;
+    $this->heartbeatStreamService = $heartbeatstream;
+    $this->heartbeatService = $heartbeat;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function getSubscribedEvents() {
+    $events['flag.entity_flagged'] = ['flag_entity_flagged'];
+    $events['flag.entity_unflagged'] = ['flag_entity_unflagged'];
+
+    return $events;
+  }
+
+  /**
+   * This method is called whenever the flag.entity_flagged event is
+   * dispatched.
+   *
+   * @param GetResponseEvent $event
+   */
+  public function flag_entity_flagged(Event $event) {
+    $stophere = null;
+    $flagging = $event->getFlagging();
+    drupal_set_message('Event flag.entity_flagged thrown by Subscriber in module heartbeat.', 'status', TRUE);
+  }
+  /**
+   * This method is called whenever the flag.entity_unflagged event is
+   * dispatched.
+   *
+   * @param GetResponseEvent $event
+   */
+  public function flag_entity_unflagged(Event $event) {
+    drupal_set_message('Event flag.entity_unflagged thrown by Subscriber in module heartbeat.', 'status', TRUE);
+  }
+
+}