protected function Products::addProductForm in Ubercart 8.4
Sets the quantity and attributes of a product added to the order.
1 call to Products::addProductForm()
- Products::buildForm in uc_order/
src/ Plugin/ Ubercart/ OrderPane/ Products.php - Form constructor.
File
- uc_order/
src/ Plugin/ Ubercart/ OrderPane/ Products.php, line 283
Class
- Products
- Manage the products an order contains.
Namespace
Drupal\uc_order\Plugin\Ubercart\OrderPaneCode
protected function addProductForm($form, FormStateInterface $form_state, $order, $node) {
$data = [];
if ($form_state
->hasValue([
'product_controls',
'qty',
])) {
$data += \Drupal::moduleHandler()
->invokeAll('uc_add_to_cart_data', [
$form_state
->getValue('product_controls'),
]);
}
if (!empty($node->data) && is_array($node->data)) {
$data += $node->data;
}
$node = uc_product_load_variant(intval($form_state
->getValue([
'product_controls',
'nid',
])), $data);
$form['title'] = [
'#markup' => '<h3>' . $node
->label() . '</h3>',
];
$form['nid'] = [
'#type' => 'hidden',
'#value' => $node
->id(),
];
$form['qty'] = [
'#type' => 'uc_quantity',
'#title' => $this
->t('Quantity'),
'#default_value' => 1,
];
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Add to order'),
'#submit' => [
[
$this,
'addProductSubmit',
],
],
'#ajax' => [
'callback' => [
$this,
'ajaxCallback',
],
'wrapper' => 'product-controls',
],
];
$form['actions']['cancel'] = [
'#type' => 'submit',
'#value' => $this
->t('Cancel'),
'#submit' => [
[
$this,
'productSelectSearch',
],
],
'#ajax' => [
'callback' => [
$this,
'ajaxCallback',
],
'wrapper' => 'product-controls',
],
'#limit_validation_errors' => [],
];
$form['node'] = [
'#type' => 'value',
'#value' => $node,
];
uc_form_alter($form, $form_state, __FUNCTION__);
return $form;
}