How to customize a link with a custom module? I installed the "Private Message" module on Drupal 8.

There is a link to send a message that I want to transform into a Bootstrap button.

How to customize a link on Drupal 8 ?

Here is the HTML code of the link :

&lt;div class="private_message_link_wrapper"&gt;&lt;a href="/private_messages/9" class="private_message_link"&gt;Envoyer un message&lt;/a&gt;&lt;/div&gt;


The developer of "Private Message" gave me this code, but I do not know what to do with it.

I need to create a custom module or put it in my_theme.info.yml ?

function HOOK_node_view_alter(&amp;$build) {
  $build['private_message_link']['#title'] = t('Click me. Click me now!');
}


The developer of the module wrote in a comment :

You can implement hook_ENTITY_TYPE_view_alter(). For example, if you are altering the link on the user profile you would implement hook_user_view_alter(). If you are altering the link on nodes, you would implement hook_node_view_alter(). If you are altering the link on comments, you would implement hook_ENTITY_TYPE_view_alter().

In this function, you can change the output of the link by altering $build['private_message_link'] as you see fit.


I created a custom module:

private_message_contact_button.module :

&lt;?php

/**
 * @file
 * Hook implementations of private_message_contact_button module.
 */

use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;

function private_message_contact_button_node_view_alter(&amp;$build) {
  $build['private_message_link']['class'] = array('button button--primary', 'btn');
}


The code works, but the button is not applied.

I want to add class btn btn-success

And I want to add an icon make awesome in front of the text &lt;i class="fas fa-comment fa-lg"&gt;&lt;/i&gt;

I have to put what as code ?
The CSS class is a sub-key of the #attributes of a render array like $build:

function private_message_contact_button_node_view_alter(&amp;$build) {
  if (array_key_exists('private_message_link', $build)) {
    $build['private_message_link']['#attributes']['class'] = array('button button--primary', 'btn');
  }
}