public function CompletionRegister::submitPaneForm in Commerce Core 8.2
Handles the submission of an pane form.
Parameters
array $pane_form: The pane form.
\Drupal\Core\Form\FormStateInterface $form_state: The form state of the parent form.
array $complete_form: The complete form structure.
Overrides CheckoutPaneBase::submitPaneForm
File
- modules/
checkout/ src/ Plugin/ Commerce/ CheckoutPane/ CompletionRegister.php, line 241
Class
- CompletionRegister
- Provides the registration after checkout pane.
Namespace
Drupal\commerce_checkout\Plugin\Commerce\CheckoutPaneCode
public function submitPaneForm(array &$pane_form, FormStateInterface $form_state, array &$complete_form) {
$values = $form_state
->getValue($pane_form['#parents']);
$account = $this->userStorage
->create([
'pass' => $values['pass'],
'mail' => $this->order
->getEmail(),
'name' => $values['name'],
'status' => TRUE,
]);
/** @var \Drupal\user\UserInterface $account */
$form_display = EntityFormDisplay::collectRenderDisplay($account, 'register');
$form_display
->extractFormValues($account, $pane_form, $form_state);
$account
->save();
user_login_finalize($account);
$this->credentialsCheckFlood
->clearAccount($this->clientIp, $account
->getAccountName());
$this->orderAssignment
->assign($this->order, $account);
// Notify other modules.
$event = new CheckoutCompletionRegisterEvent($account, $this->order);
$this->eventDispatcher
->dispatch(CheckoutEvents::COMPLETION_REGISTER, $event);
// Event subscribers are allowed to set a redirect url, to send the
// customer to their orders page, for example.
if ($url = $event
->getRedirectUrl()) {
$form_state
->setRedirectUrl($url);
}
$this
->messenger()
->addStatus($this
->t('Registration successful. You are now logged in.'));
}