public function RegisterForm::form in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/user/src/RegisterForm.php \Drupal\user\RegisterForm::form()
Gets the actual form array to be built.
Overrides AccountForm::form
See also
\Drupal\Core\Entity\EntityForm::processForm()
\Drupal\Core\Entity\EntityForm::afterBuild()
File
- core/
modules/ user/ src/ RegisterForm.php, line 30 - Contains \Drupal\user\RegisterForm.
Class
- RegisterForm
- Form controller for the user register forms.
Namespace
Drupal\userCode
public function form(array $form, FormStateInterface $form_state) {
$user = $this
->currentUser();
/** @var \Drupal\user\UserInterface $account */
$account = $this->entity;
$admin = $user
->hasPermission('administer users');
// Pass access information to the submit handler. Running an access check
// inside the submit function interferes with form processing and breaks
// hook_form_alter().
$form['administer_users'] = array(
'#type' => 'value',
'#value' => $admin,
);
$form['#attached']['library'][] = 'core/drupal.form';
// For non-admin users, populate the form fields using data from the
// browser.
if (!$admin) {
$form['#attributes']['data-user-info-from-browser'] = TRUE;
}
// Because the user status has security implications, users are blocked by
// default when created programmatically and need to be actively activated
// if needed. When administrators create users from the user interface,
// however, we assume that they should be created as activated by default.
if ($admin) {
$account
->activate();
}
// Start with the default user account fields.
$form = parent::form($form, $form_state, $account);
return $form;
}