function commerce_wishlist_add_to_wishlist_form_ajax in Commerce Wishlist 8.3
Ajax callback for the add to wishlist form.
Parameters
array $form: The form.
\Drupal\Core\Form\FormStateInterface $form_state: The form state.
Return value
\Drupal\Core\Ajax\AjaxResponse The ajax response.
1 string reference to 'commerce_wishlist_add_to_wishlist_form_ajax'
- commerce_wishlist_form_commerce_order_item_add_to_cart_form_alter in ./
commerce_wishlist.module - Implements hook_form_BASE_FORM_ID_alter() for 'commerce_order_item_add_to_cart_form'.
File
- ./
commerce_wishlist.module, line 282 - Defines the Wishlist entity and associated features.
Code
function commerce_wishlist_add_to_wishlist_form_ajax(array $form, FormStateInterface $form_state) {
// Re-render the wishlist block. The plugin doesn't have configuration,
// so it can be used directly instead of loading the parent config entity.
$block_manager = \Drupal::service('plugin.manager.block');
/** @var \Drupal\Core\Block\BlockPluginInterface $wishlist_block */
$wishlist_block = $block_manager
->createInstance('commerce_wishlist', []);
$build = $wishlist_block
->build();
$response = new AjaxResponse();
$response
->addCommand(new ReplaceCommand('.wishlist-block', $build));
$response
->addCommand(new ReplaceCommand('[data-drupal-selector="' . $form['#attributes']['data-drupal-selector'] . '"]', $form));
$response
->addCommand(new PrependCommand('[data-drupal-selector="' . $form['#attributes']['data-drupal-selector'] . '"]', [
'#type' => 'status_messages',
]));
return $response;
}