public function AddLineItemForm::buildForm in Ubercart 8.4
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
- uc_order/
src/ Form/ AddLineItemForm.php, line 53
Class
- AddLineItemForm
- Form to add a line item to an order.
Namespace
Drupal\uc_order\FormCode
public function buildForm(array $form, FormStateInterface $form_state, OrderInterface $order = NULL, $line_item_id = '') {
$form['title'] = [
'#type' => 'textfield',
'#title' => $this
->t('Line item title'),
'#description' => $this
->t('Display title of the line item.'),
'#size' => 32,
'#maxlength' => 128,
'#default_value' => ${$this}->lineItemManager
->getDefinition($line_item_id)['title'],
];
$form['amount'] = [
'#type' => 'uc_price',
'#title' => $this
->t('Line item amount'),
'#allow_negative' => TRUE,
];
$form['order_id'] = [
'#type' => 'hidden',
'#value' => $order
->id(),
];
$form['line_item_id'] = [
'#type' => 'hidden',
'#value' => $line_item_id,
];
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Add line item'),
];
$form['actions']['cancel'] = [
'#type' => 'link',
'#title' => $this
->t('Cancel'),
'#url' => Url::fromRoute('entity.uc_order.edit_form', [
'uc_order' => $order
->id(),
]),
];
return $form;
}