How can I redirect users to a node in a form submission handler similarly to the following code?
In my form alter I have added an additional submit button:
$form['actions']['save_and_exit'] = array(
'#type' => 'submit',
'#value' => t('Save & Exit'),
'#submit' => array('custom_submit'),
);
function custom_submit(&$form, \Drupal\Core\Form\FormStateInterface
$form_state) {
$system_path = '/node/2';
$url = \Drupal::service('path.alias_manager')->getAliasByPath($system_path);
$form_state->setRedirect($url);
}
Then I'm getting following error:
Symfony\Component\Routing\Exception\RouteNotFoundException: Route "/mypage" does not exist. in Drupal\Core\Routing\RouteProvider->getRouteByName() (line 190 of C:\wamp\www\www_assure_local_com\core\lib\Drupal\Core\Routing\RouteProvider.php).
where /mypage
is the url alias of my /node/2
.