In drupal 8 for page redirection, we have to use Symfony components class. Here page redirection is done by 'RedirectResponse' class from Symfony HttpFoundation. In drupal 7 we using drupal_goto() function for redirect.
But in case of drupal 8, RedirectResponse' class is..
use Symfony\Component\HttpFoundation\RedirectResponse;
and suppose redirection page is node 2691 so we will give redirect url is '/node/2691'.
Example:
$url = '/node/2691';
return new RedirectResponse($url);
OR
$redirect_variable = new Symfony\Component\HttpFoundation\RedirectResponse('/node/2691'); $redirect_variable ->send();
return;
For front page redirection, we can use..
return new \Symfony\Component\HttpFoundation\RedirectResponse(\Drupal::url('<front>'));
OR
In Function we can use redirect..
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_state->setRedirect('redirect router name');
Example:
$form_state->setRedirect('account_login.content');
}
Note: If have any suggestions or issue regarding 'Page Redirection programmatically in drupal 8' then you can ask by comments.
But in case of drupal 8, RedirectResponse' class is..
use Symfony\Component\HttpFoundation\RedirectResponse;
and suppose redirection page is node 2691 so we will give redirect url is '/node/2691'.
Example:
$url = '/node/2691';
return new RedirectResponse($url);
OR
$redirect_variable = new Symfony\Component\HttpFoundation\RedirectResponse('/node/2691'); $redirect_variable ->send();
return;
For front page redirection, we can use..
return new \Symfony\Component\HttpFoundation\RedirectResponse(\Drupal::url('<front>'));
OR
In Function we can use redirect..
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_state->setRedirect('redirect router name');
Example:
$form_state->setRedirect('account_login.content');
}
Note: If have any suggestions or issue regarding 'Page Redirection programmatically in drupal 8' then you can ask by comments.
No comments:
Post a Comment