Jun 19, 2014

Function drupal_goto() has been removed


Function drupal_goto() is gone and must be replaced with the use of something else.

For example, in  AddUpdateForm::submitForm(), which is a method implemented in a class derived from FormBase, I changed
drupal_goto('admin/config/system/optimizely');
to
$form_state['redirect_route']['route_name'] =
  'optimizely.listing';
where optimizely.listing is a route defined in the routing file and $form_state is a parameter passed in by reference.

The source article below suggests the use of  RedirectResponse() instead of  drupal_goto(). However, I haven't been able to figure out how to use it in submitForm(), and I've yet to find examples that are at my level of understanding.

Finally, here's a quote from a relevant comment made by Crell, a.k.a. Larry Garfield:
"For instance, if you're using the common controller base class there is a $this->redirect($route_name) method ready for you; ... "
That looks very straightforward, but the required context is being in an instance of the common controller base class.

Update:  redirection can no longer be done as above. See the note on method setRedirect() in this newer post  http://optimizely-to-drupal-8.blogspot.com/2014/08/drupal-8-alpha-13-alpha-14.html#setredirect

Source:

drupal_goto() has been removed
https://drupal.org/node/2023537

1 comment:

  1. https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Form!FormBuilder.php/function/FormBuilder%3A%3AredirectForm/8

    > "Redirects the user to a URL after a form has been processed."

    ReplyDelete