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 "create" 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
:
* "form" = {
* "add" = "Drupal\flag\Form\FlaggingForm",
* "edit" = "Drupal\flag\Form\FlaggingForm",
* "delete" = "Drupal\flag\Form\UnflagConfirmForm"
However, when I tried to do a hook_form_alter()
with:
function MYMODULE_form_flagging_FLAGGINGTYPE_add_form_alter(&$form, FormStateInterface $form_state, $form_id)
function MYMODULE_form_flagging_add_form_alter(&$form, FormStateInterface $form_state, $form_id)
I could not get either to pick up my code (I rebuilt the cache).
hook_form_alter()
for some reason. (Question edited)