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.
Issue fork private_message-3502162
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
Comment #3
artem_sylchukComment #4
artem_sylchukI think it would be great to add a simple test that checks those links.
Comment #5
zenimagine commentedI confirm that the patch fixes in version 3.0.6
Comment #6
pearls commentedMR184 worked for me.
Comment #9
claudiu.cristeaThank you