user_registrationpassword.install in User registration password 8
Same filename and directory in other branches
Install file.
File
user_registrationpassword.installView source
<?php
/**
* @file
* Install file.
*/
use Drupal\user\UserInterface;
use Drupal\user_registrationpassword\UserRegistrationPassword;
/**
* Implements hook_install().
*/
function user_registrationpassword_install() {
// Set the correct default configuration settings so the module needs no more
// configuration.
//
// Load configurations.
$user_config = \Drupal::configFactory()
->getEditable('user.settings');
$user_mail_config = \Drupal::configFactory()
->getEditable('user.mail');
$mail_original_config = \Drupal::configFactory()
->getEditable('user_registrationpassword.mail_original');
$user_config
->set('register', UserInterface::REGISTER_VISITORS)
->set('verify_mail', 0)
->set('notify.register_pending_approval', 0)
->set('notify.register_no_approval_required', 0)
->save();
// Save the original activation email template to a variable, so we can revive
// them when we uninstall the module.
$mail_original_config
->set('status_activated.subject', $user_mail_config
->get('status_activated.subject'))
->set('status_activated.body', $user_mail_config
->get('status_activated.body'))
->save();
// Set basic email template variable for the account activation email so it
// makes sense.
$user_mail_config
->set('status_activated.subject', 'Account details for [user:display-name] at [site:name]')
->set('status_activated.body', '[user:display-name],
Your account at [site:name] has been activated.
You will be able to log in to [site:login-url] in the future using:
username: [user:name]
password: your password.
-- [site:name] team')
->save();
}
/**
* Implements hook_uninstall().
*/
function user_registrationpassword_uninstall() {
// Load configurations.
$user_config = \Drupal::configFactory()
->getEditable('user.settings');
$user_mail_config = \Drupal::configFactory()
->getEditable('user.mail');
$mail_original_config = \Drupal::configFactory()
->getEditable('user_registrationpassword.mail_original');
// Reset system variables back to save defauls.
$user_config
->set('register', UserInterface::REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)
->set('verify_mail', 1)
->set('notify.register_pending_approval', 1)
->set('notify.register_no_approval_required', 1)
->save();
// Load original stored activation mail variables.
$original_subject = $mail_original_config
->get('status_activated.subject');
$original_body = $mail_original_config
->get('status_activated.body');
// Reset the stored activation mail template if available.
if (!empty($original_subject) && !empty($original_subject)) {
$user_mail_config
->set('status_activated.subject', $original_subject)
->set('status_activated.body', $original_body)
->save();
}
}
/**
* Set new notify to enable.
*/
function user_registrationpassword_update_8201() {
$config = \Drupal::configFactory()
->getEditable('user_registrationpassword.settings');
$config
->set('notify.register_confirmation_with_pass', 1)
->save();
}
Functions
Name | Description |
---|---|
user_registrationpassword_install | Implements hook_install(). |
user_registrationpassword_uninstall | Implements hook_uninstall(). |
user_registrationpassword_update_8201 | Set new notify to enable. |