I have a content type whose nodes redirect to a view which lists them (instead of viewing the individual node pages). When users create nodes of this content type, they are taken back to the node edit page on submit. It would make more sense to instead take them to the specified redirect path - the view where they can see their newly-created node listed with the rest...

CommentFileSizeAuthor
#1 node_save_redirect-2326005-1.patch1.34 KBBWPanda
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

BWPanda’s picture

Status: Active » Needs review
FileSize
1.34 KB

This patch does just that. On node save, if a node (or it's content type) has RH set to redirect, then it redirects to that path, otherwise it redirect back to the node edit page as normal.

olofbokedal’s picture

Status: Needs review » Active

This is perfect for most use cases. However, there are some cases where this could be annoying or confusing.

One example is if you have a Download content type. If these shouldn't be viewable nodes, it makes sense to redirect to the file path which causes a download. This would mean that the user would download the file every time (s)he creates/updates a node.

This could be implemented if its controllable by bundle. I don't want to clutter the workflow to much, but this should be doable.

seworthi’s picture

Need to account for token's in the redirect. This worked for me.

    if ($action == RABBIT_HOLE_PAGE_REDIRECT) {
      // Get the RH redirect path. Either the one specified for this node, or the
      // default value for the content type.
      $redirect = isset($form_state['values']['rh_redirect']) ? $form_state['values']['rh_redirect'] : rabbit_hole_get_redirect_bundle('node', $form['#node']->type);

      // If token enabled, replace any tokens with real values.
      if (module_exists('token')) {
        $redirect = token_replace($redirect, array('node' => $form['#node']));
      }
      $form_state['redirect'] = $redirect;
    }
    else {
      $form_state['redirect'] = 'node/' . $form_state['values']['nid'] . '/edit';
    }
olofbokedal’s picture

Status: Active » Needs work

This needs a bit more work before it's ready for commit.

Have a look at how rabbit_hole_execute() handles the redirect. We need to respect both PHP and tokens (as mentioned in #3). Perhaps the best way would be to abstract the redirect logic to a new function which we then could call in the various form submissions.

dunx’s picture

Agreed. If you create a node and normally end up on /node/% then the RH settings should kick in and do what they've been configured to do. I'm not sure why it arbitrarily takes you to the /node/%/edit page. Especially bad if the user does not have permission to edit this node.

In the meantime, I'll create a form override to do what I thought RH would do automatically for me. Happy coding :)