Here is the code of a custom form:

  public function save(array $form, FormStateInterface $form_state) {
    $entity = $this->entity;
    $status = parent::save($form, $form_state);

some code here...

    switch ($status) {
      case SAVED_NEW:
        drupal_set_message($this->t('Le service « %label » a été ajouté.', [
          '%label' => $entity->label(),

        drupal_set_message($this->t('Le service « %label » a été modifié.', [
          '%label' => $entity->label(),


The redirection doesn't work!
After validating my form, it goes to the first page of my view.
By the way, these two pages of the view are displayed as two tabs in a menu (the first being the default one)...

  • When you say page, do you mean page display or a page on a page display, e.g page 3 or the result set? the view.services.page_2 route will take you to the page_2 page display of the services view. Are you saying this is not happening? It's taking you to the page_1 page display of the services view? – sonfd May 2 '18 at 16:33
  • You got it. It is exactly what happens. – gbmapo May 2 '18 at 20:18

The solution has two parts:
1. The button that takes to my form in 'Add' mode was coded this way: <a href="/sel/service/add?destination=services" class="form-submit">Ajouter</a> (/services being the first tab I mentioned).
So I removed the ?destination=services
2. Looking at the 'Routes info' provided by Devel, I got that: enter image description here
So i changed my code to $form_state->setRedirect('view.services.page_2', ['arg_0' => $iSeliste]); (thanks to the last comment of this page)

And now it works!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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