Skip to content
Snippets Groups Projects
Commit e9a1fab3 authored by Jay Friendly's avatar Jay Friendly
Browse files

Removing modules subfolder, as both sub-modules have been spun out into their own projects

parent c616db87
No related branches found
No related tags found
No related merge requests found
Showing
with 0 additions and 993 deletions
private_message_flood.role:
type: sequence
label: 'Private Message Flood role settings'
private_message_flood.role.*:
type: config_object
label: 'Private Message flood role setting'
mapping:
limit:
type: integer
label: 'Maximum number of messages'
duration:
type: duration
label: 'Duration'
weight:
type: integer
label: 'Role Weight'
name: 'Private Message Flood Protection'
description: 'Sets up flood protection for the Private Message module'
type: module
core: 8.x
package: Private Message
dependencies:
- drupal:private_message
- drupal:duration_field
<?php
/**
* @file
* Holds hooks for the Private Message Flood Protection module.
*/
use Drupal\Core\Form\FormStateInterface;
/**
* Implements hook_form_FORM_ID_alter().
*/
function private_message_flood_form_private_message_form_alter(array &$form, FormStateInterface $formState) {
// Adds a custom validation handler to the form.
array_unshift($form['#validate'], 'private_message_flood_form_private_message_form_validate');
}
/**
* Custom validation handler for private message form.
*
* Checks if a user has reached their flood limit.
*/
function private_message_flood_form_private_message_form_validate(array $form, FormStateInterface $formState) {
if (\Drupal::service('private_message_flood.service')->checkUserFlood()) {
$formState->setError($form['message'], t('Sorry, you have reached your limit for posting. Please try again later.'));
}
}
parameters:
private_message_flood.service.class: 'Drupal\private_message_flood\Service\PrivateMessageFloodService'
services:
private_message_flood.service:
class: '%private_message_flood.service.class%'
arguments:
- '@current_user'
- '@config.factory'
- '@datetime.time'
<?php
namespace Drupal\private_message_flood\Plugin\PrivateMessageConfigForm;
use Drupal\Core\Form\FormStateInterface;
use Drupal\private_message\Plugin\PrivateMessageConfigForm\PrivateMessageConfigFormBase;
use Drupal\private_message\Plugin\PrivateMessageConfigForm\PrivateMessageConfigFormPluginInterface;
/**
* Adds Private Message Flood settings to the Private Message config page.
*
* @PrivateMessageConfigForm(
* id = "private_message_flood_settings",
* name = @Translation("Private Message Flood Protection settings"),
* )
*/
class PrivateMessageFloodPrivateMessageConfigForm extends PrivateMessageConfigFormBase implements PrivateMessageConfigFormPluginInterface {
/**
* {@inheritdoc}
*/
public function buildForm(FormStateInterface $formState) {
$form['header'] = [
'#prefix' => '<p>',
'#suffix' => '</p>',
'#markup' => $this->t('Flood protection limits the number of post users can make in a given period of time. You can apply flood protection on a per-role basis below. Priority is given to roles from top to bottom. The highest priority role a user is found to have, will be checked against the flood protection settings for that role when determining if they have flooded the private message system.'),
];
$group_class = 'group-order-weight';
$roles = array_map(['\Drupal\Component\Utility\Html', 'escape'], user_role_names(TRUE));
$items = [];
foreach ($roles as $role_id => $role_name) {
$config = $this->configFactory->get('private_message_flood.role.' . $role_id);
$items[$role_id] = [
'label' => $role_name,
'weight' => $config->get('weight'),
'elements' => [
'limit' => [
'#type' => 'number',
'#title' => t('Maxium number of messages'),
'#description' => $this->t('Leave empty to disable flood protection for this role'),
'#default_value' => $config->get('limit'),
],
'duration' => [
'#type' => 'duration',
'#title' => t('Duration'),
'#granularity' => 'y:d:m:h:i:s',
'#default_value' => $config->get('duration'),
],
],
];
}
$form['roles'] = [
'#type' => 'table',
'#caption' => $this->t('Roles'),
'#header' => [
$this->t('Label'),
$this->t('Values'),
$this->t('Weight'),
],
'#tableselect' => FALSE,
'#tabledrag' => [
[
'action' => 'order',
'relationship' => 'sibling',
'group' => $group_class,
],
],
];
// Build rows.
foreach ($items as $key => $value) {
$form['roles'][$key]['#attributes']['class'][] = 'draggable';
$form['roles'][$key]['#weight'] = $value['weight'];
// Label col.
$form['roles'][$key]['label'] = [
'#plain_text' => $value['label'],
];
// Values col.
$form['roles'][$key]['values'] = [
'details' => [
'#type' => 'details',
'#title' => $this->t('Click to expand'),
'#open' => FALSE,
'elements' => $value['elements'],
],
];
// Weight col.
$form['roles'][$key]['weight'] = [
'#type' => 'weight',
'#title' => $this->t('Weight for @title', ['@title' => $value['label']]),
'#title_display' => 'invisible',
'#default_value' => $value['weight'],
'#attributes' => ['class' => [$group_class]],
];
}
uasort($form['roles'], ['Drupal\Component\Utility\SortArray', 'sortByWeightProperty']);
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array $values) {
foreach ($values['roles'] as $rid => $data) {
$this->configFactory->getEditable('private_message_flood.role.' . $rid)
->set('limit', $data['values']['details']['elements']['limit'])
->set('duration', $data['values']['details']['elements']['duration'])
->set('weight', $data['weight'])
->save();
}
}
}
<?php
namespace Drupal\private_message_flood\Service;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
/**
* Provides services for the Private Message Flood Protection module.
*/
class PrivateMessageFloodService implements PrivateMessageFloodServiceInterface {
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected $currentUser;
/**
* The configuration factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The time service.
*
* @var \Drupal\Component\Datetime\TimeInterface
*/
protected $time;
/**
* Constructs a PrivateMessageFloodService object.
*
* @param \Drupal\Core\Session\AccountProxyInterface $currentUser
* The current user.
* @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
* The configuration factory.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time service.
*/
public function __construct(
AccountProxyInterface $currentUser,
ConfigFactoryInterface $configFactory,
TimeInterface $time
) {
$this->currentUser = $currentUser;
$this->configFactory = $configFactory;
$this->time = $time;
}
/**
* {@inheritdoc}
*/
public function checkUserFlood() {
$flood_info = $this->getFloodProtectionInfo();
// Check if we even need to check anything.
if ($limit = $flood_info['limit']) {
// Get the amount of time in which they are limited to make said number of
// posts.
$duration = new \DateInterval($flood_info['duration']);
// Get the current time.
$now = new \DateTime();
$now->setTimestamp($this->time->getRequestTime());
// Get the UNIX timestamp for time that is $duration ago from now. For
// example, if $duration is one year, then $since will be the exact date
// and time one year ago from now.
$since = $now->sub($duration)->format('U');
// Query the number of posts that the user has made since the given
// timestamp.
$post_count = db_select('private_messages', 'pm')
->fields('pm', ['id'])
->condition('owner', $this->currentUser->id())
->condition('created', $since, '>=')
->countQuery()
->execute()
->fetchField();
// Return TRUE if they've posted their limit already, FALSE if they have
// not.
return $post_count >= $limit;
}
// If there is no limit for the user, then they have no flood protection
// applied to them, and therefore are unable to flood.
return FALSE;
}
/**
* Gets flood protection info for the current user, based on their roles.
*
* Each role in the system can be assigned flood protection settings. Roles
* are also assigned a priority. This function fetches the flood protection
* data for the highest prioirty role that the current user has.
*
* @return array
* An array of flood protection data for the current user based on their
* roles.
*/
private function getFloodProtectionInfo() {
$user_roles = $this->currentUser->getRoles();
$role = array_intersect_key($this->getRoleInfo(), array_flip($user_roles));
$role_id = key($role);
$config = $this->configFactory->get('private_message_flood.role.' . $role_id);
if ($config) {
return $config->get();
}
return [
'limit' => 0,
];
}
/**
* Fetches an array of roles, ordered by priority.
*
* Each role in the system may have flood protection settings that determine
* how many posts a user can make in a given duration. Roles have priority,
* and the highest priority role is the one that a user is checked against
* when determining whether or not they have crossed the threshold for their
* flood settings.
*
* @return array
* An array of roles that have flood protection assigned to them, keyed by
* the role ID, with the value being the weight. Roles in the array are
* ordered highest to lowest priority.
*/
private function getRoleInfo() {
$roles = array_map(['\Drupal\Component\Utility\Html', 'escape'], user_role_names(TRUE));
$items = [];
foreach (array_keys($roles) as $role_id) {
$role_info = $this->configFactory->get('private_message_flood.role.' . $role_id)->get();
$items[$role_id] = $role_info['weight'];
}
uasort($items, [$this, 'sortByWeight']);
return $items;
}
/**
* Sorting callback to sort arrays by their 'weight' attribute.
*/
private function sortByWeight($a, $b) {
if ($a === $b) {
return 0;
}
return $a > $b ? 1 : -1;
}
}
<?php
namespace Drupal\private_message_flood\Service;
/**
* Provides services for the Private Message Flood Protection module.
*/
interface PrivateMessageFloodServiceInterface {
/**
* Determines whether a user has reached their post limit for messages.
*
* @return bool
* A boolean indicating whether or not they have reached their flood limit.
* TRUE means they have reached the limit, and should be stopped from
* posting. FALSE means they can post as normal.
*/
public function checkUserFlood();
}
# Private Message NodeJS
Instant updates and notifications for the [Private Message module](https://www.drupal.org/project/private_message)
module without the need for polling.
This listens for private message thread updates and uses the [drupal nodejs module](https://www.drupal.org/project/nodejs)
to trigger updates to the UI and provide notifications for members of the changed thread.
## How it works
By default, the private message module uses 'polling' to check for updates. This
means it sends a request to the server every X seconds to check if there are any
new messages. This can add a lot of additional overhead to the server,
particularly when the user leaves the private message page open and isn't even
looking at it. The alternative is to set the ajax refresh time to zero, which
disables updates altogether, requiring a page refresh to see if there are any
updates.
This module provides a solution that updates private message threads without the
use of polling,by integration with Nodejs, which handles updates in realtime.
## Benefits of this module
* No ajax polling means less work for the browser.
* No ajax polling means less work for the server.
* Message threads immediately show new messages
## Requirements
* [Private Message module](https://www.drupal.org/project/private_message)
* [Node.js](https://nodejs.org/)
## Installation
### 1. Install Node.js
Instructions on Node.js installation are not provided here, as they differ per
system, and instructions are outside the scope of this document. Please see
the [Node.js homepage](https://nodejs.org/en/) for more information.
### 2. Install the module
Install the private_message_nodejs module as you would any Drupal module.
### 3. Install the nodeJS dependendencies
On the command line, navigate to [PRIVATE_MESSAGE_MODULE_ROOT]/modules/private_message_nodejs/nodejs and run the
following command:
`npm install`
### 4. Confirm the Nodejs server is working
On the command line, navigate to [PRIVATE_MESSAGE_MODULE_ROOT]/modules/private_message_nodejs/nodejs and run the
following command:
`node app.js`
Note: Leave this open and running, as closing the server will stop it from
working.
### 5. Enter the URL to the node.js server in the private message configuration
In the web browser, navigate to /admin/config/private_message/config. Expand the
Private Message Nodejs settings section, and enter the URL to the node JS app.
It should be found at [your domain]:8080. Save.
### 6. Test
Open up the private message page and check that there has been some output in
the command line, indicating that connections have been made to the Nodejs
server.
## Authors
The Private Message Nodejs module was first written by
[Jeremy Graham](http://jez.me), integrating with the Drupal Node.js module.
A custom implementation that does not depend on that module was then written
by [Jay Friendly](https://www.jaypan.com).
{
"name": "drupal/private_message_nodejs",
"description": "Creates an integration between the Private Message module and a Node.js back end.",
"type": "drupal-module",
"homepage": "https://drupal.org/project/private_message",
"authors": [
{
"name": "Jay Friendly (Jaypan)",
"homepage": "https://www.jaypan.com",
"role": "Maintainer"
}
],
"support": {
"issues": "https://drupal.org/project/issues/private_message",
"source": "https://cgit.drupalcode.org/private_message"
},
"license": "GPL-2.0-or-later",
"minimum-stability": "dev",
"require": {
"jaypan/private-message-nodejs": "~2.8"
}
}
browser_notification_enable: false
browser_notification_title: 'Private Message'
browser_notification_body: 'New private message from [private_message:author-name]'
browser_notification_icon: '/core/themes/bartik/logo.svg'
browser_notification_link: '[private_message_thread:url]'
private_message_nodejs.settings:
type: config_object
label: 'Settings for the Private Message Nodejs module'
mapping:
nodejs_url:
type: string
label: 'The URL at which the Nodejs server can be reached'
browser_notification_enable:
type: boolean
label: 'Whether or not to enable browser notifications'
browser_notification_title:
type: string
label: 'The title to be shown in the browser notification'
browser_notification_body:
type: string
label: 'The body of the browser notification'
browser_notification_icon:
type: string
label: 'The path to the icon to be used in browser notifictions'
browser_notification_link:
type: string
label: 'The URL users will be directed to when clicking a browser notification'
/**
* @file
* Client-side script to integrate private message with browser notifications.
*/
/*global Drupal, drupalSettings, io, Notification, window*/
/*jslint white:true, this, browser:true*/
(function (Drupal, drupalSettings, io, Notification, window) {
"use strict";
var initialized, browserNotificationSocket;
function checkPermission() {
if (window.hasOwnProperty("Notification")) {
var permission = Notification.permission;
if (permission === "granted") {
return true;
}
if (permission !== "denied") {
Notification.requestPermission().then(function () {
return true;
});
}
}
}
function showBrowserNotification(body, icon, title, link, duration) {
if (checkPermission()) {
// Default duration is 5 seconds.
duration = duration || 5000;
var options = {
body: body,
icon: icon
};
// Create the notification.
var n = new Notification(title, options);
// Set a click listener if a link was passed.
if (link) {
n.onclick = function () {
window.open(link);
};
}
// Set the notification to close after the duration.
setTimeout(n.close.bind(n), duration);
}
}
function notifyBrowserOfNewMessage(message) {
showBrowserNotification(message.body, message.icon, message.title, message.link);
}
function init() {
// Only initialize once.
if (!initialized) {
initialized = true;
browserNotificationSocket = io(drupalSettings.privateMessageNodejs.nodejsUrl + "/pm_browser_notification");
// Listen for a connection to the remote server.
browserNotificationSocket.on("connect", function () {
// Enter the room for this user.
browserNotificationSocket.emit("user", drupalSettings.user.uid);
});
// Listen for an emission informing of a notification of a new message for
// the current user.
browserNotificationSocket.on("notify browser new message", function (message) {
// Send a browser notification of the new message.
notifyBrowserOfNewMessage(message);
});
}
}
Drupal.behaviors.privateMessageNodejsBrowserNotify = {
attach: function () {
init();
}
};
}(Drupal, drupalSettings, io, Notification, window));
/**
* @file
* Client-side script to integrate private message with browser notifications.
*/
/*global jQuery, Drupal, drupalSettings, io*/
/*jslint white:true, this, browser:true*/
(function ($, Drupal, drupalSettings, io) {
"use strict";
var initialized, browserNotificationSocket;
function init() {
// Only initialize once.
if (!initialized) {
initialized = true;
browserNotificationSocket = io(drupalSettings.privateMessageNodejs.nodejsUrl + "/pm_browser_notification");
Drupal.AjaxCommands.prototype.privateMessageNodejsNotifyBrowserOfNewMessage = function (ajax, response) {
// For jSlint compatibility.
ajax = ajax;
$.each(response.uids, function (index) {
browserNotificationSocket.emit("notify browser new message", response.uids[index], response.message);
});
};
}
}
Drupal.behaviors.privateMessageNodejsForm = {
attach: function () {
init();
}
};
}(jQuery, Drupal, drupalSettings, io));
/**
* @file
* Client-side script to integrate the private message inbox block with Node.js.
*/
/*global jQuery, Drupal, drupalSettings, io*/
/*jslint white:true, this, browser:true*/
(function ($, Drupal, drupalSettings, io) {
"use strict";
var initialized, inboxSocket;
function init() {
// Only initialize once.
if (!initialized) {
initialized = true;
inboxSocket = io(drupalSettings.privateMessageNodejs.nodejsUrl + "/pm_inbox");
// Listen for a connection to the remote server.
inboxSocket.on('connect', function () {
// Enter the room for this user.
inboxSocket.emit('user', drupalSettings.user.uid);
});
// Listen for an emission informing of thread update for a thread the user
// belongs to.
inboxSocket.on("update pm inbox", function () {
// Fetch new messages from the server.
Drupal.PrivateMessageInbox.updateInbox();
});
Drupal.AjaxCommands.prototype.privateMessageNodejsTriggerInboxUpdateCommand = function (ajax, response) {
// For jSlint compatibility.
ajax = ajax;
if (Drupal.PrivateMessageInbox) {
$.each(response.uids, function (index) {
inboxSocket.emit("update pm inbox", response.uids[index]);
});
}
};
}
}
Drupal.behaviors.privateMessageNodejsInbox = {
attach: function () {
init();
}
};
}(jQuery, Drupal, drupalSettings, io));
/**
* @file
* Client-side script integrating private message notification block and Nodejs.
*/
/*global jQuery, Drupal, drupalSettings, io*/
/*jslint white:true, this, browser:true*/
(function ($, Drupal, drupalSettings, io) {
"use strict";
var initialized, notificationSocket;
function init() {
// Only initialize once.
if (!initialized) {
initialized = true;
notificationSocket = io(drupalSettings.privateMessageNodejs.nodejsUrl + "/pm_notifications");
// Listen for a connection to the remote server.
notificationSocket.on('connect', function () {
// Enter the room for this user.
notificationSocket.emit('user', drupalSettings.user.uid);
});
// Listen for an emission informing of thread update for a thread the user
// belongs to.
notificationSocket.on("update pm unread thread count", function () {
// Fetch unread thread count from the server.
Drupal.PrivateMessageNotificationBlock.getUnreadThreadCount();
});
Drupal.AjaxCommands.prototype.privateMessageNodejsTriggerUnreadThreadCountUpdateCommand = function (ajax, response) {
// For jSlint compatibility.
ajax = ajax;
if (Drupal.PrivateMessageNotificationBlock) {
$.each(response.uids, function (index) {
notificationSocket.emit("update pm unread thread count", response.uids[index]);
});
}
};
}
}
Drupal.behaviors.privateMessageNodejsNotificationBlock = {
attach: function () {
init();
}
};
}(jQuery, Drupal, drupalSettings, io));
/**
* @file
* Client-side script to integrate private message threads with Nodejs.
*/
/*global Drupal, drupalSettings, io*/
/*jslint white:true, this, browser:true*/
(function (Drupal, drupalSettings, io) {
"use strict";
var initialized, threadSocket;
function init() {
// Only initialize once.
if (!initialized) {
initialized = true;
threadSocket = io(drupalSettings.privateMessageNodejs.nodejsUrl + "/pm_thread");
threadSocket.on('connect', function () {
// Enter for the room for this thread.
threadSocket.emit('thread', drupalSettings.privateMessageThread.threadId);
});
// Listen for an emission informing of a new private message in the
// thread.
threadSocket.on("new private message", function () {
// Fetch new messages from the server.
Drupal.PrivateMessages.getNewMessages();
});
// Set up a callback for when the user has changed threads.
Drupal.PrivateMessages.threadChange.privateMessageNodejs = {
threadLoaded: function (threadId) {
// Join the room for the new thread.
threadSocket.emit('thread', threadId);
}
};
Drupal.AjaxCommands.prototype.privateMessageNodejsTriggerNewMessages = function () {
threadSocket.emit("new private message", drupalSettings.privateMessageThread.threadId);
};
}
}
Drupal.behaviors.privateMessageNodejsThread = {
attach: function () {
init();
}
};
}(Drupal, drupalSettings, io));
name: 'Private Message Node.js'
description: 'Creates an integration between the Private Message module and a Node.js back end'
type: module
core: '8.x'
package: 'Private Message'
dependencies:
- drupal:private_message
io:
version: VERSION
js:
nodejs/node_modules/socket.io-client/dist/socket.io.js: {}
browser_notification:
version: VERSION
js:
js/private_message_nodejs.browser_notification.js: {}
dependencies:
- core/drupalSettings
- private_message_nodejs/io
form:
version: VERSION
js:
js/private_message_nodejs.form.js: {}
dependencies:
- core/drupalSettings
- core/jquery
- private_message_nodejs/io
thread:
version: VERSION
js:
js/private_message_nodejs.thread.js: { }
dependencies:
- core/drupalSettings
- private_message/private_message_thread_script
- private_message_nodejs/io
inbox:
version: VERSION
js:
js/private_message_nodejs.inbox.js: { }
dependencies:
- core/jquery
- core/drupalSettings
- private_message/inbox_block_script
- private_message_nodejs/io
notification_block:
version: VERSION
js:
js/private_message_nodejs.notification_block.js: { }
dependencies:
- core/drupalSettings
- private_message/notification_block_script
- private_message_nodejs/io
<?php
/**
* @file
* Holds hooks for the Private message Nodejs module.
*
* Integrates Nodejs with the Private Message module.
*/
use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\private_message\Entity\PrivateMessageThreadInterface;
/**
* Implements hook_entity_type_alter().
*/
function private_message_nodejs_entity_type_alter(array &$entity_types) {
$entity_types['private_message']->setFormClass('add', 'Drupal\private_message_nodejs\Form\PrivateMessageNodejsForm');
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function private_message_nodejs_form_entity_view_display_edit_form_alter(array &$form, FormStateInterface $formState) {
if ($form['#entity_type'] == 'private_message_thread' && isset($form['fields']['private_messages'], $form['fields']['private_messages']['plugin']['settings_edit_form']['settings']['ajax_refresh_rate'])) {
// Remove access to the the ajax refresh rate, as it is not applicable when
// this module is enabled.
$form['fields']['private_messages']['plugin']['settings_edit_form']['settings']['ajax_refresh_rate']['#access'] = FALSE;
}
}
/**
* Implements hook_form_FORM_ID_alter().
*
* Alter block settings forms.
*/
function private_message_nodejs_form_block_form_alter(array &$form, FormStateInterface $formState) {
// Act on the private message inbox block settings.
if ($formState->getFormObject()->getEntity()->getPluginId() == 'private_message_inbox_block') {
// Set the ajax refresh rate to be hidden, as refreshing of the inbox will
// happen using nodejs.
$form['settings']['ajax_refresh_rate']['#access'] = FALSE;
}
// Act on the private message notification block settings.
elseif ($formState->getFormObject()->getEntity()->getPluginId() == 'private_message_notification_block') {
// Set the ajax refresh rate to be hidden, as refreshing of the inbox will
// happen using nodejs.
$form['settings']['ajax_refresh_rate']['#access'] = FALSE;
}
}
/**
* Implements hook_field_formatter_settings_summary_alter().
*/
function private_message_field_formatter_settings_summary_alter(array &$summary, $context) {
if ($context['formatter']->getPluginId() == 'private_message_thread_message_formatter') {
// Remove the summary of the the ajax refresh rate, as it is not applicable
// when this module is enabled.
unset($summary['ajax_refresh_rate']);
}
}
/**
* Implements hook_ENTITY_TYPE_view_alter().
*/
function private_message_nodejs_private_message_thread_view_alter(array &$build, PrivateMessageThreadInterface $thread, EntityViewDisplayInterface $display) {
// Attach the library to handle Node.js integration.
$build['private_messages']['#attached']['library'][] = 'private_message_nodejs/thread';
// Disable AJAX refresh.
$build['private_messages']['#attached']['drupalSettings']['privateMessageThread']['refreshRate'] = 0;
// Set the URL to the backend Node.js app.
$build['private_messages']['#attached']['drupalSettings']['privateMessageNodejs']['nodejsUrl'] = \Drupal::config('private_message_nodejs.settings')->get('nodejs_url');
}
/**
* Implements hook_block_view_BASE_BLOCK_ID_alter().
*/
function private_message_nodejs_block_view_private_message_inbox_block_alter(array &$build, BlockPluginInterface $block) {
$build['#pre_render'][] = 'private_message_nodejs_block_view_private_message_inbox_block_pre_render';
}
/**
* Custom prerender callback for the private message inbox block.
*
* Disables polling in the private message inbox, as it is handled instead by
* nodejs.
*/
function private_message_nodejs_block_view_private_message_inbox_block_pre_render($build) {
// Attach the library to handle Node.js integration.
$build['content']['#attached']['library'][] = 'private_message_nodejs/inbox';
// Disable AJAX refresh.
$build['content']['#attached']['drupalSettings']['privateMessageInboxBlock']['ajaxRefreshRate'] = 0;
// Set the URL to the backend Node.js app.
$build['content']['#attached']['drupalSettings']['privateMessageNodejs']['nodejsUrl'] = \Drupal::config('private_message_nodejs.settings')->get('nodejs_url');
return $build;
}
/**
* Implements hook_block_view_BASE_BLOCK_ID_alter().
*/
function private_message_nodejs_block_view_private_message_notification_block_alter(array &$build, BlockPluginInterface $block) {
$build['#pre_render'][] = 'private_message_nodejs_block_view_private_message_notification_block_pre_render';
}
/**
* Custom prerender callback for the private message notification block.
*
* Disables polling in the private notification block, as it is handled instead
* by nodejs.
*/
function private_message_nodejs_block_view_private_message_notification_block_pre_render($build) {
// Attach the library to handle Node.js integration.
$build['content']['#attached']['library'][] = 'private_message_nodejs/notification_block';
// Disable AJAX refresh.
$build['content']['#attached']['drupalSettings']['privateMessageNotificationBlock']['ajaxRefreshRate'] = 0;
// Set the URL to the backend Node.js app.
$build['content']['#attached']['drupalSettings']['privateMessageNodejs']['nodejsUrl'] = \Drupal::config('private_message_nodejs.settings')->get('nodejs_url');
return $build;
}
/**
* Implements hook_page_attachments().
*/
function private_message_nodejs_page_attachments(array &$attachments) {
if (\Drupal::config('private_message_nodejs.settings')->get('browser_notification_enable')) {
$attachments['#attached']['library'][] = 'private_message_nodejs/browser_notification';
$attachments['#attached']['drupalSettings']['privateMessageNodejs']['nodejsUrl'] = \Drupal::config('private_message_nodejs.settings')->get('nodejs_url');
}
}
parameters:
private_message_nodejs.service.class: 'Drupal\private_message_nodejs\Service\PrivateMessageNodejsService'
services:
private_message_nodejs.service:
class: '%private_message_nodejs.service.class%'
arguments:
- '@config.factory'
- '@token'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment