public function Products::buildForm in Ubercart 8.4
Form constructor.
Parameters
\Drupal\uc_order\OrderInterface $order: The order that is being viewed.
array $form: An 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 EditableOrderPanePluginInterface::buildForm
File
- uc_order/
src/ Plugin/ Ubercart/ OrderPane/ Products.php, line 126
Class
- Products
- Manage the products an order contains.
Namespace
Drupal\uc_order\Plugin\Ubercart\OrderPaneCode
public function buildForm(OrderInterface $order, array $form, FormStateInterface $form_state) {
$form['add_product_button'] = [
'#type' => 'submit',
'#value' => $this
->t('Add product'),
'#submit' => [
[
$this,
'productSelectSearch',
],
],
'#ajax' => [
'callback' => [
$this,
'ajaxCallback',
],
'wrapper' => 'product-controls',
],
];
$form['add_blank_line_button'] = [
'#type' => 'submit',
'#value' => $this
->t('Add blank line'),
'#submit' => [
[
$this,
'addBlank',
],
],
'#ajax' => [
'callback' => [
$this,
'ajaxCallback',
],
'wrapper' => 'product-controls',
],
];
$form['product_controls'] = [
'#tree' => TRUE,
'#prefix' => '<div id="product-controls">',
'#suffix' => '</div>',
];
$controls = [];
if ($form_state
->has('products_action')) {
switch ($form_state
->get('products_action')) {
case 'select':
$controls = $this
->productSelectForm($form['product_controls'], $form_state, $order);
break;
case 'add_product':
$controls = $this
->addProductForm($form['product_controls'], $form_state, $order, $form_state
->get('node'));
break;
}
}
$form['product_controls'] += $controls;
$form += $this
->editProductsForm($form, $form_state, $order->products);
return $form;
}