You are here

function private_message_form_user_admin_settings_alter in Private Message 8

Implements hook_form_FORM_ID_alter().

Adds private message emails to the configuration form so that administrators can modify the email as necessary.

See also

hook_form_alter()

\Drupal\user\ProfileForm

File

./private_message.module, line 397
Contains hooks for the private message module.

Code

function private_message_form_user_admin_settings_alter(array &$form, FormStateInterface $form_state) {
  $config = \Drupal::config('private_message.settings');
  $mail_config = \Drupal::config('private_message.mail');

  // Only add the email to the form if private message email notifications
  // have been enabled.
  if ($config
    ->get('enable_email_notifications')) {

    // List the available tokens.
    $private_message_token_help = t('Available variables are: [site:name], [site:url], [user:display-name], [user:account-name], [user:mail], [site:login-url], [site:url-brief], [user:edit-url], [user:one-time-login-url], [user:cancel-url], [private_message:id], [private_message:author-name], [private_message:message], [private_message:url], [private_message:created], [private_message_thread:id], [private_message_thread:], [private_message_thread:url], [private_message_thread:updated].');
    $form['email_private_message'] = [
      '#type' => 'details',
      '#title' => t('Private message notification'),
      '#description' => t('Edit the notification mail sent to users when they receive a private message') . $private_message_token_help,
      '#group' => 'email',
      '#tree' => TRUE,
    ];
    $form['email_private_message']['settings'] = [
      '#type' => 'container',
    ];
    $form['email_private_message']['settings']['user_mail_private_message_notification_subject'] = [
      '#type' => 'textfield',
      '#title' => t('Subject'),
      '#default_value' => $mail_config
        ->get('message_notification.subject'),
      '#maxlength' => 180,
    ];
    $form['email_private_message']['settings']['user_mail_private_message_notification_body'] = [
      '#type' => 'textarea',
      '#title' => t('Body'),
      '#rows' => 17,
      '#default_value' => $mail_config
        ->get('message_notification.body'),
    ];
    $form['#submit'][] = 'private_message_user_admin_settings_submit';
  }
}