function ContactFormHooks::formUserAdminSettingsAlter
Same name and namespace in other branches
- 11.x core/modules/contact/src/Hook/ContactFormHooks.php \Drupal\contact\Hook\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 73
Class
- ContactFormHooks
- Form hook implementations for Contact module.
Namespace
Drupal\contact\HookCode
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. Note that, in this
// case, it's not possible to simply use the #config_target key. The reason
// is that, with #config_target, the entire contact.settings object gets
// validated. But values, other than `user_default_enabled` might not pass
// the validation, and there's nothing the user can do, as such values are
// not exposed by this form alter. A typical case can be observed when
// installing the Contact module. The default configuration shipped with the
// module sets contact.settings:default_form value to 'feedback' but the
// module doesn't ship any contact form config entity with this ID, hence
// the config validation will fail.
$form['#submit'][] = self::class . ':userAdminSettingsSubmit';
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.