Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ContactHooks.php

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';
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal