You are here

function htmlmail_form_user_form_alter in HTML Mail 8.3

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

Implements hook_form_FORM_ID_alter().

File

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

Code

function htmlmail_form_user_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  if (!HtmlMailHelper::allowUserAccess()) {
    return;
  }
  $user_data_name = HtmlMailHelper::HTMLMAIL_USER_DATA_NAME;
  $account_data_plaintext = \Drupal::service('user.data')
    ->get(HtmlMailHelper::HTMLMAIL_MODULE_NAME, $form_state
    ->getFormObject()
    ->getEntity()
    ->id(), $user_data_name);
  $form['account']['mail'] = [
    'mail' => $form['account']['mail'],
    $user_data_name => [
      '#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';
}