Error occurs after adding the private message link to the user display

Created on 25 January 2025, 3 days ago

Problem/Motivation

The error occurs after enabling the "private message link" extra field on the user display configuration and opening the user page:

TypeError: Drupal\private_message\Service\PrivateMessageService::Drupal\private_message\Service\{closure}(): Argument #1 ($user) must be of type Drupal\user\UserInterface, Drupal\Core\Session\AccountProxy given in Drupal\private_message\Service\PrivateMessageService->Drupal\private_message\Service\{closure}() (line 397 of modules/contrib/private_message/src/Service/PrivateMessageService.php).

This happens because $this->currentUser of type AccountProxy is passed to the ::getThreadIdForMembers call and it expects the UserInterface.

Steps to reproduce

Go to the /admin/config/people/accounts/display and enable the "Private message thread link" field.
Create a user, grant the "use private messages" permission and open the profile of the user.
You'll face the above error.

Proposed resolution

Load the entity before passing it to the $members array.

Remaining tasks

Review the patch and test it.

User interface changes

None.

API changes

None.

Data model changes

None.

πŸ› Bug report
Status

Active

Version

4.0

Component

Code

Created by

πŸ‡ΊπŸ‡¦Ukraine artem_sylchuk Lutsk

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024