public function EmptyCartButton::viewsFormSubmit in Commerce Core 8.2
Submits 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/ area/ EmptyCartButton.php, line 129
Class
- EmptyCartButton
- Defines an area handler for the "Empty cart" button.
Namespace
Drupal\commerce_cart\Plugin\views\areaCode
public function viewsFormSubmit(array &$form, FormStateInterface $form_state) {
$triggering_element = $form_state
->getTriggeringElement();
if (!empty($triggering_element['#empty_cart_button'])) {
$order_storage = $this->entityTypeManager
->getStorage('commerce_order');
/** @var \Drupal\commerce_order\Entity\OrderInterface $cart */
$cart = $order_storage
->load($this->view->argument['order_id']
->getValue());
$this->cartManager
->emptyCart($cart);
$this->messenger
->addMessage($this
->t('Your shopping cart has been emptied.'));
}
}