Panel Response from hook

I am running a hook to send an email when a page has been updated

'page.update:after' => function ($newPage, $oldPage) {
   if($afewconditions){
              $mail = new PHPMailer(true);
                $mail->CharSet = 'UTF-8';
               // ...........
                try {
                  //... send E-mail
                    $mail->send();
                 // here when the email is successful there should be a panel popup
                // saying "email successfully sent" or something
                } catch (Exception $e) {
                    // E-Mail was no send, throw error 
                }
   }
}

are there methods to throw some methods to get the response popup as confirmation in the panel?

Confirmations are not possible so far. You can only throw exceptions in case that something went wrong.

I think the biggest problems with confirmations is that it would be really difficult to prioritize them when multiple actions are registered for the same hook. Let’s say you have two actions on the page.update:after hook and both want to throw a confirmation. How would that be dealt with?

1 Like

In my example i am running only one action

which would be

  • if field A and field B has content
  • send E-mail

I could throw an error saying everything has worked (in this case) which wouldn’t be nice.
otherwise i could CC the e-mail to the logged-in user’s adress.

Both not the neatest ideas… But i am open for suggestions :wink:

That’s in fact difficult with hooks. I don’t have a good solution to this at the moment to be honest.

WordPress “solved” this issue using the (in)famous $priority argument to determine the order of execution. I personally think it’s a terrible solution. That said, I don’t really know if there’s an alternative to that. Maybe someone can come up with a clever alternative.

Thinking a bit more about it, we might need to separate this from hooks. The idea of hooks is to have numerous possible actions being executed mostly in the background. Maybe we need something like a definable page submission controller that can only be defined once per page type and can either react with a positive or negative response. I will keep on thinking about it :slight_smile: