1 | <?php |
---|
2 | // $Id: nodereference.rules.inc,v 1.1.2.2 2008/10/06 15:02:03 karens Exp $ |
---|
3 | |
---|
4 | /** |
---|
5 | * @file |
---|
6 | * Provides additional rules support for nodereference fields. |
---|
7 | */ |
---|
8 | |
---|
9 | /** |
---|
10 | * Implementation of hook_rules_action_info(). |
---|
11 | */ |
---|
12 | function nodereference_rules_action_info() { |
---|
13 | $info = array(); |
---|
14 | $info['nodereference_rules_action_load'] = array( |
---|
15 | 'label' => t('Load a referenced node'), |
---|
16 | 'arguments' => array( |
---|
17 | 'node' => array( |
---|
18 | 'type' => 'node', |
---|
19 | 'label' => t('Content containing the node reference field'), |
---|
20 | ), |
---|
21 | ), |
---|
22 | 'new variables' => array( |
---|
23 | 'referenced_node' => array( |
---|
24 | 'type' => 'node', |
---|
25 | 'label' => t('Referenced content'), |
---|
26 | ), |
---|
27 | ), |
---|
28 | 'module' => 'CCK', |
---|
29 | 'help' => t('Note that if the field has multiple values, only the first content node will be loaded.'), |
---|
30 | ); |
---|
31 | return $info; |
---|
32 | } |
---|
33 | |
---|
34 | function nodereference_rules_action_load($node, $settings) { |
---|
35 | if ($nid = $node->{$settings['field']}[0]['nid']) { |
---|
36 | return array('referenced_node' => node_load(array('nid' => $nid))); |
---|
37 | } |
---|
38 | } |
---|
39 | |
---|
40 | function nodereference_rules_action_load_form($settings, &$form) { |
---|
41 | $settings += array('field' => ''); |
---|
42 | $options = content_rules_get_field_names_by_type('nodereference'); |
---|
43 | $form['settings']['field'] = array( |
---|
44 | '#type' => 'select', |
---|
45 | '#title' => t('Field'), |
---|
46 | '#default_value' => $settings['field'], |
---|
47 | '#options' => $options, |
---|
48 | '#required' => TRUE, |
---|
49 | '#disabled' => empty($options), |
---|
50 | '#description' => empty($options) ? t('There are no nodereference fields defined.') : '', |
---|
51 | ); |
---|
52 | } |
---|
53 | |
---|
54 | /** |
---|
55 | * Helps upgrading from the workflow-ng action |
---|
56 | * "workflow_ng_action_load_referenced_node" to the equivalent rules action. |
---|
57 | */ |
---|
58 | function workflow_ng_action_load_referenced_node_upgrade(&$element) { |
---|
59 | $element['#name'] = 'nodereference_rules_action_load'; |
---|
60 | } |
---|