public function RemoveButton::viewsForm in Commerce Core 8.2
Form constructor for the views form.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
File
- modules/
cart/ src/ Plugin/ views/ field/ RemoveButton.php, line 80
Class
- RemoveButton
- Defines a form element for removing the order item.
Namespace
Drupal\commerce_cart\Plugin\views\fieldCode
public function viewsForm(array &$form, FormStateInterface $form_state) {
// Make sure we do not accidentally cache this form.
$form['#cache']['max-age'] = 0;
// The view is empty, abort.
if (empty($this->view->result)) {
unset($form['actions']);
return;
}
$form[$this->options['id']]['#tree'] = TRUE;
foreach ($this->view->result as $row_index => $row) {
$order_item = $this
->getEntity($row);
if ($order_item
->isLocked()) {
continue;
}
$form[$this->options['id']][$row_index] = [
'#type' => 'submit',
'#value' => $this
->t('Remove'),
'#name' => 'delete-order-item-' . $row_index,
'#remove_order_item' => TRUE,
'#row_index' => $row_index,
'#attributes' => [
'class' => [
'delete-order-item',
],
],
];
}
}