public function CustomerInfoPane::view in Ubercart 8.4
Returns the contents of a checkout pane.
Parameters
\Drupal\uc_order\OrderInterface $order: The order that is being processed.
array $form: The checkout form array.
\Drupal\Core\Form\FormStateInterface $form_state: The checkout form state array.
Return value
array A form array, with an optional '#description' key to provide help text for the pane.
Overrides CheckoutPanePluginInterface::view
File
- uc_cart/
src/ Plugin/ Ubercart/ CheckoutPane/ CustomerInfoPane.php, line 26
Class
- CustomerInfoPane
- Gets the user's email address for login.
Namespace
Drupal\uc_cart\Plugin\Ubercart\CheckoutPaneCode
public function view(OrderInterface $order, array $form, FormStateInterface $form_state) {
$user = \Drupal::currentUser();
$cart_config = \Drupal::config('uc_cart.settings');
if ($user
->isAuthenticated()) {
$email = $user
->getEmail();
$contents['#description'] = $this
->t('Order information will be sent to your account e-mail listed below.');
$contents['primary_email'] = [
'#type' => 'hidden',
'#value' => $email,
];
$contents['email_text'] = [
'#markup' => '<div>' . $this
->t('<b>E-mail address:</b> @email (<a href=":url">edit</a>)', [
'@email' => $email,
':url' => Url::fromRoute('entity.user.edit_form', [
'user' => $user
->id(),
], [
'query' => $this
->getDestinationArray(),
])
->toString(),
]) . '</div>',
];
}
else {
$email = $order
->getEmail();
$contents['#description'] = $this
->t('Enter a valid email address for this order or <a href=":url">click here</a> to login with an existing account and return to checkout.', [
':url' => Url::fromRoute('user.login', [], [
'query' => $this
->getDestinationArray(),
])
->toString(),
]);
$contents['primary_email'] = [
'#type' => 'email',
'#title' => $this
->t('E-mail address'),
'#default_value' => $email,
'#required' => TRUE,
];
if ($cart_config
->get('email_validation')) {
$contents['primary_email_confirm'] = [
'#type' => 'email',
'#title' => $this
->t('Confirm e-mail address'),
'#default_value' => $email,
'#required' => TRUE,
];
}
$contents['new_account'] = [];
if ($cart_config
->get('new_account_name')) {
$contents['new_account']['name'] = [
'#type' => 'textfield',
'#title' => $this
->t('Username'),
'#default_value' => isset($order->data->new_user_name) ? $order->data->new_user_name : '',
'#maxlength' => 60,
'#size' => 32,
];
}
if ($cart_config
->get('new_account_password')) {
$contents['new_account']['pass'] = [
'#type' => 'password',
'#title' => $this
->t('Password'),
'#maxlength' => 32,
'#size' => 32,
];
$contents['new_account']['pass_confirm'] = [
'#type' => 'password',
'#title' => $this
->t('Confirm password'),
'#description' => $this
->t('Passwords must match to proceed.'),
'#maxlength' => 32,
'#size' => 32,
];
}
if (!empty($contents['new_account'])) {
$contents['new_account'] += [
'#type' => 'details',
'#title' => $this
->t('New account details'),
'#description' => $this
->t('<b>Optional.</b> New customers may supply custom account details.<br />We will create these for you if no values are entered.'),
'#open' => TRUE,
];
}
}
return $contents;
}