Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • project/private_message
  • issue/private_message-3102091
  • issue/private_message-3184577
  • issue/private_message-3186067
  • issue/private_message-3095101
  • issue/private_message-3164669
  • issue/private_message-3203419
  • issue/private_message-2942602
  • issue/private_message-3095232
  • issue/private_message-3216927
  • issue/private_message-3217509
  • issue/private_message-3232483
  • issue/private_message-3226703
  • issue/private_message-3231433
  • issue/private_message-3137648
  • issue/private_message-3094213
  • issue/private_message-3156194
  • issue/private_message-3183628
  • issue/private_message-3231711
  • issue/private_message-3142633
  • issue/private_message-3042276
  • issue/private_message-3236702
  • issue/private_message-3239279
  • issue/private_message-3239575
  • issue/private_message-3281258
  • issue/private_message-3243139
  • issue/private_message-3195730
  • issue/private_message-3184550
  • issue/private_message-3041599
  • issue/private_message-3179135
  • issue/private_message-3029461
  • issue/private_message-3245298
  • issue/private_message-3250059
  • issue/private_message-3261287
  • issue/private_message-3221475
  • issue/private_message-3261292
  • issue/private_message-3050359
  • issue/private_message-3249348
  • issue/private_message-3248258
  • issue/private_message-3082478
  • issue/private_message-3265901
  • issue/private_message-3300046
  • issue/private_message-2947762
  • issue/private_message-3321802
  • issue/private_message-3051300
  • issue/private_message-3207855
  • issue/private_message-3099166
  • issue/private_message-3344346
  • issue/private_message-3297889
  • issue/private_message-3261083
  • issue/private_message-3151941
  • issue/private_message-3317985
  • issue/private_message-3285143
  • issue/private_message-3337185
  • issue/private_message-3337186
  • issue/private_message-3337189
  • issue/private_message-3322900
  • issue/private_message-2977313
  • issue/private_message-3333001
  • issue/private_message-3337216
  • issue/private_message-3088743
  • issue/private_message-3337221
  • issue/private_message-3337222
  • issue/private_message-3343726
  • issue/private_message-3337224
  • issue/private_message-3339976
  • issue/private_message-3297888
  • issue/private_message-3355273
  • issue/private_message-3356586
  • issue/private_message-3378251
  • issue/private_message-3391546
  • issue/private_message-3381016
  • issue/private_message-3412209
  • issue/private_message-3414396
  • issue/private_message-3204985
  • issue/private_message-3043898
  • issue/private_message-3384791
  • issue/private_message-3121606
  • issue/private_message-3035510
  • issue/private_message-3337240
  • issue/private_message-3417386
  • issue/private_message-3183523
  • issue/private_message-3386742
  • issue/private_message-3322629
  • issue/private_message-3322625
  • issue/private_message-3417433
  • issue/private_message-3241221
  • issue/private_message-3417449
  • issue/private_message-3417461
  • issue/private_message-3271454
  • issue/private_message-3417457
  • issue/private_message-3417644
  • issue/private_message-3417654
  • issue/private_message-3417705
  • issue/private_message-3417731
  • issue/private_message-3417742
  • issue/private_message-3417747
  • issue/private_message-3417751
  • issue/private_message-3417752
  • issue/private_message-3212104
  • issue/private_message-3427223
  • issue/private_message-3365542
  • issue/private_message-3424499
  • issue/private_message-3432140
  • issue/private_message-3439400
  • issue/private_message-3454771
  • issue/private_message-3456956
  • issue/private_message-3464363
  • issue/private_message-3464371
  • issue/private_message-3470070
  • issue/private_message-3470072
  • issue/private_message-3470928
  • issue/private_message-3475462
  • issue/private_message-2987189
  • issue/private_message-3477667
  • issue/private_message-3477873
  • issue/private_message-3478456
  • issue/private_message-3054106
  • issue/private_message-3479391
  • issue/private_message-3417748
  • issue/private_message-3480219
  • issue/private_message-3482103
  • issue/private_message-3482504
  • issue/private_message-3482630
  • issue/private_message-2971692
  • issue/private_message-3484561
  • issue/private_message-3484828
  • issue/private_message-3484854
  • issue/private_message-3485607
  • issue/private_message-3486915
  • issue/private_message-3487175
  • issue/private_message-3482416
  • issue/private_message-3487689
  • issue/private_message-3487705
  • issue/private_message-3487770
  • issue/private_message-3488097
  • issue/private_message-3484915
  • issue/private_message-3488247
  • issue/private_message-3488508
  • issue/private_message-3487692
  • issue/private_message-3484246
  • issue/private_message-3488863
  • issue/private_message-3486047
  • issue/private_message-3489091
  • issue/private_message-3489205
  • issue/private_message-3490037
  • issue/private_message-3490119
  • issue/private_message-3490456
  • issue/private_message-3489224
  • issue/private_message-3490346
  • issue/private_message-3490816
  • issue/private_message-3491252
  • issue/private_message-3491271
  • issue/private_message-3492177
  • issue/private_message-3492289
  • issue/private_message-3331865
  • issue/private_message-3497800
  • issue/private_message-3499154
  • issue/private_message-3499926
  • issue/private_message-3501083
  • issue/private_message-3501286
  • issue/private_message-3501694
  • issue/private_message-3502128
  • issue/private_message-3502140
  • issue/private_message-3502159
  • issue/private_message-3502162
  • issue/private_message-3502180
  • issue/private_message-3502186
  • issue/private_message-3502190
  • issue/private_message-3502496
  • issue/private_message-3504372
  • issue/private_message-3512770
  • issue/private_message-3513969
