You are here

function htmlmail_form_user_form_alter in HTML Mail 8

Same name and namespace in other branches
  1. 8.3 htmlmail.module \htmlmail_form_user_form_alter()

Implements hook_form_FORM_ID_alter().

File

./htmlmail.module, line 65
Default file for HTML Mail module.

Code

function htmlmail_form_user_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  if (!HtmlMailHelper::allowUserAccess()) {
    return;
  }
  $account_data_plaintext = \Drupal::service('user.data')
    ->get(HtmlMailHelper::HTMLMAIL_MODULE_NAME, $form_state
    ->getFormObject()
    ->getEntity()
    ->id(), 'htmlmail_plaintext');
  $form['account']['mail'] = [
    'mail' => $form['account']['mail'],
    'htmlmail_plaintext' => [
      '#type' => 'checkbox',
      '#title' => t('Plaintext-only emails'),
      '#default_value' => empty($account_data_plaintext) ? 0 : 1,
      '#description' => t('The %htmlmail module can send emails with fonts, styles, and other HTML formatting.  If you prefer to receive all your emails in unformatted plain text, select this option.', [
        '%htmlmail' => 'HTML Mail',
      ]),
    ],
  ];
  $form['actions']['submit']['#submit'][] = 'htmlmail_user_form_submit';
}