public function CompletionRegister::validatePaneForm in Commerce Core 8.2
Validates the 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::validatePaneForm
File
- modules/
checkout/ src/ Plugin/ Commerce/ CheckoutPane/ CompletionRegister.php, line 211
Class
- CompletionRegister
- Provides the registration after checkout pane.
Namespace
Drupal\commerce_checkout\Plugin\Commerce\CheckoutPaneCode
public function validatePaneForm(array &$pane_form, FormStateInterface $form_state, array &$complete_form) {
// Validate the entity. This will ensure that the username and email are in
// the right format and not already taken.
$values = $form_state
->getValue($pane_form['#parents']);
$account = $this->userStorage
->create([
'mail' => $this->order
->getEmail(),
'name' => $values['name'],
'pass' => $values['pass'],
'status' => TRUE,
]);
/** @var \Drupal\user\UserInterface $account */
$form_display = EntityFormDisplay::collectRenderDisplay($account, 'register');
$form_display
->extractFormValues($account, $pane_form, $form_state);
$form_display
->validateFormValues($account, $pane_form, $form_state);
// Manually flag violations of fields not handled by the form display. This
// is necessary as entity form displays only flag violations for fields
// contained in the display.
// @see \Drupal\user\AccountForm::flagViolations
$violations = $account
->validate();
foreach ($violations
->getByFields([
'name',
'pass',
]) as $violation) {
list($field_name) = explode('.', $violation
->getPropertyPath(), 2);
$form_state
->setError($pane_form[$field_name], $violation
->getMessage());
}
}