Nicolas Posted November 19, 2020 Share Posted November 19, 2020 (edited) Hi, For a project I need to add a custom admin action button. Tanks to @bernhard i was able to add the action in the submit button dropdown. To peform the action i'm adding a hook to the InputfieldSubmit::processInput method, however the function is executed twice for some reasons i can't figure out. What am i doing wrong ? <?php // Add a save action button to resend the registration email $wire->addHookAfter('ProcessPageEdit::getSubmitActions', function(HookEvent $event) { $actions = $event->return; $actions['send_registration'] = [ 'value' => 'send_registration', 'icon' => 'check', 'label' => '%s + Resend registration email', ]; $event->return = $actions; }); // Process custom save button action wire()->addHookAfter('InputfieldSubmit::processInput', null, 'send_registration_email'); function send_registration_email($event) { $input = $event->arguments(0); if('send_registration' === $input->_after_submit_action) { // populate email vars here send_email($input->email, $mail_subject, $mail_body, wireMail()); } // Populate back return value, if you have modified it // $event->return = $attendee; $event->cancelHooks = true; }; function send_email($email, $mail_subject, $mail_body, $mailer) { // Sends the email } Edited November 19, 2020 by kongondo Wrapped code in code blocks <> Link to comment Share on other sites More sharing options...
Robin S Posted November 20, 2020 Share Posted November 20, 2020 On 11/19/2020 at 11:30 PM, Nicolas said: however the function is executed twice for some reasons i can't figure out Using Tracy Debugger to dump the name of the submit button can give you a clue... $wire->addHookAfter('InputfieldSubmit::processInput', function(HookEvent $event) { $inputfield = $event->object; bd($inputfield->name, "inputfield->name"); }); So there are two submit buttons in Page Edit that get processed: the Save button and the Trash button on the Delete tab. Rather than hooking InputfieldSubmit::processInput you can use the dedicated hookable method that performs the save actions: $wire->addHookAfter('ProcessPageEdit::processSubmitAction', function(HookEvent $event) { $value = $event->arguments(0); if($value === 'send_registration') { // Do your action here... } }); 2 Link to comment Share on other sites More sharing options...
Nicolas Posted November 20, 2020 Author Share Posted November 20, 2020 @Robin S Hi Robin. thanks for the clue about Tracy debugger and the right hook method. Solved my problem. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now