I have successfully used Rules module to take new user after creating/saving new account to "create content" page. That could be done with the help of Redirect URL.
But I have a complex case scenario and I need help to customize Rules for this purpose.
On new account/registration page, along with other details user is asked to select a particular taxonomy term (hierarchical select) like: mobile>mobile phones / mobile accessories atc. or real estate > flats for sale/ appartments on rent/paying guest etc. I have separate Content types for each of these taxonomy terms with a particular taxonomy term set as default category. Like Mobile phone content type has mobile phone taxonomy term set as default category.
I want to lead users on new account registration to add a particular content type selected automatically on the basis of his chosen category in registration form.
How to do it: How to tell Rules to Redirect url to that particular content type? Can flag module be of any help?
I tried using flag module and creating taxonomy term flag. And then I used wild card url like node/add/* in both flag and rules action. In rules I added flag as condition. But it didnt work. Users are simply taken to front page now. Please help.

Comments

ManuAdam’s picture

Title: Rules redirect url to particular content type on new account save » Rules for redirecting url to particular content type on new account save

So many days passed and no helpful hint yet :(

TR’s picture

Component: Forms Support » Rules Core
TR’s picture

Status: Active » Fixed

Once you decide on a data model and set up your content types and taxonomy terms and user entity appropriately, writing the Rule is EASY. Here's one way to do it:

I want to lead users on new account registration to add a particular content type selected automatically on the basis of his chosen category in registration form.

Here's the key problem you have to solve - what relates the selected taxonomy term to the content type? And how is Rules or anything else supposed to figure out the association between the two? You say

Mobile phone content type has mobile phone taxonomy term set as default category

But that's not good enough. A taxonomy term may be many words, mixed case, special characters, spaces, etc. but a content type has to be a machine name with a limited length and a restricted character set. It's not good enough to lower case and replace spaces with _ etc - you have to design a data model to create a 1-to-1 mapping between term name your use selects and content type machine name that is used to create the content.

The way you do that is to add a field to your taxonomy. Go to /admin/structure/taxonomy and "Manage fields" for your vocabulary. I would install https://www.drupal.org/project/machine_name to get a real machine name field, so that it is always a valid machine name. Add the machine name field, call it a "Content type", with machine name "field_content_type". Make it mandatory. Go to "Manage display" and set the display to "Hidden", because you do not want it to show. Now when you create your taxonomy terms you will have to enter the machine name of the content type it is associated with.

Now we have to configure things.

1) Install the Token module. Go to /admin/structure/taxonomy and edit your vocabulary. Go to the "Manage display" tab for your vocabulary and open the "Custom display settings" fieldset at the bottom, and check "Tokens" (and only "Tokens"). Save. Then go to the "Tokens" subtab under manage display and choose "Default" for the format of your "Content type" field. Save. This enables the "Content type" values to appear in tokens - we will need this later.
2) Add a term reference field to your user (do this at /admin/config/people/accounts/fields). Make it single selection - the user can only choose one term. Make that selection mandatory. I named that field "field_single_term_ref". This term reference field should use the vocabulary with the "Content type" field that you set up above.
3) On the user page, the user will now be required to choose one and only term from your vocabulary, and in the above steps you've associated a specific content type to each term. We now have all the information we need to do the redirect.
4) Import the Rule shown below. This will redirect to the term page for the term your user selected.
5) Note this Rule triggers on user updated, but you can change it to user logged in or any other event you like. It's a lot easier to debug if you don't have to keep logging out and logging in ...

{ "rules_redirect_to_user_profile_term" : {
    "LABEL" : "redirect to add content page based on selected profile term",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "user_update" : [] },
    "DO" : [
      { "redirect" : { "url" : "node\/add\/[account:field-single-term-ref:field-content-type]" } }
    ]
  }
}

As you can see, writing the Rule was the simple part - the harder part was deciding on a data model and setting up your user entity, your term vocabulary, and your individual terms to contain all the data that you need to do this.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

TR’s picture