I'm working with a custom entity and would like to programmatically set the redirect based on submitted values.

When I set the redirect path however, the user is redirected to the canonical path instead of the path I'm setting in the redirect.

In the file mymodule/src/Form/MyEntityForm.php, I'm doing something like this:

  public function submitForm(array &$form, FormStateInterface $form_state)
    // Note: Same results with the order of the next 2 lines reversed.
    parent::submitForm($form, $form_state);
    $form_state->setRedirect('mymodule.overview', ['state' => 'CA']);

So how would I set the destination of an entity form submission dynamically?

1 Answer 1


Probably you need to override EntityFormInterface::save():

Form submission handler for the 'save' action.

Normally this method should be overridden to provide specific messages to the user and redirect the form after the entity has been saved.

submitForm() is the first submit handler called and should not be used to override submit actions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.