Add Chatbox Block to Private Message Module

Created on 7 January 2025, 3 months ago

This feature introduces a Chatbox Block to the Private Message module, enabling chatbox functionality on sites. The block includes a configuration option to define the user context, providing flexibility for creating private message threads between users.

How to Use the Feature
Place the Block:
Navigate to the Block Layout page and place the Chatbox block in a desired region.

Block Configuration Options:

User Context:
The block configuration includes a select field named User Context with two options:
User Route Context (default):
The block uses the user route context to determine the target user. The target user is retrieved from the URL (e.g., user profile URL) using Drupal's RouteMatch::getParameter service.
A private message thread is created between the currently logged-in user and the target user specified in the URL, displaying a chatbox for these two users.
Select User:
Allows the admin to manually select a default user in the block configuration.
Case 1: User Route Context
If the User Route Context option is selected, the block retrieves the target user from the URL (e.g., user profile page) through the route context using RouteMatch::getParameter.
A private message thread is automatically created between the current user (the logged-in user) and the target user (the user from the URL).
The chatbox displays a private message form for these two users.
Case 2: Select User
If the Select User option is selected, a user reference field dynamically appears via AJAX in the block configuration form.
The admin selects a default user in this field and saves the configuration.
On pages where the block is placed, the private message form displays with a thread created between the current user and the default user specified in the configuration.

This feature enhances the Private Message module by providing an intuitive and flexible chatbox feature, making it easier for users to initiate private conversations directly from the site interface.

Note:
I am also raising a Merge Request (MR) for this feature.

Feature request
Status

Active

Version

3.0

Component

Code

Created by

🇮🇳India dev.drupal.ln

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024