Display alert notification in the panel

Hello,

I try to display an alert notification in the panel on the hook “panel.site.update”

So I have just started with this simple code in a plugin file:

kirby()->hook(['panel.site.update'], function( $site , $oldSite ) {
  panel()->alert("Error!!");
});

… but the alert didn’t appear when I change a panel options field value and save.
I’ve got the green smile instead.

If I replace

panel()->alert("Error!!");

by …

echo "Error!!";
die();

The hook catch my message.

notify() or alert() don’t work if you don’t redirect.

kirby()->hook(['panel.page.update'], function($page) {
  panel()->alert("Error!!");
  panel()->redirect($page);
});

Thanks. Works with the redirect now :slight_smile:

If I need to translate the alert message, may I have access to the l::get() value in the hook?

The language variables are not available in the config. but you could probably load them manually in a hook like in a route, as described here: AJAX Mail Translation problem

Is there a way to show an alert in the panel in Kirby3 ?

2 Likes

Hi @piaaaac,

I would like to know if you find a solution to show an alert in the panel? I didn’t find a good way to handle them.

Thanks.

That was ages ago… but no, I didn’t, I’m sorry

1 Like

@texnixe may I ask, how a Kirby 4 valid solution for notifying users in the panel looks like? Neither alert() nor notify() seem to exist anymore.

Thanks
Andreas

From a hook you can throw an exception, example: Throw new Exception() in hooks displays "Please fix all form errors…" message

Thank you @texnixe - that is a backup solution, but what I would really like to be able to do is some success/info/warning error notifications which pop up as is typical for dashboards.

Is that possible by onboard means?

Edit: I just found this: Theming and stacking for panel notifications · Kirby Feedback (getkirby.com) which comes very near what I am asking for but being triggered server-side.