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 (3)
Showing
with 191 additions and 778 deletions
......@@ -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
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'
......@@ -12,108 +12,28 @@ 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;
use PrivateMessageSettingsTrait;
/**
* The logger service for private message notifications.
*
* @var \Drupal\Core\Logger\LoggerChannelInterface
*/
protected $logger;
/**
* 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}
......@@ -131,7 +51,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;
}
......@@ -174,12 +97,11 @@ class PrivateMessageNotifier implements PrivateMessageNotifierInterface {
* A boolean indicating whether or not the message should be sent.
*/
private function shouldSend(AccountInterface $recipient, PrivateMessageInterface $message, PrivateMessageThreadInterface $thread) {
// Don't notify the user by default.
$notify = FALSE;
// Check if notifications have been enabled.
if ($this->config->get('enable_notifications')) {
if ($this->getSettings()->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->getSettings()->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->getSettings()->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->getSettings()->get('number_of_seconds_considered_away');
}
// Check if users should always be notified.
......@@ -253,7 +175,6 @@ class PrivateMessageNotifier implements PrivateMessageNotifierInterface {
]
);
// @phpstan-ignore-next-line
if (empty($exclude)) {
return $recipients;
}
......
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
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
......
......@@ -7,7 +7,7 @@
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().
......@@ -394,7 +394,7 @@ function private_message_update_8011() {
*/
function private_message_update_8012() {
\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')
......
services:
_defaults:
autoconfigure: true
autowire: true
private_message.mapper:
class: Drupal\private_message\Mapper\PrivateMessageMapper
arguments:
- '@database'
- '@current_user'
Drupal\private_message\Mapper\PrivateMessageMapperInterface: '@private_message.mapper'
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
......@@ -36,9 +29,9 @@ services:
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'
......@@ -13,22 +13,9 @@ use Drupal\Core\Routing\ResettableStackedRouteMatchInterface;
*/
class PrivateMessageThreadCacheContext implements CacheContextInterface {
/**
* The current route matcher.
*
* @var \Drupal\Core\Routing\ResettableStackedRouteMatchInterface
*/
protected $currentRouteMatcher;
/**
* Constructs a new UserCacheContextBase class.
*
* @param \Drupal\Core\Routing\ResettableStackedRouteMatchInterface $currentRouteMatcher
* The current route matcher.
*/
public function __construct(ResettableStackedRouteMatchInterface $currentRouteMatcher) {
$this->currentRouteMatcher = $currentRouteMatcher;
}
public function __construct(
protected readonly ResettableStackedRouteMatchInterface $currentRouteMatcher,
) {}
/**
* {@inheritdoc}
......
......@@ -4,11 +4,8 @@ namespace Drupal\private_message\Controller;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\SettingsCommand;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\private_message\Ajax\PrivateMessageInboxInsertThreadsCommand;
use Drupal\private_message\Ajax\PrivateMessageInboxUpdateCommand;
use Drupal\private_message\Ajax\PrivateMessageInsertNewMessagesCommand;
......@@ -16,7 +13,6 @@ use Drupal\private_message\Ajax\PrivateMessageInsertPreviousMessagesCommand;
use Drupal\private_message\Ajax\PrivateMessageInsertThreadCommand;
use Drupal\private_message\Ajax\PrivateMessageUpdateUnreadItemsCountCommand;
use Drupal\private_message\Service\PrivateMessageServiceInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
/**
......@@ -24,77 +20,11 @@ use Symfony\Component\HttpFoundation\RequestStack;
*/
class AjaxController extends ControllerBase implements AjaxControllerInterface {
/**
* The renderer service.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* The entity manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The configuration factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected $currentUser;
/**
* The private message service.
*
* @var \Drupal\private_message\Service\PrivateMessageServiceInterface
*/
protected $privateMessageService;
public function __construct(
RendererInterface $renderer,
RequestStack $requestStack,
EntityTypeManagerInterface $entityTypeManager,
ConfigFactoryInterface $configFactory,
AccountProxyInterface $currentUser,
PrivateMessageServiceInterface $privateMessageService,
) {
$this->renderer = $renderer;
$this->requestStack = $requestStack;
$this->entityTypeManager = $entityTypeManager;
$this->configFactory = $configFactory;
$this->currentUser = $currentUser;
$this->privateMessageService = $privateMessageService;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('renderer'),
$container->get('request_stack'),
$container->get('entity_type.manager'),
$container->get('config.factory'),
$container->get('current_user'),
$container->get('private_message.service'),
);
}
protected readonly RendererInterface $renderer,
protected readonly RequestStack $requestStack,
protected readonly PrivateMessageServiceInterface $privateMessageService,
) {}
/**
* {@inheritdoc}
......@@ -155,7 +85,7 @@ class AjaxController extends ControllerBase implements AjaxControllerInterface {
$count = 0;
if (is_numeric($thread_id) && is_numeric($message_id)) {
/** @var \Drupal\private_message\Entity\PrivateMessageThreadInterface $thread */
$thread = $this->entityTypeManager
$thread = $this->entityTypeManager()
->getStorage('private_message_thread')
->load($thread_id);
if ($thread) {
......@@ -164,9 +94,9 @@ class AjaxController extends ControllerBase implements AjaxControllerInterface {
$count = count($new_messages);
if ($count) {
$messages = [];
$view_builder = $this->entityTypeManager->getViewBuilder('private_message');
$view_builder = $this->entityTypeManager()->getViewBuilder('private_message');
foreach ($new_messages as $message) {
if ($message->access('view', $this->currentUser)) {
if ($message->access('view', $this->currentUser())) {
$message_view = $view_builder->view($message);
$message_view['#prefix'] = '<div class="private-message-wrapper field__item">';
$message_view['#suffix'] = '</div>';
......@@ -198,10 +128,10 @@ class AjaxController extends ControllerBase implements AjaxControllerInterface {
if (count($message_info['messages'])) {
$messages = [];
$view_builder = $this->entityTypeManager->getViewBuilder('private_message');
$view_builder = $this->entityTypeManager()->getViewBuilder('private_message');
$has_next = $message_info['next_exists'];
foreach ($message_info['messages'] as $message) {
if ($message->access('view', $this->currentUser)) {
if ($message->access('view', $this->currentUser())) {
$message_view = $view_builder->view($message);
$message_view['#prefix'] = '<div class="private-message-wrapper field__item">';
$message_view['#suffix'] = '</div>';
......@@ -230,10 +160,10 @@ class AjaxController extends ControllerBase implements AjaxControllerInterface {
$thread_info = $this->privateMessageService->getThreadsForUser($thread_count, $timestamp);
$has_next = FALSE;
if (count($thread_info['threads'])) {
$view_builder = $this->entityTypeManager->getViewBuilder('private_message_thread');
$view_builder = $this->entityTypeManager()->getViewBuilder('private_message_thread');
$threads = [];
foreach ($thread_info['threads'] as $thread) {
if ($thread->access('view', $this->currentUser)) {
if ($thread->access('view', $this->currentUser())) {
$has_next = $thread_info['next_exists'];
$threads[] = $view_builder->view($thread, 'inbox');
}
......@@ -263,18 +193,19 @@ class AjaxController extends ControllerBase implements AjaxControllerInterface {
else {
// No IDs were posted, so the maximum possible number of threads to be
// returned is retrieved from the block settings.
$thread_count = $this->configFactory->get('block.block.privatemessageinbox')->get('settings.thread_count');
$thread_count = $this->config('block.block.privatemessageinbox')
->get('settings.thread_count');
$inbox_threads = $this->privateMessageService->getUpdatedInboxThreads([], $thread_count);
}
// Only need to do something if any thread IDS were found.
if (count($inbox_threads['thread_ids'])) {
$view_builder = $this->entityTypeManager->getViewBuilder('private_message_thread');
$view_builder = $this->entityTypeManager()->getViewBuilder('private_message_thread');
// Render any new threads as HTML to be sent to the browser.
$rendered_threads = [];
foreach (array_keys($inbox_threads['new_threads']) as $thread_id) {
if ($inbox_threads['new_threads'][$thread_id]->access('view', $this->currentUser)) {
if ($inbox_threads['new_threads'][$thread_id]->access('view', $this->currentUser())) {
$renderable = $view_builder->view($inbox_threads['new_threads'][$thread_id], 'inbox');
$rendered_threads[$thread_id] = $this->renderer->renderRoot($renderable);
}
......@@ -324,12 +255,12 @@ class AjaxController extends ControllerBase implements AjaxControllerInterface {
protected function loadThread(AjaxResponse $response) {
$thread_id = $this->requestStack->getCurrentRequest()->get('id');
if ($thread_id) {
$thread = $this->entityTypeManager->getStorage('private_message_thread')->load($thread_id);
$thread = $this->entityTypeManager()->getStorage('private_message_thread')->load($thread_id);
if ($thread && $thread->access('view', $this->currentUser)) {
if ($thread && $thread->access('view', $this->currentUser())) {
$this->privateMessageService->updateLastCheckTime();
$view_builder = $this->entityTypeManager->getViewBuilder('private_message_thread');
$view_builder = $this->entityTypeManager()->getViewBuilder('private_message_thread');
$renderable = $view_builder->view($thread);
$rendered_thread = $this->renderer->renderRoot($renderable);
......
......@@ -2,103 +2,22 @@
namespace Drupal\private_message\Controller;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormBuilderInterface;
use Drupal\Core\Link;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\Url;
use Drupal\private_message\Form\BanUserForm;
use Drupal\private_message\Service\PrivateMessageServiceInterface;
use Drupal\user\UserDataInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Private message page controller. Returns render arrays for the page.
*/
class PrivateMessageController extends ControllerBase implements PrivateMessageControllerInterface {
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected $currentUser;
/**
* The entity manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The form builder interface.
*
* @var \Drupal\Core\Form\FormBuilderInterface
*/
protected $formBuilder;
/**
* The user data service.
*
* @var \Drupal\user\UserDataInterface
*/
protected $userData;
/**
* The private message service.
*
* @var \Drupal\private_message\Service\PrivateMessageServiceInterface
*/
protected $privateMessageService;
/**
* The configuration factory service.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected $config;
/**
* Constructs a PrivateMessageForm object.
*
* @param \Drupal\Core\Session\AccountProxyInterface $currentUser
* The current user.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity manager service.
* @param \Drupal\Core\Form\FormBuilderInterface $formBuilder
* The form builder service.
* @param \Drupal\user\UserDataInterface $userData
* The user data service.
* @param \Drupal\private_message\Service\PrivateMessageServiceInterface $privateMessageService
* The private message service.
* @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
* The config factory service.
*/
public function __construct(AccountProxyInterface $currentUser, EntityTypeManagerInterface $entityTypeManager, FormBuilderInterface $formBuilder, UserDataInterface $userData, PrivateMessageServiceInterface $privateMessageService, ConfigFactoryInterface $configFactory) {
$this->currentUser = $currentUser;
$this->entityTypeManager = $entityTypeManager;
$this->formBuilder = $formBuilder;
$this->userData = $userData;
$this->privateMessageService = $privateMessageService;
$this->config = $configFactory->get('private_message.settings');
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('current_user'),
$container->get('entity_type.manager'),
$container->get('form_builder'),
$container->get('user.data'),
$container->get('private_message.service'),
$container->get('config.factory')
);
}
public function __construct(
protected readonly UserDataInterface $userData,
protected readonly PrivateMessageServiceInterface $privateMessageService,
) {}
/**
* {@inheritdoc}
......@@ -107,14 +26,14 @@ class PrivateMessageController extends ControllerBase implements PrivateMessageC
$this->privateMessageService->updateLastCheckTime();
/** @var \Drupal\user\UserInterface $user */
$user = $this->entityTypeManager
$user = $this->entityTypeManager()
->getStorage('user')
->load($this->currentUser->id());
->load($this->currentUser()->id());
$private_message_thread = $this->privateMessageService->getFirstThreadForUser($user);
if ($private_message_thread) {
$view_builder = $this->entityTypeManager->getViewBuilder('private_message_thread');
$view_builder = $this->entityTypeManager()->getViewBuilder('private_message_thread');
// No wrapper is provided, as the full view mode of the entity already
// provides the #private-message-page wrapper.
$page = $view_builder->view($private_message_thread);
......@@ -161,7 +80,7 @@ class PrivateMessageController extends ControllerBase implements PrivateMessageC
return [
'#prefix' => '<div id="private_message_configuration_page">',
'#suffix' => '</div>',
'form' => $this->formBuilder->getForm('Drupal\private_message\Form\ConfigForm'),
'form' => $this->formBuilder()->getForm('Drupal\private_message\Form\ConfigForm'),
];
}
......@@ -190,8 +109,8 @@ class PrivateMessageController extends ControllerBase implements PrivateMessageC
* {@inheritdoc}
*/
public function banUnbanPage(): array {
$user_has_permission = $this->currentUser->hasPermission('use private messaging system')
&& $this->currentUser->hasPermission('access user profiles');
$user_has_permission = $this->currentUser()->hasPermission('use private messaging system')
&& $this->currentUser()->hasPermission('access user profiles');
$table = [];
......@@ -200,13 +119,13 @@ class PrivateMessageController extends ControllerBase implements PrivateMessageC
$header = [t('User'), t('Operations')];
/** @var \Drupal\private_message\Entity\PrivateMessageBan[] $private_message_bans */
$private_message_bans = $this->entityTypeManager
$private_message_bans = $this->entityTypeManager()
->getStorage('private_message_ban')
->loadByProperties(['owner' => $this->currentUser->id()]);
->loadByProperties(['owner' => $this->currentUser()->id()]);
$destination = Url::fromRoute('<current>')->getInternalPath();
foreach ($private_message_bans as $private_message_ban) {
$label = $this->config->get('unban_label');
$label = $this->config('private_message.settings')->get('unban_label');
$url = Url::fromRoute('private_message.unban_user_form',
['user' => $private_message_ban->getTargetId()],
['query' => ['destination' => $destination]],
......@@ -230,7 +149,7 @@ class PrivateMessageController extends ControllerBase implements PrivateMessageC
'content' => [
$table,
[
'form' => $this->formBuilder->getForm(BanUserForm::class),
'form' => $this->formBuilder()->getForm(BanUserForm::class),
],
],
];
......
......@@ -2,7 +2,7 @@
namespace Drupal\private_message\Drush\Commands;
use Drupal\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\DependencyInjection\AutowireTrait;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\private_message\Service\PrivateMessageUninstallerInterface;
use Drush\Attributes as CLI;
......@@ -13,6 +13,7 @@ use Drush\Commands\DrushCommands;
*/
final class PrivateMessageCommands extends DrushCommands {
use AutowireTrait;
use StringTranslationTrait;
public function __construct(
......@@ -21,15 +22,6 @@ final class PrivateMessageCommands extends DrushCommands {
parent::__construct();
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container): self {
return new static(
$container->get('private_message.uninstaller')
);
}
/**
* Prepares the Private Message module for uninstallation.
*/
......
......@@ -2,82 +2,23 @@
namespace Drupal\private_message\Form;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\DependencyInjection\AutowireTrait;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\private_message\Service\PrivateMessageBanManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Private Message users banning form.
*/
class BanUserForm extends FormBase {
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected AccountProxyInterface $currentUser;
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected EntityTypeManagerInterface $entityTypeManager;
use AutowireTrait;
/**
* The private message configuration.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The Private Message Ban manager.
*
* @var \Drupal\private_message\Service\PrivateMessageBanManagerInterface
*/
private PrivateMessageBanManagerInterface $privateMessageBanManager;
/**
* Constructs a BanUserForm object.
*
* @param \Drupal\Core\Session\AccountProxyInterface $currentUser
* The current user.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager service.
* @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
* The configuration factory service.
* @param \Drupal\private_message\Service\PrivateMessageBanManagerInterface $privateMessageBanManager
* The Private Message Ban manager.
*/
public function __construct(
AccountProxyInterface $currentUser,
EntityTypeManagerInterface $entityTypeManager,
ConfigFactoryInterface $configFactory,
PrivateMessageBanManagerInterface $privateMessageBanManager,
) {
$this->currentUser = $currentUser;
$this->entityTypeManager = $entityTypeManager;
$this->configFactory = $configFactory;
$this->privateMessageBanManager = $privateMessageBanManager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container): self {
return new static(
$container->get('current_user'),
$container->get('entity_type.manager'),
$container->get('config.factory'),
$container->get('private_message.ban_manager'),
);
}
protected readonly EntityTypeManagerInterface $entityTypeManager,
protected readonly PrivateMessageBanManagerInterface $privateMessageBanManager,
) {}
/**
* {@inheritdoc}
......@@ -90,7 +31,7 @@ class BanUserForm extends FormBase {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state): array {
$config = $this->configFactory->get('private_message.settings');
$config = $this->config('private_message.settings');
$form['banned_user'] = [
'#title' => $this->t('Select User'),
......@@ -118,7 +59,7 @@ class BanUserForm extends FormBase {
public function validateForm(array &$form, FormStateInterface $form_state): void {
$userId = $form_state->getValue('banned_user');
// Add security to prevent blocking ourselves.
if ($userId === $this->currentUser->id()) {
if ($userId === $this->currentUser()->id()) {
$form_state->setErrorByName($userId, $this->t("You can't block yourself."));
}
......
......@@ -4,49 +4,47 @@ namespace Drupal\private_message\Form;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\DependencyInjection\AutowireTrait;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\private_message\PluginManager\PrivateMessageConfigFormManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\private_message\Model\BlockType;
use Drupal\private_message\PluginManager\PrivateMessageConfigFormManagerInterface;
/**
* Defines the configuration form for the private message module.
*/
class ConfigForm extends ConfigFormBase {
use AutowireTrait;
/**
* Ban types.
* Blocking type: passive.
*
* @deprecated in private_message:4.0.0 and is removed from
* private_message:5.0.0. Use \Drupal\private_message\Model\BlockType::Passive
* instead.
*
* @todo Move to Enum.
* @see https://www.drupal.org/project/private_message/issues/3490037
*/
const PASSIVE = 'passive';
const ACTIVE = 'active';
/**
* The private message config form plugin manager.
* Blocking type: active.
*
* @var \Drupal\private_message\PluginManager\PrivateMessageConfigFormManager
* @deprecated in private_message:4.0.0 and is removed from
* private_message:5.0.0. Use \Drupal\private_message\Model\BlockType::Active
* instead.
*
* @see https://www.drupal.org/project/private_message/issues/3490037
*/
protected $privateMessageConfigFormManager;
const ACTIVE = 'active';
public function __construct(
ConfigFactoryInterface $configFactory,
TypedConfigManagerInterface $typedConfigManager,
PrivateMessageConfigFormManager $privateMessageConfigFormManager,
protected readonly PrivateMessageConfigFormManagerInterface $privateMessageConfigFormManager,
) {
parent::__construct($configFactory, $typedConfigManager);
$this->privateMessageConfigFormManager = $privateMessageConfigFormManager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
$container->get('config.typed'),
$container->get('private_message.private_message_config_form_manager')
);
}
/**
......@@ -185,17 +183,12 @@ class ConfigForm extends ConfigFormBase {
$form['pm_block']['ban_mode'] = [
'#type' => 'radios',
'#title' => $this->t("Blocking mode"),
'#default_value' => $config->get('ban_mode') ?: self::PASSIVE,
'#options' => [
self::PASSIVE => $this
->t('Passive'),
self::ACTIVE => $this
->t('Active'),
],
self::PASSIVE => [
'#default_value' => $config->get('ban_mode') ?: BlockType::Passive->value,
'#options' => BlockType::asOptions(),
BlockType::Passive->value => [
'#description' => $this->t('Blocked members do not know they are blocked and can message the user that blocked them. The user who blocked them will not see the message.'),
],
self::ACTIVE => [
BlockType::Active->value => [
'#description' => $this->t('Blocked members cannot message users that blocked them and instead a message is shown.'),
],
];
......
......@@ -2,78 +2,33 @@
namespace Drupal\private_message\Form;
use Drupal\Core\DependencyInjection\AutowireTrait;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\Url;
use Drupal\private_message\Model\BlockType;
use Drupal\private_message\Service\PrivateMessageBanManagerInterface;
use Drupal\user\UserInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* The User Ban confirmation form.
*/
class ConfirmBanUserForm extends ConfirmFormBase {
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected AccountProxyInterface $currentUser;
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected EntityTypeManagerInterface $entityTypeManager;
/**
* The Private Message Ban manager.
*
* @var \Drupal\private_message\Service\PrivateMessageBanManagerInterface
*/
protected PrivateMessageBanManagerInterface $privateMessageBanManager;
use AutowireTrait;
/**
* The user to block.
*
* @var \Drupal\user\UserInterface|null
*/
protected ?UserInterface $user;
/**
* Constructs a ConfirmBanUserForm object.
*
* @param \Drupal\Core\Session\AccountProxyInterface $currentUser
* The current user.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager service.
* @param \Drupal\private_message\Service\PrivateMessageBanManagerInterface $privateMessageBanManager
* The Private Message Ban manager.
*/
public function __construct(
AccountProxyInterface $currentUser,
EntityTypeManagerInterface $entityTypeManager,
PrivateMessageBanManagerInterface $privateMessageBanManager,
) {
$this->currentUser = $currentUser;
$this->entityTypeManager = $entityTypeManager;
$this->privateMessageBanManager = $privateMessageBanManager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('current_user'),
$container->get('entity_type.manager'),
$container->get('private_message.ban_manager'),
);
}
protected readonly AccountProxyInterface $currentUser,
protected readonly EntityTypeManagerInterface $entityTypeManager,
protected readonly PrivateMessageBanManagerInterface $privateMessageBanManager,
) {}
/**
* {@inheritdoc}
......@@ -145,7 +100,7 @@ class ConfirmBanUserForm extends ConfirmFormBase {
public function getDescription() {
$config = $this->config('private_message.settings');
if ($config->get('ban_mode') == ConfigForm::PASSIVE) {
if ($config->get('ban_mode') === BlockType::Passive->value) {
return $this->t('By confirming, you will no longer be able to send messages to this user.');
}
else {
......
......@@ -2,6 +2,7 @@
namespace Drupal\private_message\Form;
use Drupal\Core\DependencyInjection\AutowireTrait;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
......@@ -9,71 +10,24 @@ use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\Url;
use Drupal\private_message\Service\PrivateMessageBanManagerInterface;
use Drupal\user\UserInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* User unban confirmation form.
*/
class ConfirmUnbanUserForm extends ConfirmFormBase {
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected AccountProxyInterface $currentUser;
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected EntityTypeManagerInterface $entityTypeManager;
/**
* The Private Message Ban manager.
*
* @var \Drupal\private_message\Service\PrivateMessageBanManagerInterface
*/
private PrivateMessageBanManagerInterface $privateMessageBanManager;
use AutowireTrait;
/**
* The user to unban.
*
* @var \Drupal\user\UserInterface|null
*/
private ?UserInterface $user;
/**
* Constructs a BlockUserForm object.
*
* @param \Drupal\Core\Session\AccountProxyInterface $currentUser
* The current user.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager service.
* @param \Drupal\private_message\Service\PrivateMessageBanManagerInterface $privateMessageBanManager
* The Private Message Ban manager.
*/
public function __construct(
AccountProxyInterface $currentUser,
EntityTypeManagerInterface $entityTypeManager,
PrivateMessageBanManagerInterface $privateMessageBanManager,
) {
$this->currentUser = $currentUser;
$this->entityTypeManager = $entityTypeManager;
$this->privateMessageBanManager = $privateMessageBanManager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('current_user'),
$container->get('entity_type.manager'),
$container->get('private_message.ban_manager'),
);
}
protected readonly AccountProxyInterface $currentUser,
protected readonly EntityTypeManagerInterface $entityTypeManager,
protected readonly PrivateMessageBanManagerInterface $privateMessageBanManager,
) {}
/**
* {@inheritdoc}
......
......@@ -7,36 +7,37 @@ use Drupal\Component\Utility\Html;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\ReplaceCommand;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\ImmutableConfig;
use Drupal\Core\DependencyInjection\AutowireTrait;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem;
use Drupal\Core\Form\FormBuilderInterface;
use Drupal\Core\Form\FormState;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element\StatusMessages;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\TypedData\TypedDataManagerInterface;
use Drupal\private_message\Ajax\PrivateMessageInboxTriggerUpdateCommand;
use Drupal\private_message\Ajax\PrivateMessageLoadNewMessagesCommand;
use Drupal\private_message\Entity\PrivateMessage;
use Drupal\private_message\Entity\PrivateMessageThread;
use Drupal\private_message\Entity\PrivateMessageThreadInterface;
use Drupal\private_message\Model\BlockType;
use Drupal\private_message\Service\PrivateMessageBanManagerInterface;
use Drupal\private_message\Service\PrivateMessageServiceInterface;
use Drupal\private_message\Service\PrivateMessageThreadManagerInterface;
use Drupal\user\UserDataInterface;
use Drupal\private_message\Traits\PrivateMessageSettingsTrait;
use Drupal\user\UserInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Defines the private message form.
*/
class PrivateMessageForm extends ContentEntityForm {
use AutowireTrait;
use PrivateMessageSettingsTrait;
/**
* A unique instance identifier for the form.
*
......@@ -44,141 +45,19 @@ class PrivateMessageForm extends ContentEntityForm {
*/
protected $formId;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected $currentUser;
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The typed data manager service.
*
* @var \Drupal\Core\TypedData\TypedDataManagerInterface
*/
protected $typedDataManager;
/**
* The user data service.
*
* @var \Drupal\user\UserDataInterface
*/
protected $userData;
/**
* The private message service.
*
* @var \Drupal\private_message\Service\PrivateMessageServiceInterface
*/
protected $privateMessageService;
/**
* The private message thread manager service.
*
* @var \Drupal\private_message\Service\PrivateMessageThreadManagerInterface
*/
protected $privateMessageThreadManager;
/**
* The Private Message Ban manager.
*
* @var \Drupal\private_message\Service\PrivateMessageBanManagerInterface
*/
protected PrivateMessageBanManagerInterface $privateMessageBanManager;
/**
* The Form Builder service.
*
* @var \Drupal\Core\Form\FormBuilderInterface
*/
protected $formBuilder;
/**
* The message configuration.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected ImmutableConfig $config;
/**
* Constructs a PrivateMessageForm object.
*
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entityRepository
* The entity repository service.
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
* The entity type bundle service.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time service.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager service.
* @param \Drupal\Core\Session\AccountProxyInterface $currentUser
* The current user.
* @param \Drupal\Core\TypedData\TypedDataManagerInterface $typedDataManager
* The typed data manager service.
* @param \Drupal\user\UserDataInterface $userData
* The user data service.
* @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
* The configuration factory service.
* @param \Drupal\private_message\Service\PrivateMessageServiceInterface $privateMessageService
* The private message service.
* @param \Drupal\private_message\Service\PrivateMessageThreadManagerInterface $privateMessageThreadManager
* The private message thread manager service.
* @param \Drupal\private_message\Service\PrivateMessageBanManagerInterface $privateMessageBanManager
* The Private Message Ban manager.
* @param \Drupal\Core\Form\FormBuilderInterface $formBuilder
* The Form Builder service.
*/
public function __construct(
EntityRepositoryInterface $entityRepository,
EntityTypeBundleInfoInterface $entity_type_bundle_info,
TimeInterface $time,
EntityTypeManagerInterface $entityTypeManager,
AccountProxyInterface $currentUser,
TypedDataManagerInterface $typedDataManager,
UserDataInterface $userData,
ConfigFactoryInterface $configFactory,
PrivateMessageServiceInterface $privateMessageService,
PrivateMessageThreadManagerInterface $privateMessageThreadManager,
PrivateMessageBanManagerInterface $privateMessageBanManager,
FormBuilderInterface $formBuilder,
protected readonly TypedDataManagerInterface $typedDataManager,
protected readonly PrivateMessageServiceInterface $privateMessageService,
protected readonly PrivateMessageThreadManagerInterface $privateMessageThreadManager,
protected readonly PrivateMessageBanManagerInterface $privateMessageBanManager,
protected readonly FormBuilderInterface $formBuilder,
) {
parent::__construct($entityRepository, $entity_type_bundle_info, $time);
$this->entityTypeManager = $entityTypeManager;
$this->currentUser = $currentUser;
$this->typedDataManager = $typedDataManager;
$this->userData = $userData;
$this->config = $configFactory->get('private_message.settings');
$this->privateMessageService = $privateMessageService;
$this->privateMessageThreadManager = $privateMessageThreadManager;
$this->privateMessageBanManager = $privateMessageBanManager;
$this->formBuilder = $formBuilder;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.repository'),
$container->get('entity_type.bundle.info'),
$container->get('datetime.time'),
$container->get('entity_type.manager'),
$container->get('current_user'),
$container->get('typed_data_manager'),
$container->get('user.data'),
$container->get('config.factory'),
$container->get('private_message.service'),
$container->get('private_message.thread_manager'),
$container->get('private_message.ban_manager'),
$container->get('form_builder'),
);
$this->configFactory = $configFactory;
}
/**
......@@ -215,15 +94,15 @@ class PrivateMessageForm extends ContentEntityForm {
if ($privateMessageThread) {
$threadMembers = $privateMessageThread->getMembersId();
$bannedUsers = $this->privateMessageBanManager->getBannedUsers($this->currentUser->id());
$bannedUsers = $this->privateMessageBanManager->getBannedUsers($this->currentUser()->id());
$banned = FALSE;
foreach ($bannedUsers as $bannedUser) {
if (\in_array($bannedUser, $threadMembers)) {
if (!empty($this->config->get('ban_message'))) {
if (!empty($this->getSettings()->get('ban_message'))) {
$this->messenger()
->addError($this->config->get('ban_message'));
->addError($this->getSettings()->get('ban_message'));
$form['message_for_user'] = [
StatusMessages::renderMessages(),
......@@ -239,16 +118,16 @@ class PrivateMessageForm extends ContentEntityForm {
// Block messaging form for active blocking mode.
if (!$banned) {
$ban_mode = $this->config->get('ban_mode');
if ($ban_mode === ConfigForm::ACTIVE) {
$ban_mode = $this->getSettings()->get('ban_mode');
if ($ban_mode === BlockType::Active) {
foreach ($threadMembers as $threadMember) {
$bannedUsers = $this->privateMessageBanManager->getBannedUsers($threadMember);
if (in_array($this->currentUser->id(), $bannedUsers)) {
if (in_array($this->currentUser()->id(), $bannedUsers)) {
if (!empty($this->config->get('ban_message'))) {
if (!empty($this->getSettings()->get('ban_message'))) {
$this->messenger()
->addError($this->config->get('ban_message'));
->addError($this->getSettings()->get('ban_message'));
$form['message_for_user'] = [
StatusMessages::renderMessages(),
......@@ -272,8 +151,8 @@ class PrivateMessageForm extends ContentEntityForm {
// Only to do these when using #ajax.
$form['#attached']['library'][] = 'private_message/message_form';
$form['#attached']['drupalSettings']['privateMessageSendKey'] = $this->config->get('keys_send');
$autofocus_enabled = $this->config->get('autofocus_enable');
$form['#attached']['drupalSettings']['privateMessageSendKey'] = $this->getSettings()->get('keys_send');
$autofocus_enabled = $this->getSettings()->get('autofocus_enable');
if ($autofocus_enabled) {
$form['message']['widget'][0]['#attributes']['autofocus'] = 'autofocus';
}
......@@ -311,7 +190,7 @@ class PrivateMessageForm extends ContentEntityForm {
$form['#validate'][] = '::validateBannedMembers';
if ($save_label = $this->config->get('save_message_label')) {
if ($save_label = $this->getSettings()->get('save_message_label')) {
$form['actions']['submit']['#value'] = $save_label;
}
......@@ -367,7 +246,7 @@ class PrivateMessageForm extends ContentEntityForm {
}
}
if ((count($members) === 1 && $this->currentUser->id() === $members[0]->id())) {
if ((count($members) === 1 && $this->currentUser()->id() === $members[0]->id())) {
$formState->setError($form['members'], $this->t('You can not send a message to yourself only.'));
}
......@@ -398,7 +277,7 @@ class PrivateMessageForm extends ContentEntityForm {
/** @var \Drupal\private_message\Entity\PrivateMessageThread|null $privateMessageThread */
$privateMessageThread = $formState->get('thread');
$threadMembers = $privateMessageThread ? $privateMessageThread->getMembersId() : [];
$bannedUsers = $this->privateMessageBanManager->getBannedUsers($this->currentUser->id());
$bannedUsers = $this->privateMessageBanManager->getBannedUsers($this->currentUser()->id());
foreach ($bannedUsers as $bannedUser) {
if (in_array($bannedUser, $threadMembers)) {
......@@ -486,7 +365,7 @@ class PrivateMessageForm extends ContentEntityForm {
// Generate an array containing the members of the thread.
$current_user = $this->entityTypeManager
->getStorage('user')
->load($this->currentUser->id());
->load($this->currentUser()->id());
$members = [$current_user];
......
......@@ -13,32 +13,10 @@ use Drupal\user\UserInterface;
*/
class PrivateMessageMapper implements PrivateMessageMapperInterface {
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected Connection $database;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected AccountProxyInterface $currentUser;
/**
* Constructs a PrivateMessageMapper object.
*
* @param \Drupal\Core\Database\Connection $database
* The database connection.
* @param \Drupal\Core\Session\AccountProxyInterface $currentUser
* The current user.
*/
public function __construct(Connection $database, AccountProxyInterface $currentUser) {
$this->database = $database;
$this->currentUser = $currentUser;
}
public function __construct(
protected readonly Connection $database,
protected readonly AccountProxyInterface $currentUser,
) {}
/**
* {@inheritdoc}
......
<?php
declare(strict_types=1);
namespace Drupal\private_message\Model;
/**
* Blocking type.
*/
enum BlockType: string {
case Passive = 'passive';
case Active = 'active';
/**
* Returns the enum as options.
*
* @return array
* Options.
*/
public static function asOptions(): array {
return [
self::Passive->value => t('Passive'),
self::Active->value => t('Active'),
];
}
}
<?php
declare(strict_types=1);
namespace Drupal\private_message\PluginManager;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\private_message\Annotation\PrivateMessageConfigForm;
use Drupal\private_message\Plugin\PrivateMessageConfigForm\PrivateMessageConfigFormPluginInterface;
/**
* Plugin Manager to detect PrivateMessageConfigForm plugins.
* Plugin manager for detect PrivateMessageConfigForm plugins.
*/
class PrivateMessageConfigFormManager extends DefaultPluginManager implements PrivateMessageConfigFormManagerInterface {
/**
* Constructs a PrivateMessageConfigFormManager object.
*
* @param \Traversable $namespaces
* Namespaces to be searched for the plugin.
* @param \Drupal\Core\Cache\CacheBackendInterface $cacheBackend
* The cache backend.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
* The module handler service.
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cacheBackend, ModuleHandlerInterface $moduleHandler) {
parent::__construct('Plugin/PrivateMessageConfigForm', $namespaces, $moduleHandler, 'Drupal\private_message\Plugin\PrivateMessageConfigForm\PrivateMessageConfigFormPluginInterface', 'Drupal\private_message\Annotation\PrivateMessageConfigForm');
parent::__construct('Plugin/PrivateMessageConfigForm', $namespaces, $moduleHandler, PrivateMessageConfigFormPluginInterface::class, PrivateMessageConfigForm::class);
$this->alterInfo('private_message_config_form_info');
$this->setCacheBackend($cacheBackend, 'private_message_config_form');
}
......
......@@ -4,7 +4,6 @@ namespace Drupal\private_message\Service;
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\private_message\Entity\PrivateMessageBanInterface;
......@@ -16,57 +15,11 @@ class PrivateMessageBanManager implements PrivateMessageBanManagerInterface {
use StringTranslationTrait;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected AccountProxyInterface $currentUser;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The database.
*
* @var \Drupal\Core\Database\Connection
*/
private Connection $database;
/**
* The messenger service.
*
* @var \Drupal\Core\Messenger\MessengerInterface
*/
private MessengerInterface $messenger;
/**
* Constructs a PrivateMessageBanManager object.
*
* @param \Drupal\Core\Session\AccountProxyInterface $currentUser
* The current user.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager interface.
* @param \Drupal\Core\Database\Connection $database
* The database.
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The messenger service.
*/
public function __construct(
AccountProxyInterface $currentUser,
EntityTypeManagerInterface $entityTypeManager,
Connection $database,
MessengerInterface $messenger,
) {
$this->currentUser = $currentUser;
$this->entityTypeManager = $entityTypeManager;
$this->database = $database;
$this->messenger = $messenger;
}
protected readonly AccountProxyInterface $currentUser,
protected readonly EntityTypeManagerInterface $entityTypeManager,
protected readonly Connection $database,
) {}
/**
* {@inheritdoc}
......