0

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);
    $values=$form_state->getValues();

some code here...

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

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

    $form_state->setRedirect('view.services.page_2');
  }

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
0

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 acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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