2

I would like for when I add of piece of content for it to stay on the admin back-end.. right now it forwards the user to the created node with a message saying it's been created, but the rest of the admin interface disappears so it's difficult to get back to adding more, and certain content types look very strange in that view.

I looked at actions/triggers, but I don't see a way to distinguish between content types, and I wouldn't want comments and user posts to forward to the admin interface so I don't see that as a solution.

1

The Add another module might come in handy for that:

Add another is designed to save time during repetitive content creation. It allows the content creator to add another node of the same type much faster.

It provides a 'Save and add another' button in addition to the standard 'Save' button on node forms.

0

The programming answer:

You can use hook_form_alter to alter redirect behavior.

Like so: (from linked thread)

<?php
function jeff_form_alter(&$form, &$form_state, $form_id)
{
     $form['#submit'][] = 'jeff_form_submit'; 
}

function jeff_form_submit($form, &$form_state)
{
     $form_state['redirect'] = 'process-your-donation';
}
?>

The contrib module answer:

Clive's recommendation of Add Another (compatible with D6 and D7) is a good one if you simply want to add another of the same type of node upon content submission.

6
  • I see I got a downvote. Is there an error in my answer?
    – beth
    Jun 11 '12 at 15:11
  • T'wasn't me but there are a lot of errors in that code (function sig is wrong, using $form['#id'] instead of provided $form_id, node form id has obliques instead of underscores, using $form['#redirect'] instead of providing a submit handler and using $form_state['redirect'], etc.)
    – Clive
    Jun 11 '12 at 15:17
  • So, the problem is a best-practice violation, then? I'm not trying to argue, genuinely want to fix it. Is there documentation on how best to accomplish this in the code?
    – beth
    Jun 11 '12 at 15:35
  • I think I've found a better example that's implemented more correctly and edited my answer. Is that what you had in mind?
    – beth
    Jun 11 '12 at 15:40
  • It wasn't just best-practice violations, the function signature was incorrect which meant the whole thing would fall over...the new example looks good, except $form_state should be passed by reference (&$form_state). It doesn't matter in the example above but it's a good practice to get into :)
    – Clive
    Jun 11 '12 at 15:42
0

A possible solution to answer this question is to enable the Rules module, and create a custom rule that looks like so:

{ "rules_show_new_article_link" : {
    "LABEL" : "Show New Article link",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_insert" : [] },
    "IF" : [
      { "node_is_of_type" : { "node" : [ "node" ], "type" : { "value" : { "article" : "article" } } } }
    ],
    "DO" : [
      { "drupal_message" : { "message" : "Click \u003Ca href=\u0022[site:url]node\/add\/article\u0022\u003Ethis link\u003C\/a\u003E to add another article ..." } }
    ]
  }
}

Some details about this rule:

  • Rules Events: After saving new content.
  • Rules Condition: Content is of type article.
  • Rules Action: Show a message on the site, whereas the actual message content that will be shown is "Click this link to add another article ..." and with 'this link' being rendered as an hyperlink to relative path node/add/article.

If you have the Rules UI enabled, you can just import the above rule in your own site. Adapt content type article to custom_content (or whatever fits your needs).

With that, each time you edit or create a node of article, you'll get such message (with appropriate link) in the Drupal message area. Obviously, you could add any applicable rules logic to further improve this prototype (e.g. to only show this for selected user roles). And should you want to do so, you could also add an extra Rules Action to perform a redirect to relative path node/add/article.

PS: this rule is my favorite sample to get started with the Rules module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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