Dear All:
I am fairly new to Drupal and Rules. I have already created a few rules to automate notifications on content creation, CCK field changes etc. Those I did, I followed the information on the documentation. This modules is quite powerful and I want to learn a bit farther how to use it and diminish the work load of my users
I have read many post from this group and I believe the issue I have is not fully referenced or I totally missed it. This post http://groups.drupal.org/node/71243 I think has something to do with my case but not completely. So let me explain my situation.
I have two content types A and B. Each content type looks like
Content A
-Title
-Body (recipe)
-Reference to Content B (nodereference -multivalued- to Content B, certainly this field is not mandatory to fill at creation)
Content B
-Referenced Content A (nodereference to content A -single valued-, mandatory)
-Body (this is the report)
Content A is a request of some type (let say a cooking recipe, which is not my real case ;-)). This request is tried/tested by several users and eventually they will create a/some Report(s) on it (Content B). After a Report is created/saved, I'd want automatically the nodereference field in Content A to be filled accordingly pointing to this Report (filling a unlimited list of reports). In my production environment owners of content A are forced populate manually the nodereference field with the new report added (as many times as reports added). That's the step I want to get rid of.
To bias experts explanations, I believe the principles for this workflow to work are:
1- content A is created independently and in advance to any content B related to it (this process is manual)
2- When the content B is going to be saved the system knows to which node of type "A" it references.
As I said in http://groups.drupal.org/node/71243 is slightly similar but not the same. Probably my situation is less complex. But I already know drupal 6 has some issues with loading several nodes at the same time.
I appreciate any help you can give me,
best regards,
Comments
Look into this module,
Look into this module, http://drupal.org/project/cnr. I think it's close to what you want.
Thomas Hansen
www.ThomasHansen.me
thanks
Dear thomas4019:
thanks for your comment I think that module does the work I also tried (successfully) backreference.
Best regards,
A Rules method
A way of doing this with Rules is:
// $node is the newly created node, of type B
// $referenced_node is the refrerenced node, of type A
// Please adjust any variables in the script to match your setup.
$reference_list = $referenced_node->field_reference_a2b // This will be an array of all current references from A to Bs
// If there were no referenced nodes, replace the first (empty) place with this new reference
if (is_null($reference_list[0]['nid'])) {
$reference_list[0] = array(
nid => $node->nid,
);
} else {
// Otherwise, append the new reference to the list
$reference_list[] = array(
nid => $node->nid,
);
}
return $reference_list;
If you can find a module that does exactly what you want I would recommend using it instead of putting PHP snippets in your database. But this might be a nice exercise anyway. :-)
(I'm pretty sure there are modules doing back references the way you want, but a very quick search didn't find anything that was 100% match.)
Good luck!
//Johan Falk, NodeOne, Sweden
thx Itanglo (some drupalmodules does solve the original problem)
Clever solution. I will copy into my tricks and tips documentation. However, I will follow your last advise, less php code in the site the better ;-).
For completeness of this post, Both modules reported above: http://drupal.org/project/backreference and http://drupal.org/project/cnr; solve the situation I posted. I can assure the backreference does the work (nicely), however the "cnr" apparetly has a better UI but I haven't tested it yet.
confirmation of Rules example from Itngalo
Hi Itanglo:
Yes indeed, your example works like a charm.
For other users here you have the result of the export of the rules suggested (just the referencing is done when the content Song is newly created).
Notice that for this to work you need two Content Types (Artis and Song in the example bellow) each with a field referencing each other.
Song has a "field_reference_artist" Node Reference Field (pointing to nodes of type Artist )
Artist has a "field_reference_song" Node Reference Field (pointing to nodes of type Song )
The Artist node must have been created in advance.
array (
'rules' =>
array (
'rules_1' =>
array (
'#type' => 'rule',
'#set' => 'event_node_insert',
'#label' => 'Load node and fill CCK field',
'#active' => 1,
'#weight' => '0',
'#categories' =>
array (
0 => 'node populate',
),
'#status' => 'custom',
'#conditions' =>
array (
0 =>
array (
'#weight' => 0,
'#info' =>
array (
'label' => 'Created content is Song',
'arguments' =>
array (
'node' =>
array (
'type' => 'node',
'label' => 'Content',
),
),
'module' => 'Node',
),
'#name' => 'rules_condition_content_is_type',
'#settings' =>
array (
'type' =>
array (
'song' => 'song',
),
'#argument map' =>
array (
'node' => 'node',
),
),
'#type' => 'condition',
),
),
'#actions' =>
array (
0 =>
array (
'#type' => 'action',
'#settings' =>
array (
'field' => 'field_reference_artist',
'#argument map' =>
array (
'node' => 'node',
'referenced_node' => 'referenced_node',
),
),
'#name' => 'nodereference_rules_action_load',
'#info' =>
array (
'label' => 'Load a referenced node',
'arguments' =>
array (
'node' =>
array (
'type' => 'node',
'label' => 'Content containing the node reference field',
),
),
'new variables' =>
array (
'referenced_node' =>
array (
'type' => 'node',
'label' => 'Referenced content',
),
),
'module' => 'CCK',
),
'#weight' => 0,
),
1 =>
array (
'#weight' => 0,
'#info' =>
array (
'label' => 'Populate Referenced content\'s field \'field_reference_song\'',
'arguments' =>
array (
'node' =>
array (
'type' => 'node',
'label' => 'Content',
),
),
'eval input' =>
array (
0 => 'code',
),
'module' => 'CCK',
),
'#name' => 'content_rules_action_populate_field',
'#settings' =>
array (
'field_name' => 'field_reference_song',
'#argument map' =>
array (
'node' => 'referenced_node',
),
'value' =>
array (
0 =>
array (
'nid' => NULL,
),
),
'code' => '// $node is the newly created node, of type B
// $referenced_node is the referenced node, of type A
// Please adjust any variables in the script to match your setup.
$reference_list = $referenced_node->field_reference_song; // This will be an array of all current references from A to Bs
// If there were no referenced nodes, replace the first (empty) place with this new reference
if (is_null($reference_list[0][\'nid\'])) {
$reference_list[0] = array(
nid => $node->nid,
);
} else {
// Otherwise, append the new reference to the list
$reference_list[] = array(
nid => $node->nid,
);
}
return $reference_list;',
'vars' =>
array (
0 => 'referenced_node',
1 => 'node',
),
),
'#type' => 'action',
),
),
'#version' => 6003,
),
),
)
how to set rules for following conditions
i have two content types
content type "job Application " has node reference field for "job posting". so whenever one user create a "job posting" means, another user can send a "job application" to that job by filling the fields.
can i know how i can sent a notification to the user who had posted job ,when "job application" has been created for his/her job by rules ?
thank in advance