-
Notifications
You must be signed in to change notification settings - Fork 0
/
liveblog_firebase.module
39 lines (33 loc) · 1.26 KB
/
liveblog_firebase.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
/**
* @file
* The module file.
*/
use \Drupal\liveblog_firebase\Plugin\LiveblogNotificationChannel\FirebaseNotificationChannel;
use \Drupal\node\Entity\Node;
use \Drupal\Core\Url;
use \Drupal\Core\Entity\Display\EntityViewDisplayInterface;
/**
* Implements hook_ENTITY_TYPE_view().
*/
function liveblog_firebase_node_view(array &$build, Node $node, EntityViewDisplayInterface $display, $view_mode) {
if ($display->getComponent('liveblog_posts')
&& Drupal::config('liveblog.settings')->get('notification_channel') == FirebaseNotificationChannel::PLUGIN_ID) {
$config = Drupal::config('liveblog.notification_channel.liveblog_firebase');
$build['liveblog_posts']['#attached']['library'][] = 'liveblog_firebase/firebase';
$build['liveblog_posts']['#attached']['drupalSettings']['liveblog_firebase'] = [
'sender_id' => $config->get('sender_id'),
'topic' => FirebaseNotificationChannel::createTopicId($node),
'sw_file' => '/liveblog_firebase/firebase-messaging-sw.js',
];
// Inject manifest.
$build['#attached']['html_head_link'][] = array(
array(
'rel' => 'manifest',
'href' => "/" . Url::fromRoute('liveblog_firebase.manifest')->getInternalPath(),
),
// Add header.
FALSE,
);
}
}