CheckoutReviewForm.php in Ubercart 8.4
File
uc_cart/src/Form/CheckoutReviewForm.php
View source
<?php
namespace Drupal\uc_cart\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
class CheckoutReviewForm extends FormBase {
protected $session;
public function __construct(SessionInterface $session) {
$this->session = $session;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('session'));
}
public function getFormId() {
return 'uc_cart_checkout_review_form';
}
public function buildForm(array $form, FormStateInterface $form_state, $order = NULL) {
if (!$form_state
->has('uc_order')) {
$form_state
->set('uc_order', $order);
}
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['back'] = [
'#type' => 'submit',
'#value' => $this
->t('Back'),
'#validate' => [
'::skipValidation',
],
'#submit' => [
[
$this,
'back',
],
],
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Submit order'),
'#button_type' => 'primary',
];
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$order = $form_state
->get('uc_order');
$this->session
->remove('uc_checkout_review_' . $order
->id());
$this->session
->set('uc_checkout_complete_' . $order
->id(), TRUE);
$form_state
->setRedirect('uc_cart.checkout_complete');
}
public function skipValidation(array &$form, FormStateInterface $form_state) {
}
public function back(array &$form, FormStateInterface $form_state) {
$form_state
->setRedirect('uc_cart.checkout');
}
}
Classes
Name |
Description |
CheckoutReviewForm |
Gives customers the option to finish checkout or revise their information. |