I have a node type question that I want users to be able to create rapidly. So, after adding a question, I want them to be redirected to /node/add/question
to immediately do it again.
This is my code so far:
function MYMODULE_form_alter(&$form, FormStateInterface $form_state, $form_id) {
switch ($form_id) {
case 'node_question_form':
foreach (array_keys($form['actions']) as $action) {
if ($action != 'preview' && isset($form['actions'][$action]['#type']) && $form['actions'][$action]['#type'] === 'submit') {
$form['actions'][$action]['#submit'][] = 'MYMODULE_node_form_submit';
}
}
break;
}
}
function MYMODULE_node_form_submit(array &$form, FormStateInterface &$form_state) {
// https://drupal.stackexchange.com/a/250474/5147
\Drupal::request()->query->remove('destination');
$form_state->setRedirect('node.add_page');
}
This redirects to /node/add
, but I want to redirect to /node/add/question
. I tried digging through the route options in PHPStorm but I couldn't find anything that gets to the create page for a custom content type.