public function WishlistViewForm::submitForm in UC Wish List 8
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormInterface::submitForm
File
- src/
Form/ WishlistViewForm.php, line 273
Class
Namespace
Drupal\uc_wishlist\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
// Get the products post data and iterate them to update one by one.
$items = $values['items'];
foreach ($items as $item) {
$wpid = $item['wpid'];
$remove = $item['remove'];
$node = Node::load($item['nid']);
$title = $node
->get('title')
->getValue()[0]['value'];
$title = Xss::filter($title);
// Check to see if the user wanted to remove this product from the wish list and if so then delete it.
if ($remove) {
drupal_set_message($this
->t('<b>@product_title</b> has been removed from <a href="@url">your wish list</a>.', [
'@product_title' => $title,
'@url' => Url::fromRoute('uc_wishlist.wishlist'),
]));
}
else {
// Update the information for this product in the wish list
// user wanted quantity of the product.
$wanted_qty = $item['wanted_qty'];
$this->ucwishlistManager
->updateWantedQuantity($wpid, $wanted_qty);
}
}
drupal_set_message($this
->t('Your wish list has been updated'));
$form_state
->setRedirectUrl(Url::fromRoute('uc_wishlist.wishlist'));
}