8 – Editing the “Send private message” link to include the username

I prefer to edit (hack) the private message module directly in this case if you won’t mind helping me. https://www.drupal.org/project/private_message 8.x-2.0-beta16

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 hack this line directly to insert the username?

I tried without success.

The relevant code is located in: private_messagesrcServicePrivateMessageService.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>',
      );
    }
  }   
}