I have a view for a Drupal 8 site that uses 'work' as its path. I want to redirect user to this path right after the node has been submitted.
Form alter seems to be the right solution as it was in Drupal 7, but it's more complicated then it was before. In Drupal 7 we just used a direct path and redirect took place; now we need to provide a route name which isn't that obvious anymore. How do we find proper route name value? It's different for nodes, views, custom paths etc.
What I should use as argument for $form_state->setRedirect('')
? How do I find what route name I should use in different cases?
function work_form_alter(&$form, \Drupal\Core\Form\FormStateInterface\FormStateInterface $form_state, $form_id) {
switch ($form_id) {
case 'node_work_form':
$form['actions']['submit']['#submit'][] = 'work_redirect';
break;
}
}
function work_redirect($form, FormStateInterface $form_state) {
// Set redirect to some path.
$form_state->setRedirect(''); // What should I provide here as an argument/arguments
}