commerce
commerce copied to clipboard
Split validation into multiple methods to simplify login and registration form customizations
PR for https://www.drupal.org/node/2870783
In my project, I have this now, combined with an alter hook to switch out the class:
/**
* Customized Login pane that allows registration by e-mail.
*/
class EmailLoginPane extends Login {
/**
* {@inheritdoc}
*/
public function buildPaneForm(array $pane_form, FormStateInterface $form_state, array &$complete_form) {
$pane_form = parent::buildPaneForm($pane_form, $form_state, $complete_form);
$pane_form['returning_customer']['name']['#title'] = $this->t('E-mail or username');
$pane_form['register']['name']['#access'] = FALSE;
return $pane_form;
}
/**
* {@inheritdoc}
*/
protected function getAndValidateRegisterUserValues(array &$pane_form, FormStateInterface $form_state) {
if ($user_values = parent::getAndValidateRegisterUserValues($pane_form, $form_state)) {
$user_values['name'] = $user_values['mail'];
return $user_values;
}
}
}
Not sure yet about spliting up the login method further.