function ContactFormHooks::formUserAdminSettingsAlter

Implements hook_form_FORM_ID_alter() for \Drupal\user\AccountSettingsForm.

Adds the default personal contact setting on the user settings page.

Attributes

#[Hook('form_user_admin_settings_alter')]

File

core/modules/contact/src/Hook/ContactFormHooks.php, line 58

Class

ContactFormHooks
Form hook implementations for Contact module.

Namespace

Drupal\contact\Hook

Code

public function formUserAdminSettingsAlter(&$form, FormStateInterface $form_state) : void {
  $form['contact'] = [
    '#type' => 'details',
    '#title' => $this->t('Contact settings'),
    '#open' => TRUE,
    '#weight' => 0,
  ];
  $form['contact']['contact_default_status'] = [
    '#type' => 'checkbox',
    '#title' => $this->t('Enable the personal contact form by default for new users'),
    '#description' => $this->t('Changing this setting will not affect existing users.'),
    '#default_value' => $this->configFactory
      ->getEditable('contact.settings')
      ->get('user_default_enabled'),
  ];
  // Add submit handler to save contact configuration.
  $form['#submit'][] = 'contact_form_user_admin_settings_submit';
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.