I'm using the Private Message module version 8.x-2.0-beta16 and I want to change the message from 'Send private message'
to 'Send private message to @username'
which should display the username from the user's page that we are visiting and contacting.
The module uses the following code.
'#title' => t('Send private message'),
Is there are way to override this line directly and insert the username? I tried without success.
The relevant code is located in: private_message\src\Service\PrivateMessageService.php#L336-382.
public function createRenderablePrivateMessageThreadLink(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
if ($display->getComponent('private_message_link')) {
if ($entity instanceof UserInterface) {
$author = $entity;
}
else {
$author = $entity->getOwner();
}
$current_user = \Drupal::currentUser();
if ($current_user->isAuthenticated()) {
if ($current_user->hasPermission('use private messaging system') && $current_user->id() != $author->id()) {
$members = [$current_user, $author];
$thread_id = $this->mapper->getThreadIdForMembers($members);
if ($thread_id) {
$url = Url::fromRoute('entity.private_message_thread.canonical', ['private_message_thread' => $thread_id], ['attributes' => ['class' => ['private_message_link']]]);
$build['private_message_link'] = [
'#type' => 'link',
'#url' => $url,
'#title' => t('Send private message'),
'#prefix' => '<div class="private_message_link_wrapper">',
'#suffix' => '</div>',
];
}
else {
$url = Url::fromRoute('private_message.private_message_create', [], ['query' => ['recipient' => $author->id()]]);
$build['private_message_link'] = [
'#type' => 'link',
'#url' => $url,
'#title' => t('Send private message'),
'#prefix' => '<div class="private_message_link_wrapper">',
'#suffix' => '</div>',
];
}
}
}
else {
$url = Url::fromRoute('user.login');
$build['private_message_link'] = [
'#type' => 'link',
'#url' => $url,
'#title' => t('Send private message'),
'#prefix' => '<div class="private_message_link_wrapper">',
'#suffix' => '</div>',
];
}
}
}