8 – How to customize a link with a custom module?

I installed the module "Private message" in Drupal 8.

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

How to customize a link in Drupal 8?

Here is the HTML code of the link:


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 ?

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

The developer of the module wrote in a comment:

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

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

I have created a custom module:

private_message_contact_button.module :

<? php

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

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

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

The code works, but the button does not apply.

I want to add class btn btn-success

And I want to add an icon that looks impressive in front of the text.

Do I have to put what code?