Personal contact form button if available How can I add a button to the user twig template that links to their personal contact form, but only shows if that user has the form available, and the person viewing the page has permissions to use it?
This was the solution I came up with:

/**
 * Implements hook_preprocess_user().
 */
function MYTHEME_preprocess_user(&amp;$variables)
{
    $account = $variables['elements']['#user'];
    if ($account-&gt;getEmail() != '') {
        $contactUrl = Url::fromRoute('entity.user.contact_form', ['user' =&gt; $account-&gt;id()]);
        if ($contactUrl-&gt;access()) {
            $contactLink = Link::fromTextAndUrl('Contact', $contactUrl);
            $variables['contact_btn'] = $contactLink-&gt;toRenderable();
            $variables['contact_btn']['#attributes'] = array('class' =&gt; array('btn', 'btn-primary', 'btn-contact-user'));
        }
    }
}