public function LogintobogganProfileForm::form in LoginToboggan 8
Gets the actual form array to be built.
Overrides AccountForm::form
See also
\Drupal\Core\Entity\EntityForm::processForm()
\Drupal\Core\Entity\EntityForm::afterBuild()
File
- src/
Form/ LogintobogganProfileForm.php, line 24
Class
- LogintobogganProfileForm
- LogintobogganProfileForm.
Namespace
Drupal\logintoboggan\FormCode
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
// Add a revalidate link for users who are not yet in the trusted role.
$trusted_role = LogintobogganUtility::trustedRole();
$authenticated_role = UserInterface::AUTHENTICATED_ROLE;
// Provided these two roles are not the same, and the current user does not
// have the trusted role, can assume user has not yet validated so provide a
// revalidate link.
$user_account = $form['account'];
$user_name = $user_account['name']['#default_value'];
$account = user_load_by_name($user_name);
$roles = $account
->getRoles();
$got_trusted = in_array($trusted_role, $roles);
$currentuser = \Drupal::currentUser();
// If there's a trusted role, and it's not standard authenticated
// and user does not have that role.
if (isset($trusted_role) && $trusted_role != $authenticated_role && !$got_trusted) {
// Check the viewer of the page is either the account holder or admin.
if ($currentuser
->id() == $account
->id() || $currentuser
->hasPermission('administer users')) {
$url = Url::fromRoute('logintoboggan.user_revalidate', [
'user' => $account
->id(),
]);
$validate_link = Link::fromTextAndUrl($this
->t('re-send validation email'), $url)
->toString();
$form['revalidate'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Account validation'),
'#weight' => -20,
'#description' => $this
->t('Validate your email to get full access to the site'),
];
$form['revalidate']['revalidate_link'] = [
'#markup' => $validate_link,
];
$form['account']['roles']['#description'] = $this
->t("The user is not assigned LoginToboggan's trusted role, \n so is currently only receiving authenticated user permissions.");
$reg_type = \Drupal::config('user.settings')
->get('register');
if ($reg_type == 'visitors_admin_approval') {
$form['account']['status']['#description'] = $this
->t('If this user was created using immediate login, remember to add the %trusted role when activating', [
'%trusted' => $trusted_role,
]);
}
}
}
// Let user know the password length.
$min_pass_length = $this
->config('logintoboggan.settings')
->get('minimum_password_length');
if ($min_pass_length != '0') {
$description = $form['account']['pass']['#description'];
$original = $description
->render();
$pass_message = $original . $this
->t('<br>The minimum length for the password is %min characters.', [
'%min' => $min_pass_length,
]);
$form['account']['pass']['#description'] = $pass_message;
}
return $form;
}