Overrides Drupal\Core\Entity\EntityFormController::form().
Overrides AccountFormController::form
public function form(array $form, array &$form_state, EntityInterface $account) {
global $user;
$admin = user_access('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,
);
// If we aren't admin but already logged on, go to the user page instead.
if (!$admin && $user->uid) {
drupal_goto('user/' . $user->uid);
}
$form['#attached']['library'][] = array(
'system',
'jquery.cookie',
);
$form['#attributes']['class'][] = 'user-info-from-cookie';
// Start with the default user account fields.
$form = parent::form($form, $form_state, $account);
// Attach field widgets, and hide the ones where the 'user_register_form'
// setting is not on.
field_attach_form('user', $account, $form, $form_state);
foreach (field_info_instances('user', 'user') as $field_name => $instance) {
if (empty($instance['settings']['user_register_form'])) {
$form[$field_name]['#access'] = FALSE;
}
}
if ($admin) {
// Redirect back to page which initiated the create request; usually
// admin/people/create.
$form_state['redirect'] = current_path();
}
return $form;
}