How do I redirect on flag save programmatically? I want to redirect users to a view when they flag a taxonomy term.
This question is about how to use Rules to redirect on flag save.  I want to do this programmatically.
I tried to use hook_form_alter() to add a submit handler with the redirect.  Unfortunately, while flaggings have an edit form that can be targeted by hook_form_alter() (MYMODULE_form_flagging_FLAGTYPE_edit_form_alter()), they do not seem to have a &quot;create&quot; form.
So how can I add a redirect programmatically upon flagging?
EDIT
Based on 4k4's comment I looked at /flag/srs/Entity/Flagging.php:
 *    &quot;form&quot; = {
 *      &quot;add&quot; = &quot;Drupal\flag\Form\FlaggingForm&quot;,
 *      &quot;edit&quot; = &quot;Drupal\flag\Form\FlaggingForm&quot;,
 *      &quot;delete&quot; = &quot;Drupal\flag\Form\UnflagConfirmForm&quot;

However, when I tried to do a hook_form_alter() with:

function MYMODULE_form_flagging_FLAGGINGTYPE_add_form_alter(&amp;$form, FormStateInterface $form_state, $form_id)
function MYMODULE_form_flagging_add_form_alter(&amp;$form, FormStateInterface $form_state, $form_id)

I could not get either to pick up my code (I rebuilt the cache).
This can be done in hook_entity_presave().
function MYMODULE_flagging_presave(FlaggingInterface $flagging) {
  switch ($flagging-&gt;getFlagId()) {
    case 'FLAGTYPE':
      $redirect_url = Url::fromRoute('view.VIEW_MACHINE_NAME.VIEW_DISPLAY_ID')-&gt;toString();
      $response = new RedirectResponse($redirect_url);
      $response-&gt;send();
     break;
   }
 }