commerce icon indicating copy to clipboard operation
commerce copied to clipboard

Split validation into multiple methods to simplify login and registration form customizations

Open Berdir opened this issue 8 years ago • 0 comments

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.

Berdir avatar Apr 18 '17 16:04 Berdir