Untitled
unknown
plain_text
2 years ago
1.1 kB
11
Indexable
/**
* Implements hook_form_alter().
*/
function your_module_name_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
// Check if the form is the user registration form.
if ($form_id == 'user_register_form') {
// Add a custom submit handler.
$form['#submit'][] = 'your_module_name_custom_submit_handler';
}
}
/**
* Custom submit handler to auto-approve Gmail.com registrations.
*/
function your_module_name_custom_submit_handler(&$form, \Drupal\Core\Form\FormStateInterface $form_state) {
// Get the email address submitted by the user.
$email = $form_state->getValue('mail');
// Check if the email address belongs to Gmail.com.
if (strpos($email, '@gmail.com') !== false) {
// Approve the user registration.
// You can use the following code to approve the user programmatically.
$user = $form_state->getFormObject()->getEntity();
$user->activate();
$user->save();
// Optionally, you can display a message to the user indicating approval.
drupal_set_message(t('Your registration has been automatically approved.'));
}
}Editor is loading...