I wonder how to access node properties via another node with Rules. I already store the link of my other node in a field (of the original node), but I don't know if we can do that.
I'm using the Drupal Commerce 7.x, Rules Link, and Content Access modules.
Here is what I want to do: after a candidate (a particular user) clicks on a rules link in a 1st node, I want to grant access for that candidate to a 2nd node and do a redirection to that 2nd node.
Here is what I currently do and how it works : When an Advertiser creates a node of type "classified ad
" i use a rule to do 2 things:
- Store the url of the primary node in one of the node's fields.
- Clone that node and convert it in another content type (= "
classified complete
").
Then with Content Access I block the access for all users except the author (in this case the Advertiser), administrator and super users.
When a candidate clicks on the link in the 1st node (with content type "classified ad
"), the candidate spends 100 credits (using the Userpoints module). Next I need to grant the candidate access to the 2nd node (with content type "classified complete
"), followed by a page redirect to that 2nd node.
a) My Rules Link export :
{
"settings" : {
"text" : "Access to contact informations",
"link_type" : "confirm",
"bundles" : { "classified" : "classified" },
"entity_link" : 1,
"view_mode" : { "full" : "full" },
"confirm_question" : "spend credits",
"confirm_description" : "Would you like to spend 100 credits to access contacts informations ?"
},
"name" : "access_to_contact_info_links",
"label" : "authenticated user Link contact infos ",
"path" : "access_to_contact_info_links",
"entity_type" : "node",
"rdf_mapping" : []
}
b) Rules Link Access condition (don't know how to export that) : I use a "user has role" condition and I check if the user is authenticated
c) Rules Link Reaction rule:
{ "rules_link_set_access_to_contact_info_links" : {
"LABEL" : "Rules link: Access to contact info links rules set",
"PLUGIN" : "rule set",
"OWNER" : "rules",
"REQUIRES" : [
"rules",
"userpoints_rules",
"rules_conditional",
"rules_i18n",
"content_access_rules"
],
"USES VARIABLES" : { "node" : { "label" : "node", "type" : "node" } },
"RULES" : [
{ "RULE" : {
"PROVIDE" : { "loaded_points" : { "loaded_points" : "Number of credit in the specified category." } },
"IF" : [
{ "user_has_role" : {
"account" : [ "site:current-user" ],
"roles" : { "value" : { "2" : "2" } }
}
}
],
"DO" : [
{ "userpoints_rules_get_current_points" : {
"USING" : { "user" : [ "site:current-user" ], "tid" : "86" },
"PROVIDE" : { "loaded_points" : { "loaded_points" : "Number of credit in the specified category." } }
}
},
{ "CONDITIONAL" : [
{
"IF" : { "data_is" : { "data" : [ "loaded-points" ], "op" : "\u003C", "value" : "100" } },
"DO" : [
{ "drupal_message" : { "message" : "You don\u0027t have enough credits !", "type" : "error" } }
]
},
{ "ELSE" : [
{ "userpoints_action_grant_points" : {
"user" : [ "site:current-user" ],
"points" : "-100",
"tid" : "86",
"entity" : [ "" ],
"operation" : "Remove",
"display" : "1",
"moderate" : "approved"
}
},
{ "CONDITIONAL" : [
{
"IF" : { "node_is_of_type" : {
"node" : [ "node" ],
"type" : { "value" : { "classified_complete" : "classified_complete" } }
}
},
"DO" : [
{ "CONDITIONAL" : [
{
"IF" : { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_link_to_unlocked_content_t" } },
"DO" : [
{ "drupal_message" : { "message" : "Trying to grant access !" } },
{ "content_access_action_user_grant" : {
"node" : [ "node" ],
"content_access_user_view" : [ "site:current-user" ],
"content_access_user_update" : [ "" ],
"content_access_user_delete" : [ "" ]
}
},
{ "redirect" : { "url" : "[node:field-link-to-unlocked-content-t]", "destination" : "1" } }
]
}
]
}
]
}
]
}
]
}
]
}
],
"LABEL" : "Enough Credits"
}
}
]
}
}
**
Is it possible ?