class PaymentLineItemElement in Payment 8.2
Hierarchy
- class \Drupal\payment_test\PaymentLineItemElement implements ContainerInjectionInterface, FormInterface
Expanded class hierarchy of PaymentLineItemElement
1 string reference to 'PaymentLineItemElement'
- payment_test.routing.yml in modules/
payment_test/ payment_test.routing.yml - modules/payment_test/payment_test.routing.yml
File
- modules/
payment_test/ src/ PaymentLineItemElement.php, line 12
Namespace
Drupal\payment_testView source
class PaymentLineItemElement implements ContainerInjectionInterface, FormInterface {
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static();
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'payment_test_payment_line_item_element';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
// Nest the element to make sure that works.
$form['container']['line_item'] = array(
'#cardinality' => 4,
'#default_value' => Generate::createPaymentLineItems(),
'#type' => 'payment_line_items_input',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$line_items_data = [];
/** @var \Drupal\payment\Plugin\Payment\LineItem\PaymentLineItemInterface $line_item */
foreach (PaymentLineItemsInput::getLineItems($form['container']['line_item'], $form_state) as $line_item) {
$line_items_data[] = array(
'plugin_id' => $line_item
->getPluginId(),
'plugin_configuration' => $line_item
->getConfiguration(),
);
}
\Drupal::state()
->set('payment_test_line_item_form_element', $line_items_data);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PaymentLineItemElement:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
PaymentLineItemElement:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
PaymentLineItemElement:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
PaymentLineItemElement:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
PaymentLineItemElement:: |
public | function |
Form validation handler. Overrides FormInterface:: |