diff --git a/modules/checkout/src/Event/AccountCreateEvent.php b/modules/checkout/src/Event/AccountCreateEvent.php new file mode 100644 index 0000000..13820f0 --- /dev/null +++ b/modules/checkout/src/Event/AccountCreateEvent.php @@ -0,0 +1,108 @@ +getFormState()->setRedirect('user.page'); + * @endcode + * + * @var \Drupal\Core\Form\FormStateInterface + */ + protected $formState; + + /** + * Constructs a new AccountCreateEvent object. + * + * @param \Drupal\Core\Session\AccountInterface + * The account created during checkout. + * @param \Drupal\commerce_order\Entity\OrderInterface + * The checkout order. + * @param array $form + * The form that the customer used to register. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The state of the form that the customer used to register. + */ + public function __construct(AccountInterface $account, OrderInterface $order, array $form, FormStateInterface $form_state) { + $this->account = $account; + $this->order = $order; + $this->form = $form; + $this->formState = $form_state; + } + + /** + * Gets the created account. + * + * @return \Drupal\Core\Session\AccountInterface + * The account created during checkout. + */ + public function getAccount() { + return $this->account; + } + + /** + * Gets the checkout order. + * + * @return \Drupal\commerce_order\Entity\OrderInterface + * The checkout order. + */ + public function getOrder() { + return $this->order; + } + + /** + * Returns the form that the customer used to register. + * + * @return array + * The form that the customer used to register. + */ + public function getForm() { + return $this->form; + } + + /** + * Returns the state of the form that the customer used to register. + * + * @return \Drupal\Core\Form\FormStateInterface + * The state of the form that the customer used to register. + */ + public function getFormState() { + return $this->formState; + } + +} diff --git a/modules/checkout/src/Event/CheckoutEvents.php b/modules/checkout/src/Event/CheckoutEvents.php new file mode 100644 index 0000000..dbf3ef6 --- /dev/null +++ b/modules/checkout/src/Event/CheckoutEvents.php @@ -0,0 +1,19 @@ +credentialsCheckFlood = $credentials_check_flood; @@ -88,6 +111,7 @@ class Registration extends CheckoutPaneBase implements CheckoutPaneInterface, Co $this->entityTypeManager = $entity_type_manager; $this->userAuth = $user_auth; $this->clientIp = $request_stack->getCurrentRequest()->getClientIp(); + $this->eventDispatcher = $event_dispatcher; } /** @@ -103,7 +127,8 @@ class Registration extends CheckoutPaneBase implements CheckoutPaneInterface, Co $container->get('current_user'), $container->get('entity_type.manager'), $container->get('user.auth'), - $container->get('request_stack') + $container->get('request_stack'), + $container->get('event_dispatcher') ); } @@ -218,6 +243,10 @@ class Registration extends CheckoutPaneBase implements CheckoutPaneInterface, Co $form_state->setRedirect('commerce_checkout.form', [ 'commerce_order' => $this->order->id(), ]); + + // Notify other modules about the account creation. + $event = new AccountCreateEvent($account, $this->order, $pane_form, $form_state); + $this->eventDispatcher->dispatch(CheckoutEvents::ACCOUNT_CREATE, $event); } }