Implements hook_form_FORM_ID_alter().
Add the enable personal contact form to an individual user's account page.
user_profile_form()
function contact_form_user_profile_form_alter(&$form, &$form_state) {
$form['contact'] = array(
'#type' => 'details',
'#title' => t('Contact settings'),
'#weight' => 5,
'#collapsible' => TRUE,
);
$account = $form_state['controller']
->getEntity($form_state);
$account_data = drupal_container()
->get('user.data')
->get('contact', $account
->id(), 'enabled');
$form['contact']['contact'] = array(
'#type' => 'checkbox',
'#title' => t('Personal contact form'),
'#default_value' => isset($account_data) ? $account_data : config('contact.settings')
->get('user_default_enabled'),
'#description' => t('Allow other users to contact you via a personal contact form which keeps your e-mail address hidden. Note that some privileged users such as site administrators are still able to contact you even if you choose to disable this feature.'),
);
}