I have a Drupal 8 site with the Private Message module. I want to display a contact button instead of the contact link.
I created a custom module, it works. But I prefer to put the code in the theme rather than creating a new module.
<?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(&$build) {
if (array_key_exists('private_message_link', $build)) {
$build['private_message_link']['#attributes']['class'] = array('btn-success', 'btn-sm', 'btn');
$build['private_message_link']['#title'] = t('<i class="fas fa-comment-dots fa-lg"></i> Send a message');
}
}
function private_message_contact_button_user_view_alter(&$build) {
if (array_key_exists('private_message_link', $build)) {
$build['private_message_link']['#attributes']['class'] = array('btn-success', 'btn-sm', 'btn');
$build['private_message_link']['#title'] = t('<i class="fas fa-comment-dots fa-lg"></i> Send a message');
}
}
I uninstalled my custom module and copied the code below in my theme but it does not work.
How to use the code in the theme ?
bootstrap_subtheme_front_office_old.theme
:
/**
* Private Message button.
*/
function bootstrap_subtheme_front_office_old_node_view_alter(&$build) {
if (array_key_exists('private_message_link', $build)) {
$build['private_message_link']['#attributes']['class'] = array('btn-success', 'btn-sm', 'btn');
$build['private_message_link']['#title'] = t('<i class="fas fa-comment-dots fa-lg"></i> Send a message');
}
}
function bootstrap_subtheme_front_office_old_user_view_alter(&$build) {
if (array_key_exists('private_message_link', $build)) {
$build['private_message_link']['#attributes']['class'] = array('btn-success', 'btn-sm', 'btn');
$build['private_message_link']['#title'] = t('<i class="fas fa-comment-dots fa-lg"></i> Send a message');
}
}