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';

function MYMODULE_node_form_submit(array &$form, FormStateInterface &$form_state) {
  // https://drupal.stackexchange.com/a/250474/5147

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.

  • 1
    A good way to learn about specific routes is to look at the module's .routing.yml file.
    – sonfd
    Commented Jul 1, 2020 at 11:50

2 Answers 2


You're looking for the node.add route, which has a node_type parameter.

$form_state->setRedirect('node.add', ['node_type' => 'question']);

You have to redirect to the "add page" of type question,replace



$form_state->setRedirect('node.add', ['node_type' => 'question']);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.