Score:0

Ajax message after node save

cn flag

I am trying to add a Ajax Alert or popup message inside a hook_node_presave or hook_node_update, but it is not working.

My current code look like this, but I have tried a lot of other ajax

$response = new ajaxResponse();
$response->addCommand(new AlertCommand('Ajax test'));
return $response;

The node is saved but no alert and no errors in the console. Drupal 9

Kevin avatar
in flag
Those hooks dont return responses. https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21entity.api.php/function/hook_ENTITY_TYPE_presave/9.2.x
Tommy Styrbæk avatar
cn flag
No I understand that now. I do have a RedirectResponse that works fine when I not saving with Ajax.
Tommy Styrbæk avatar
cn flag
Any suggestion to how I can solve this issue? I have struggled with this for 3 days now. Everything works fine when savning from a form. Then I get at message on the page. But when saving with Ajax I want at alert or someting to popup.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.