public function PaymentReferenceElement::buildForm in Payment 8.2
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- modules/
payment_reference_test/ src/ PaymentReferenceElement.php, line 26
Class
- PaymentReferenceElement
- Provides a form for testing the payment_reference element.
Namespace
Drupal\payment_reference_testCode
public function buildForm(array $form, FormStateInterface $form_state) {
$key = 'payment_reference_element_prototype_payment';
if ($form_state
->has($key)) {
/** @var \Drupal\payment\Entity\PaymentInterface $prototype_payment */
$prototype_payment = $form_state
->get($key);
$payment_type = $prototype_payment
->getPaymentType();
}
else {
$entity_type_id = 'user';
$bundle = 'user';
$field_name = 'foobarbaz';
/** @var \Drupal\payment\Entity\PaymentInterface $prototype_payment */
$prototype_payment = Payment::create(array(
'bundle' => 'payment_reference',
));
$prototype_payment
->setCurrencyCode('EUR')
->setOwnerId(2)
->setLineItems(Generate::createPaymentLineItems());
/** @var \Drupal\payment_reference\Plugin\Payment\Type\PaymentReference $payment_type */
$payment_type = $prototype_payment
->getPaymentType();
$payment_type
->setEntityTypeId($entity_type_id);
$payment_type
->setBundle($bundle);
$payment_type
->setFieldName($field_name);
$form_state
->set($key, $prototype_payment);
}
$form['payment_reference'] = array(
'#plugin_selector_id' => 'payment_select_list',
'#prototype_payment' => $prototype_payment,
'#queue_category_id' => $payment_type
->getEntityTypeId() . '.' . $payment_type
->getBundle() . '.' . $payment_type
->getFieldName(),
'#queue_owner_id' => 2,
'#required' => TRUE,
'#title' => 'FooBarBaz',
'#type' => 'payment_reference',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}