173 results
Show changes
Commits on Source (2)
Showing
with 206 additions and 270 deletions
......@@ -3,7 +3,6 @@
/.gitattributes
/.prettierignore
/.prettierrc.json
/phpcs.xml.dist
/phpstan-baseline.neon
/phpstan.neon
/vendor/
......
......@@ -26,6 +26,10 @@ private_message.settings:
ban_mode:
type: string
label: 'The blocking mode.'
constraints:
Choice:
- passive
- active
ban_message:
type: string
label: 'The message to show to the user when they are blocked.'
......
......@@ -5,6 +5,8 @@
* Hook documentation for Private Message Notify module hooks.
*/
declare(strict_types=1);
use Drupal\private_message\Entity\PrivateMessageInterface;
use Drupal\private_message\Entity\PrivateMessageThreadInterface;
......
......@@ -2,7 +2,7 @@ name: Private Message Notify
type: module
description: Implements new message notifications.
package: Private Message
core_version_requirement: ^9.3 || ^10 || ^11
core_version_requirement: ^10.3 || ^11
dependencies:
- message_notify:message_notify
- private_message:private_message
......@@ -5,13 +5,15 @@
* Primary module hooks for Private Message Notify module.
*/
declare(strict_types=1);
use Drupal\private_message\Entity\PrivateMessageInterface;
use Drupal\private_message\Entity\PrivateMessageThreadInterface;
/**
* Implements hook_private_message_new_message().
*/
function private_message_notify_private_message_new_message(PrivateMessageInterface $privateMessage, PrivateMessageThreadInterface $thread) {
function private_message_notify_private_message_new_message(PrivateMessageInterface $privateMessage, PrivateMessageThreadInterface $thread): void {
/** @var \Drupal\private_message_notify\Service\PrivateMessageNotifierInterface $notifier */
$notifier = \Drupal::service('private_message_notify.notifier');
$notifier->notify($privateMessage, $thread);
......
services:
_defaults:
autoconfigure: true
autowire: true
private_message_notify.notifier:
class: Drupal\private_message_notify\Service\PrivateMessageNotifier
arguments:
- '@private_message.service'
- '@current_user'
- '@user.data'
- '@config.factory'
- '@entity_type.manager'
- '@message_notify.sender'
- '@module_handler'
- '@logger.factory'
<?php
declare(strict_types=1);
namespace Drupal\private_message_notify\Service;
use Drupal\Core\Config\ConfigFactoryInterface;
......@@ -12,114 +14,34 @@ use Drupal\message_notify\MessageNotifier;
use Drupal\private_message\Entity\PrivateMessageInterface;
use Drupal\private_message\Entity\PrivateMessageThreadInterface;
use Drupal\private_message\Service\PrivateMessageServiceInterface;
use Drupal\private_message\Traits\PrivateMessageSettingsTrait;
use Drupal\user\UserDataInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
/**
* A service class for sending notifications of private messages.
*/
class PrivateMessageNotifier implements PrivateMessageNotifierInterface {
/**
* The private message service.
*
* @var \Drupal\private_message\Service\PrivateMessageServiceInterface
*/
protected $privateMessageService;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected $currentUser;
/**
* The user data service.
*
* @var \Drupal\user\UserDataInterface
*/
protected $userData;
/**
* The configuration factory service.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected $config;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The message notification service.
*
* @var \Drupal\message_notify\MessageNotifier
*/
protected $messageNotifier;
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The logger service for private message notifications.
*
* @var \Drupal\Core\Logger\LoggerChannelInterface
*/
protected $logger;
use PrivateMessageSettingsTrait;
/**
* Constructs a new PrivateMessageNotifier object.
*
* @param \Drupal\private_message\Service\PrivateMessageServiceInterface $privateMessageService
* The private message service.
* @param \Drupal\Core\Session\AccountProxyInterface $currentUser
* The current user.
* @param \Drupal\user\UserDataInterface $userData
* The user data service.
* @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
* The configuration factory service.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager service.
* @param \Drupal\message_notify\MessageNotifier $messageNotifier
* The message notification service.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
* The module handler service.
* @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $loggerFactory
* The logger channel factory.
*/
public function __construct(
PrivateMessageServiceInterface $privateMessageService,
AccountProxyInterface $currentUser,
UserDataInterface $userData,
ConfigFactoryInterface $configFactory,
EntityTypeManagerInterface $entityTypeManager,
MessageNotifier $messageNotifier,
ModuleHandlerInterface $moduleHandler,
LoggerChannelFactoryInterface $loggerFactory,
) {
$this->privateMessageService = $privateMessageService;
$this->currentUser = $currentUser;
$this->userData = $userData;
$this->config = $configFactory->get('private_message.settings');
$this->entityTypeManager = $entityTypeManager;
$this->messageNotifier = $messageNotifier;
$this->moduleHandler = $moduleHandler;
$this->logger = $loggerFactory->get('private_message_notify');
}
protected readonly PrivateMessageServiceInterface $privateMessageService,
protected readonly AccountProxyInterface $currentUser,
protected readonly UserDataInterface $userData,
protected readonly ConfigFactoryInterface $configFactory,
protected readonly EntityTypeManagerInterface $entityTypeManager,
#[Autowire(service: 'message_notify.sender')]
protected readonly MessageNotifier $messageNotifier,
protected readonly ModuleHandlerInterface $moduleHandler,
protected readonly LoggerChannelFactoryInterface $loggerFactory,
) {}
/**
* {@inheritdoc}
*/
public function notify(PrivateMessageInterface $message, PrivateMessageThreadInterface $thread) {
$members = $this->getNotificationRecipients($message, $thread);
public function notify(PrivateMessageInterface $message, PrivateMessageThreadInterface $thread): void {
$members = $this->getRecipients($message, $thread);
foreach ($members as $member) {
// Skip the current user and any member without a valid email.
......@@ -131,7 +53,10 @@ class PrivateMessageNotifier implements PrivateMessageNotifierInterface {
$email = $member->getEmail();
if (empty($email)) {
// Log a warning if the email is missing, then skip this member.
$this->logger->warning('Notification not sent to user ID @uid due to missing email.', ['@uid' => $member->id()]);
$this->loggerFactory->get('private_message_notify')
->warning('Notification not sent to user ID @uid due to missing email.', [
'@uid' => $member->id(),
]);
continue;
}
......@@ -143,14 +68,12 @@ class PrivateMessageNotifier implements PrivateMessageNotifierInterface {
// Create and send the notification.
$notification = $this->entityTypeManager
->getStorage('message')
->create(
[
'template' => 'private_message_notification',
'uid' => $member->id(),
]
);
$notification->set('field_message_private_message', $message);
$notification->set('field_message_pm_thread', $thread);
->create([
'template' => 'private_message_notification',
'uid' => $member->id(),
'field_message_private_message' => $message,
'field_message_pm_thread' => $thread,
]);
$notification->setLanguage($member->getPreferredLangcode());
$notification->save();
......@@ -171,15 +94,14 @@ class PrivateMessageNotifier implements PrivateMessageNotifierInterface {
* The private message thread.
*
* @return bool
* A boolean indicating whether or not the message should be sent.
* A boolean indicating whether the message should be sent.
*/
private function shouldSend(AccountInterface $recipient, PrivateMessageInterface $message, PrivateMessageThreadInterface $thread) {
private function shouldSend(AccountInterface $recipient, PrivateMessageInterface $message, PrivateMessageThreadInterface $thread): bool {
// Don't notify the user by default.
$notify = FALSE;
// Check if notifications have been enabled.
if ($this->config->get('enable_notifications')) {
if ($this->getPrivateMessageSettings()->get('enable_notifications')) {
// Eligibility to receive notifications will be checked.
$eligible_to_receive = FALSE;
......@@ -192,7 +114,7 @@ class PrivateMessageNotifier implements PrivateMessageNotifierInterface {
}
// Check if the user has not made any selection, and the system default is
// to send:
elseif (is_null($user_default) && $this->config->get('notify_by_default')) {
elseif (is_null($user_default) && $this->getPrivateMessageSettings()->get('notify_by_default')) {
$eligible_to_receive = TRUE;
}
......@@ -207,7 +129,7 @@ class PrivateMessageNotifier implements PrivateMessageNotifierInterface {
// Check if the user has not yet set a value.
if (is_null($notify_when_using)) {
// The user has not yet set a value, so use the system default.
$notify_when_using = $this->config->get('notify_when_using');
$notify_when_using = $this->getPrivateMessageSettings()->get('notify_when_using');
}
// Get the number of seconds a user has set in their profile, after
......@@ -216,7 +138,7 @@ class PrivateMessageNotifier implements PrivateMessageNotifierInterface {
// Check if the user has not yet set a value.
if (is_null($away_time)) {
// The user has not yet set a value, so use the system default.
$away_time = $this->config->get('number_of_seconds_considered_away');
$away_time = $this->getPrivateMessageSettings()->get('number_of_seconds_considered_away');
}
// Check if users should always be notified.
......@@ -234,26 +156,22 @@ class PrivateMessageNotifier implements PrivateMessageNotifierInterface {
}
/**
* The users to receive notifications.
* Returns the list of recipients as user accounts.
*
* @return \Drupal\Core\Session\AccountInterface[]
* An array of Account objects of the thread members who are to receive
* the notification.
* Array of thread members user entities receiving the notification.
*/
public function getNotificationRecipients(PrivateMessageInterface $message, PrivateMessageThreadInterface $thread) {
protected function getRecipients(PrivateMessageInterface $message, PrivateMessageThreadInterface $thread): array {
$recipients = $thread->getMembers();
$exclude = [];
// Allow other modules to alter notification recipients.
$this->moduleHandler->invokeAll(
'private_message_notify_exclude', [
$message,
$thread,
&$exclude,
]
);
$this->moduleHandler->invokeAll('private_message_notify_exclude', [
$message,
$thread,
&$exclude,
]);
// @phpstan-ignore-next-line
if (empty($exclude)) {
return $recipients;
}
......@@ -267,4 +185,21 @@ class PrivateMessageNotifier implements PrivateMessageNotifierInterface {
);
}
/**
* The users to receive notifications.
*
* @return \Drupal\Core\Session\AccountInterface[]
* An array of Account objects of the thread members who are to receive
* the notification.
*
* @deprecated in private_message:4.0.0 and is removed from
* private_message:5.0.0. Instead, use self ::getRecipients()
*
* @see https://www.drupal.org/node/3490530
*/
public function getNotificationRecipients(PrivateMessageInterface $message, PrivateMessageThreadInterface $thread) {
@trigger_error(__METHOD__ . '() is deprecated in private_message:4.0.0 and is removed from private_message:5.0.0. Instead, use self ::getRecipients(). See https://www.drupal.org/node/3490530', E_USER_DEPRECATED);
return $this->getRecipients($message, $thread);
}
}
<?php
declare(strict_types=1);
namespace Drupal\private_message_notify\Service;
use Drupal\private_message\Entity\PrivateMessageInterface;
......
type: module
name: Private Message Notify Test
package: Testing
core_version_requirement: ^9.3 || ^10 || ^11
core_version_requirement: ^10.3 || ^11
dependencies:
- private_message:private_message_notify
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="private_message">
<description>PHP CodeSniffer configuration for Private Message module.</description>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/ruleset.xml"/>
<arg name="extensions" value="php,inc,module,install,info,test,profile,theme"/>
<!-- Strict typing & type hinting rules -->
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing">
<severity>5</severity>
<!-- TODO: Remove these two exclusions in private_message:5.0.0 -->
<exclude-pattern>src/Mapper/PrivateMessageMapper.php</exclude-pattern>
<exclude-pattern>src/Mapper/PrivateMessageMapperInterface.php</exclude-pattern>
</rule>
</ruleset>
......@@ -5,6 +5,8 @@
* Hook documentation for Private Message module hooks.
*/
declare(strict_types=1);
use Drupal\Core\Entity\EntityInterface;
use Drupal\private_message\Entity\PrivateMessageInterface;
use Drupal\private_message\Entity\PrivateMessageThreadInterface;
......@@ -19,7 +21,7 @@ use Drupal\private_message\Entity\PrivateMessageThreadInterface;
* @param string $viewMode
* The view mode being rendered on the private message.
*/
function hook_private_message_view_alter(array &$build, EntityInterface $privateMessage, $viewMode) {
function hook_private_message_view_alter(array &$build, EntityInterface $privateMessage, string $viewMode): void {
// Create a new class specific to the author of the message.
$class = 'private-message-author-' . $privateMessage->getOwnerId();
// Add the class to the wrapper.
......
name: Private Message
description: A private message system for users to send messages to each other
core_version_requirement: ^10 || ^11
core_version_requirement: ^10.3 || ^11
type: module
package: Private Message
......
......@@ -5,14 +5,16 @@
* Holds install and update hooks for the Private Message module.
*/
declare(strict_types=1);
use Drupal\Core\Database\IntegrityConstraintViolationException;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\private_message\Form\ConfigForm as Config;
use Drupal\private_message\Model\BlockType;
/**
* Implements hook_install().
*/
function private_message_install() {
function private_message_install(): void {
$messenger = \Drupal::messenger();
$messenger->addStatus(t('Make sure you granted "use private messaging system" and "access user profiles" permissions for roles you want to provide access to use private messages.'));
$messenger->addStatus(t('Enable "Private Message Actions" and "Private Message Inbox" block to have simple private message UI from the box.'));
......@@ -21,7 +23,7 @@ function private_message_install() {
/**
* Implements hook_uninstall().
*/
function private_message_uninstall() {
function private_message_uninstall(): void {
\Drupal::configFactory()->getEditable('core.entity_view_display.user.user.private_message_author')->delete();
\Drupal::configFactory()->getEditable('core.entity_view_mode.user.private_message_author')->delete();
\Drupal::configFactory()->getEditable('message.template.private_message_notification')->delete();
......@@ -31,41 +33,10 @@ function private_message_uninstall() {
\Drupal::configFactory()->getEditable('core.entity_view_display.message.private_message_notification.default')->delete();
}
/**
* Implements hook_update_n().
*/
function private_message_update_8001() {
$config_factory = \Drupal::configFactory();
$config_factory->getEditable('private_message.settings')
->set('enable_email_notifications', TRUE)
->set('send_by_default', TRUE)
->save(TRUE);
$message_notification_mail_map = [
'subject' => 'Private message at [site:name]',
'body' => "[user:display-name],\n\nYou have received a private message at [site:name] from [private_message:author_name]\n\nThe message is as follows:\n\n[private_message:message]\n\nYou can view the entire thread and reply to this message at:\n\n[private_message_thread:url]\n\n\nThank you,\n\n-- [site:name]",
];
$config_factory->getEditable('private_message.mail')
->set('message_notification', $message_notification_mail_map)
->save(TRUE);
}
/**
* Add the create private message label.
*/
function private_message_update_8002() {
$config_factory = \Drupal::configFactory();
$config_factory->getEditable('private_message.settings')
->set('create_message_label', 'Create Private Message')
->save(TRUE);
}
/**
* Implements hook_schema().
*/
function private_message_schema() {
function private_message_schema(): array {
$schema['pm_thread_history'] = [
'description' => 'A record of which {users} have read which {node}s.',
'fields' => [
......@@ -104,10 +75,41 @@ function private_message_schema() {
return $schema;
}
/**
* Implements hook_update_n().
*/
function private_message_update_8001(): void {
$config_factory = \Drupal::configFactory();
$config_factory->getEditable('private_message.settings')
->set('enable_email_notifications', TRUE)
->set('send_by_default', TRUE)
->save(TRUE);
$message_notification_mail_map = [
'subject' => 'Private message at [site:name]',
'body' => "[user:display-name],\n\nYou have received a private message at [site:name] from [private_message:author_name]\n\nThe message is as follows:\n\n[private_message:message]\n\nYou can view the entire thread and reply to this message at:\n\n[private_message_thread:url]\n\n\nThank you,\n\n-- [site:name]",
];
$config_factory->getEditable('private_message.mail')
->set('message_notification', $message_notification_mail_map)
->save(TRUE);
}
/**
* Add the create private message label.
*/
function private_message_update_8003() {
function private_message_update_8002(): void {
$config_factory = \Drupal::configFactory();
$config_factory->getEditable('private_message.settings')
->set('create_message_label', 'Create Private Message')
->save(TRUE);
}
/**
* Add the create private message label.
*/
function private_message_update_8003(): void {
$config_factory = \Drupal::configFactory();
$config_factory->getEditable('private_message.settings')
->set('create_message_label', 'Create Private Message')
......@@ -117,7 +119,7 @@ function private_message_update_8003() {
/**
* Install the module schema.
*/
function private_message_update_8004() {
function private_message_update_8004(): void {
$database = \Drupal::database();
// Create database table.
......@@ -162,7 +164,7 @@ function private_message_update_8004() {
/**
* Migrate the records into a new table.
*/
function private_message_update_8005(&$sandbox) {
function private_message_update_8005(?array &$sandbox = NULL): void {
// Store last processed thread ID, so the sites with a huge amount of threads
// will have at least some chances to complete this update in a few runs.
$last_processed = \Drupal::state()->get('scalable_bridge_last', 0);
......@@ -259,7 +261,7 @@ function private_message_update_8005(&$sandbox) {
/**
* Drop the old entity types and field definitions.
*/
function private_message_update_8006(&$sandbox) {
function private_message_update_8006(?array &$sandbox = NULL): void {
$entity_update_manager = \Drupal::entityDefinitionUpdateManager();
foreach (['pm_thread_access_time', 'pm_thread_delete_time'] as $entity_type_id) {
if ($entity_type = $entity_update_manager->getEntityType($entity_type_id)) {
......@@ -276,7 +278,7 @@ function private_message_update_8006(&$sandbox) {
/**
* Enable notifications submodule.
*/
function private_message_update_8007() {
function private_message_update_8007(): void {
// Delete the configs that will be migrated to private_message_notify.
// Only delete configurations if private_message_notify is not installed
// already.
......@@ -361,7 +363,7 @@ function private_message_update_8008() {
/**
* Skip update because of unnecessary.
*/
function private_message_update_8009() {
function private_message_update_8009(): void {
// Leave this hook update empty because it already passed who applied patch
// from issue https://www.drupal.org/project/private_message/issues/3265901
}
......@@ -369,7 +371,7 @@ function private_message_update_8009() {
/**
* Skip update because of unnecessary.
*/
function private_message_update_8010() {
function private_message_update_8010(): void {
// Leave this hook update empty because it already passed who applied patch
// from issue https://www.drupal.org/project/private_message/issues/3265901
}
......@@ -377,24 +379,21 @@ function private_message_update_8010() {
/**
* Install the private_message_ban entity type.
*/
function private_message_update_8011() {
if (!\Drupal::database()->schema()->tableExists('private_message_ban')) {
\Drupal::entityTypeManager()->clearCachedDefinitions();
\Drupal::entityDefinitionUpdateManager()->installEntityType(\Drupal::entityTypeManager()->getDefinition('private_message_ban'));
}
else {
function private_message_update_8011(): string {
if (\Drupal::database()->schema()->tableExists('private_message_ban')) {
return 'Private Message Ban entity already exists';
}
\Drupal::entityTypeManager()->clearCachedDefinitions();
\Drupal::entityDefinitionUpdateManager()->installEntityType(\Drupal::entityTypeManager()->getDefinition('private_message_ban'));
return 'Installed Private Message Ban entity';
}
/**
* Sets default values for the block functionality.
*/
function private_message_update_8012() {
function private_message_update_8012(): void {
\Drupal::configFactory()->getEditable('private_message.settings')
->set('ban_mode', Config::PASSIVE)
->set('ban_mode', BlockType::Passive->value)
->set('ban_message', 'User is unable to receive your message')
->set('ban_label', 'Block')
->set('unban_label', 'Unblock')
......@@ -404,7 +403,7 @@ function private_message_update_8012() {
/**
* Install the `subject` field to 'private_message_thread' entity.
*/
function private_message_update_8013() {
function private_message_update_8013(): void {
$storage_definition = BaseFieldDefinition::create('string')
->setLabel(t('Subject'))
->setSetting('max_length', 64)
......@@ -422,7 +421,7 @@ function private_message_update_8013() {
/**
* Show input formats functionality.
*/
function private_message_update_8014() {
function private_message_update_8014(): void {
$config = \Drupal::configFactory()
->getEditable('private_message.settings');
$rows = $config->getRawData();
......
......@@ -5,6 +5,9 @@
* Contains hooks for the private message module.
*/
declare(strict_types=1);
use Drupal\Component\Render\MarkupInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
......@@ -17,7 +20,7 @@ use Drupal\user\Entity\User;
/**
* Implements hook_views_data().
*/
function private_message_views_data() {
function private_message_views_data(): array {
$data['private_message_threads']['has_history'] = [
'title' => t('Clean history'),
'group' => t('Private Message Thread'),
......@@ -86,7 +89,7 @@ function private_message_views_data() {
/**
* Implements hook_entity_extra_field_info().
*/
function private_message_entity_extra_field_info() {
function private_message_entity_extra_field_info(): array {
$fields = [];
$private_message_thread_bundles = \Drupal::service('entity_type.bundle.info')->getBundleInfo('private_message_thread');
......@@ -206,7 +209,7 @@ function private_message_entity_extra_field_info() {
*
* @see hook_entity_view()
*/
function private_message_private_message_thread_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
function private_message_private_message_thread_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, string $view_mode): void {
if ($display->getComponent('last_message')) {
$messages = $entity->getMessages();
if ($messages) {
......@@ -276,8 +279,7 @@ function private_message_private_message_thread_view(array &$build, EntityInterf
*
* @see hook_entity_view()
*/
function private_message_user_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
function private_message_user_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, string $view_mode): void {
if ($display->getComponent('linked_username')) {
if (\Drupal::currentUser()->hasPermission('access user profiles')) {
$url = Url::fromRoute('entity.user.canonical', ['user' => $entity->id()]);
......@@ -347,7 +349,7 @@ function private_message_user_view(array &$build, EntityInterface $entity, Entit
*
* @see hook_entity_view()
*/
function private_message_node_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
function private_message_node_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, string $view_mode): void {
\Drupal::service('private_message.service')->createRenderablePrivateMessageThreadLink($build, $entity, $display, $view_mode);
}
......@@ -358,7 +360,7 @@ function private_message_node_view(array &$build, EntityInterface $entity, Entit
*
* @see hook_entity_view()
*/
function private_message_comment_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
function private_message_comment_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, string $view_mode): void {
\Drupal::service('private_message.service')->createRenderablePrivateMessageThreadLink($build, $entity, $display, $view_mode);
}
......@@ -369,14 +371,14 @@ function private_message_comment_view(array &$build, EntityInterface $entity, En
*
* @see hook_entity_view()
*/
function private_message_profile_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
function private_message_profile_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, string $view_mode): void {
\Drupal::service('private_message.service')->createRenderablePrivateMessageThreadLink($build, $entity, $display, $view_mode);
}
/**
* Implements hook_form_alter().
*/
function private_message_form_alter(&$form, FormStateInterface $formState, $form_id) {
function private_message_form_alter(array &$form, FormStateInterface $formState, string $form_id): void {
// Act on any implementation of the private message entity form. This form
// can potentially exist multiple times on a page, so the form ID will be
// dynamic in such a case.
......@@ -403,8 +405,7 @@ function private_message_form_alter(&$form, FormStateInterface $formState, $form
*
* @see hook_form_alter()
*/
function private_message_form_user_form_alter(array &$form, FormStateInterface $formState) {
function private_message_form_user_form_alter(array &$form, FormStateInterface $formState): void {
$config = \Drupal::config('private_message.settings');
// Get the user whose account is being modified.
......@@ -503,7 +504,7 @@ function private_message_form_user_form_alter(array &$form, FormStateInterface $
*
* @see private_message_form_user_form_alter()
*/
function private_message_user_form_submit(array &$form, FormStateInterface $formState) {
function private_message_user_form_submit(array &$form, FormStateInterface $formState): void {
// Get the user whose account object is being modified.
$user = $formState->getFormObject()->getEntity();
$user_data = \Drupal::service('user.data');
......@@ -525,7 +526,7 @@ function private_message_user_form_submit(array &$form, FormStateInterface $form
/**
* Implements hook_theme().
*/
function private_message_theme() {
function private_message_theme(): array {
return [
'private_message_thread' => [
'render element' => 'elements',
......@@ -557,7 +558,7 @@ function private_message_theme() {
* - private_message_thread: The private message thread object.
* - view_mode: View mode; e.g., 'full', 'teaser', etc.
*/
function template_preprocess_private_message_thread(array &$variables) {
function template_preprocess_private_message_thread(array &$variables): void {
$variables['view_mode'] = $variables['elements']['#view_mode'];
// Provide a distinct $teaser boolean.
$variables['private_message_thread'] = $variables['elements']['#private_message_thread'];
......@@ -587,7 +588,7 @@ function template_preprocess_private_message_thread(array &$variables) {
* - private_message: The private message object.
* - view_mode: View mode; e.g., 'full', 'teaser', etc.
*/
function template_preprocess_private_message(array &$variables) {
function template_preprocess_private_message(array &$variables): void {
$variables['view_mode'] = $variables['elements']['#view_mode'];
// Provide a distinct $teaser boolean.
$variables['private_message'] = $variables['elements']['#private_message'];
......@@ -608,7 +609,7 @@ function template_preprocess_private_message(array &$variables) {
/**
* Implements hook_help().
*/
function private_message_help($route_name, RouteMatchInterface $route_match) {
function private_message_help($route_name, RouteMatchInterface $route_match): string|array|MarkupInterface {
switch ($route_name) {
case 'help.page.private_message':
return t(
......@@ -619,6 +620,7 @@ function private_message_help($route_name, RouteMatchInterface $route_match) {
]
);
}
return [];
}
/**
......@@ -628,7 +630,7 @@ function private_message_help($route_name, RouteMatchInterface $route_match) {
* may be altered in themes/templates, and therefore should not be depended
* upon.
*/
function private_message_preprocess_field__private_message_thread__private_messages(&$vars) {
function private_message_preprocess_field__private_message_thread__private_messages(array &$vars): void {
foreach (array_keys($vars['items']) as $index) {
$vars['items'][$index]['attributes']->setAttribute('class', 'private-message-wrapper');
}
......@@ -641,7 +643,7 @@ function private_message_preprocess_field__private_message_thread__private_messa
* classes may be altered in themes/templates, and therefore should not be
* depended upon.
*/
function private_message_preprocess_container(&$vars) {
function private_message_preprocess_container(array &$vars): void {
if (!empty($vars['element']['#id'])) {
if (str_starts_with($vars['element']['#id'], 'edit-members-wrapper')) {
// Add a custom class to the private message members widget container.
......@@ -659,7 +661,7 @@ function private_message_preprocess_container(&$vars) {
*
* Swaps out tokens with values.
*/
function private_message_message_view_alter(array &$build) {
function private_message_message_view_alter(array &$build): void {
if ($build['#message']->bundle() == 'private_message_notification') {
$data = [
'private_message' => $build['#message']->get('field_message_private_message')->entity,
......@@ -679,13 +681,13 @@ function private_message_message_view_alter(array &$build) {
/**
* Implements hook_suggestions_HOOK_alter().
*/
function private_message_theme_suggestions_private_message_thread_alter(&$suggestions, &$vars) {
function private_message_theme_suggestions_private_message_thread_alter(array &$suggestions, array &$vars): void {
$suggestions[] = 'private_message_thread__' . $vars['elements']['#view_mode'];
}
/**
* Implements hook_suggestions_HOOK_alter().
*/
function private_message_theme_suggestions_private_message_alter(&$suggestions, &$vars) {
function private_message_theme_suggestions_private_message_alter(array &$suggestions, array &$vars): void {
$suggestions[] = 'private_message__' . $vars['elements']['#view_mode'];
}
......@@ -7,7 +7,7 @@ private_message.private_message_page:
_permission: 'use private messaging system,access user profiles'
_user_is_logged_in: 'TRUE'
options:
no_cache: 'TRUE'
no_cache: TRUE
entity.private_message_thread.canonical:
path: '/private-messages/{private_message_thread}'
......@@ -147,6 +147,7 @@ private_message.ban_user_form:
requirements:
_permission: 'use private messaging system,access user profiles'
_user_is_logged_in: 'TRUE'
user: \d+
options:
parameters:
user:
......
services:
private_message.mapper:
class: Drupal\private_message\Mapper\PrivateMessageMapper
arguments:
- '@database'
- '@current_user'
_defaults:
autoconfigure: true
autowire: true
private_message.service:
class: Drupal\private_message\Service\PrivateMessageService
arguments:
- '@private_message.mapper'
- '@current_user'
- '@config.factory'
- '@user.data'
- '@cache_tags.invalidator'
- '@entity_type.manager'
- '@datetime.time'
Drupal\private_message\Service\PrivateMessageServiceInterface: '@private_message.service'
private_message.uninstaller:
class: Drupal\private_message\Service\PrivateMessageUninstaller
Drupal\private_message\Service\PrivateMessageUninstallerInterface: '@private_message.uninstaller'
private_message.ban_manager:
class: Drupal\private_message\Service\PrivateMessageBanManager
arguments:
- '@current_user'
- '@entity_type.manager'
- '@database'
- '@messenger'
Drupal\private_message\Service\PrivateMessageBanManagerInterface: '@private_message.ban_manager'
cache_context.private_message_thread:
class: Drupal\private_message\Cache\Context\PrivateMessageThreadCacheContext
arguments:
- '@current_route_match'
tags:
- { name: cache.context }
private_message.thread_manager:
class: Drupal\private_message\Service\PrivateMessageThreadManager
arguments:
- '@private_message.service'
Drupal\private_message\Service\PrivateMessageThreadManagerInterface: '@private_message.thread_manager'
private_message.private_message_config_form_manager:
class: Drupal\private_message\PluginManager\PrivateMessageConfigFormManager
parent: default_plugin_manager
Drupal\private_message\PluginManager\PrivateMessageConfigFormManagerInterface: '@private_message.private_message_config_form_manager'
private_message.mapper:
class: Drupal\private_message\Mapper\PrivateMessageMapper
deprecated: The "%service_id%" service is deprecated in private_message:4.0.0 and is removed from private_message:5.0.0. No replacement is provided. See https://www.drupal.org/node/3490530
......@@ -5,13 +5,15 @@
* Contains preprocess functions for the private message module.
*/
declare(strict_types=1);
use Drupal\Core\Link;
use Drupal\Core\Url;
/**
* Implements hook_preprocess_private_message_notification_block().
*/
function template_preprocess_private_message_notification_block(&$vars) {
function template_preprocess_private_message_notification_block(array &$vars): void {
$vars['notification_image_path'] = base_path() . \Drupal::service('extension.list.module')->getPath('private_message') . '/images/private-message-notification-icon.png';
switch ($vars['count_method']) {
......
......@@ -5,6 +5,8 @@
* Provides tokens for the Private Message module.
*/
declare(strict_types=1);
use Drupal\Core\Datetime\Entity\DateFormat;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Render\BubbleableMetadata;
......@@ -14,8 +16,7 @@ use Drupal\user\Entity\User;
/**
* Implements hook_token_info().
*/
function private_message_token_info() {
function private_message_token_info(): array {
// Defined the private message token type.
$private_message_type = [
'name' => t('Private Messages'),
......@@ -89,7 +90,7 @@ function private_message_token_info() {
/**
* Implements hook_tokens().
*/
function private_message_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
function private_message_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata): array {
$replacements = [];
$token_service = \Drupal::token();
......
<?php
declare(strict_types=1);
namespace Drupal\private_message\Ajax;
use Drupal\Component\Render\MarkupInterface;
use Drupal\Core\Ajax\CommandInterface;
/**
* Ajax Command to insert private message inbox threads.
* Ajax command to insert private message inbox threads.
*/
class PrivateMessageInboxInsertThreadsCommand implements CommandInterface {
/**
* The HTML for the threads to be inserted in the page.
*
* @var string
*/
protected $threads;
/**
* Boolean to determine if there are more threads to come.
*
* @var bool
*/
protected $hasNext;
/**
* Constructs a PrivateMessageInboxInsertThreadsCommand object.
*
* @param string $threads
* The HTML for the threads to be inserted in the page.
* @param bool $has_next
* A boolean to know if there are more threads after.
*/
public function __construct($threads, $has_next) {
$this->threads = $threads;
$this->hasNext = $has_next;
public function __construct(
protected readonly MarkupInterface|string $threads,
protected readonly bool $hasMoreThreads,
) {
}
/**
* {@inheritdoc}
*/
public function render() {
public function render(): array {
return [
'command' => 'insertInboxOldPrivateMessageThreads',
'threads' => $this->threads,
'hasNext' => $this->hasNext,
'threads' => (string) $this->threads,
'hasNext' => $this->hasMoreThreads,
];
}
......
<?php
declare(strict_types=1);
namespace Drupal\private_message\Ajax;
use Drupal\Core\Ajax\CommandInterface;
......@@ -12,7 +14,7 @@ class PrivateMessageInboxTriggerUpdateCommand implements CommandInterface {
/**
* {@inheritdoc}
*/
public function render() {
public function render(): array {
return [
'command' => 'privateMessageTriggerInboxUpdate',
];
......