function ContactHooks::formUserAdminSettingsAlter

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

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

File

core/modules/contact/src/Hook/ContactHooks.php, line 204

Class

ContactHooks
Hook implementations for contact.

Namespace

Drupal\contact\Hook

Code

public function formUserAdminSettingsAlter(&$form, FormStateInterface $form_state) : void {
    $form['contact'] = [
        '#type' => 'details',
        '#title' => t('Contact settings'),
        '#open' => TRUE,
        '#weight' => 0,
    ];
    $form['contact']['contact_default_status'] = [
        '#type' => 'checkbox',
        '#title' => t('Enable the personal contact form by default for new users'),
        '#description' => t('Changing this setting will not affect existing users.'),
        '#default_value' => \Drupal::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.