public function MoveToWishlist::viewsForm in Commerce Wishlist 8.3
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
- src/
Plugin/ views/ field/ MoveToWishlist.php, line 137
Class
- MoveToWishlist
- Defines a form element for moving or copying the wishlist item to the cart.
Namespace
Drupal\commerce_wishlist\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) {
$form[$this->options['id']][$row_index] = [
'#type' => 'submit',
'#value' => $this->options['keep_item'] ? $this
->t('Copy to wishlist') : $this
->t('Move to wishlist'),
'#name' => 'move-cart-item-' . $row_index,
'#move_cart_item' => TRUE,
'#row_index' => $row_index,
'#attributes' => [
'class' => [
'move-cart-item',
],
],
];
}
}