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.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

artem_sylchuk created an issue. See original summary.

artem_sylchuk’s picture

Status: Active » Needs review
artem_sylchuk’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

I think it would be great to add a simple test that checks those links.

zenimagine’s picture

I confirm that the patch fixes in version 3.0.6

pearls’s picture

Status: Needs work » Reviewed & tested by the community

MR184 worked for me.

claudiu.cristea made their first commit to this issue’s fork.

claudiu.cristea’s picture

Status: Reviewed & tested by the community » Fixed

Thank you

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.