public function RemoveButton::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/ RemoveButton.php, line 80
Class
- RemoveButton
- Defines a form element for removing the wishlist item.
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' => t('Remove'),
'#name' => 'delete-wishlist-item-' . $row_index,
'#remove_wishlist_item' => TRUE,
'#row_index' => $row_index,
'#attributes' => [
'class' => [
'delete-wishlist-item',
],
],
];
}
}