PaymentLineItemPaymentBasicFormElements.php in Payment 8.2
File
modules/payment_test/src/PaymentLineItemPaymentBasicFormElements.php
View source
<?php
namespace Drupal\payment_test;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Form\FormInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\payment\Payment;
use Symfony\Component\DependencyInjection\ContainerInterface;
class PaymentLineItemPaymentBasicFormElements implements ContainerInjectionInterface, FormInterface {
public static function create(ContainerInterface $container) {
return new static();
}
public function getFormId() {
return 'payment_test-payment-line_item-payment_basic';
}
public function buildForm(array $form, FormStateInterface $form_state) {
if ($form_state
->has('payment_line_item')) {
$line_item = $form_state
->get('payment_line_item');
}
else {
$line_item = Payment::lineItemManager()
->createInstance('payment_basic');
$form_state
->set('payment_line_item', $line_item);
}
$form['line_item'] = $line_item
->buildConfigurationForm([], $form_state);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
public function validateForm(array &$form, FormStateInterface $form_state) {
$line_item = $form_state
->get('payment_line_item');
$line_item
->validateConfigurationForm($form['line_item'], $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$line_item = $form_state
->get('payment_line_item');
$line_item
->submitConfigurationForm($form['line_item'], $form_state);
$form_state
->setRedirect('user.login');
}
}