source: sipes/modules_contrib/revisioning/revisioning.rules.inc @ a8b1f3f

stableversion-3.0
Last change on this file since a8b1f3f was 177a560, checked in by José Gregorio Puentes <jpuentes@…>, 8 años ago

se agrego el directorio de modulos contribuidos de drupal

  • Propiedad mode establecida a 100644
File size: 8.3 KB
Línea 
1<?php
2
3/**
4 * @file
5 *  Rules integration for Revisioning module.
6 *
7 */
8
9/*************************** Rules Conditions ********************************/
10
11/*
12 * Implementation of hook_rules_condition_info().
13 */
14function revisioning_rules_condition_info() {
15  return array(
16    'revisioning_node_has_pending' => array(
17      'label' => t('Content has pending revision'),
18      'arguments' => array(
19        'node' => array('type' => 'node', 'label' => t('Content'))
20      ),
21      'help' => t('Evaluates to TRUE, if the node has one or more pending revisions.'),
22      'module' => 'Revisioning',
23    ),
24    'revisioning_condition_revision_is' => array(
25      'label' => t('Content revision is'),
26      'arguments' => array(
27        'node' => array('type' => 'node', 'label' => t('Content'))
28      ),
29      'help' => t('Evaluates to TRUE, if the revision is in one of the selected states.'),
30      'module' => 'Revisioning',
31    ),
32  );
33}
34
35/*
36 * Condition: check for pending revisions of the node.
37 */
38function revisioning_node_has_pending($node, $settings) {
39  $nid = is_numeric($node) ? $node : $node->nid;
40  $num_pending = _revisioning_get_number_of_pending_revisions($nid);
41  return $num_pending > 0 || (is_object($node) && !$node->status && ($node->num_revisions = node_tools_get_number_of_revisions($node->nid)) <= 1);
42}
43
44/*
45 * Condition: check for pending revisions of the node.
46 */
47function revisioning_condition_revision_is($node, $settings) {
48  // For some reason, when a node is published, rather than updated, $node will
49  // be the nid, without any vid info, so we can't load the revision.
50  if (!is_object($node) || empty($node->revision_moderation)) {
51    return FALSE;
52  }
53
54  $node->is_current = node_tools_revision_is_current($node);
55  $node->is_pending = _revisioning_node_is_pending($node);
56  $node->num_revisions = node_tools_get_number_of_revisions($node->nid);
57  $type = _revisioning_revision_is($node);
58  return in_array($type, $settings['revision_type']);
59}
60
61/*
62 *  Check for content types - configuration form.
63 */
64function revisioning_condition_revision_is_form($settings = array(), &$form) {
65  $form['settings']['revision_type'] = array(
66    '#type' => 'select',
67    '#title' => t('Is one of'),
68    '#options' => revisioning_revision_states(),
69    '#multiple' => TRUE,
70    '#default_value' => isset($settings['revision_type']) ? $settings['revision_type'] : array(),
71    '#required' => TRUE,
72  );
73}
74
75/**
76 * Label callback for "revisioning_revision_is" condition.
77 */
78function revisioning_condition_revision_is_label($settings, $argument_labels) {
79  $names = array_intersect_key(revisioning_revision_states(), $settings['revision_type']);
80  return t('Revision status of @node is: @type', $argument_labels + array('@type' => implode(t(' or '), $names)));
81}
82
83/**
84 * Label callback for "revisioning_node_has_pending" condition.
85 */
86function revisioning_node_has_pending_label($settings, $argument_labels) {
87  return t('@node has pending revision(s)', $argument_labels);
88}
89
90/************************** Rules Events **************************************/
91
92/**
93 * Implementation of hook_rules_event_info().
94 */
95function revisioning_rules_event_info() {
96  $default = array(
97    'module' => 'Revisioning',
98    'arguments' =>  _revisioning_rules_event_arguments(),
99    'redirect' => TRUE,
100  );
101  $events = array(
102    'revisioning_post_unpublish' => $default + array(
103      'label' => t('Node has been unpublished'),
104    ),
105    'revisioning_post_publish' => $default + array(
106      'label' => t('Pending revision has been published'),
107    ),
108    'revisioning_post_revert' => $default + array(
109      'label' => t('Node has been reverted to revision'),
110    ),
111    'revisioning_pre_publish' => $default + array(
112      'label' => t('Node revision is going to be published'),
113    ),
114    'revisioning_pre_delete' => $default + array(
115      'label' => t('Node revision is going to be deleted'),
116    ),
117    'revisioning_pre_revert' => $default + array(
118      'label' => t('Node is going to be reverted to revision'),
119    ),
120  );
121  return $events;
122}
123
124/**
125 * Returns arguments suitable for using it with a node.
126 */
127function _revisioning_rules_event_arguments() {
128  return array(
129    'node' => array(
130      'type' => 'node',
131      'label' => t('target revision of operation'),
132    ),
133    'current_revision' => array(
134      'type' => 'node',
135      'label' => t('current revision of target content'),
136      'handler' => 'revisioning_events_argument_current_revision'
137    ),
138    'author' => array(
139      'type' => 'user',
140      'label' => t('content author'),
141      'handler' => 'rules_events_argument_node_author'
142    ),
143    'target_author' => array(
144      'type' => 'user',
145      'label' => t('target revision author'),
146      'handler' => 'revisioning_events_argument_target_revision_author'
147    ),
148    'current_author' => array(
149      'type' => 'user',
150      'label' => t('current revision author'),
151      'handler' => 'revisioning_events_argument_current_revision_author'
152    ),
153    'user' => array(
154      'type' => 'user',
155      'label' => t('acting user'),
156      'handler' => 'rules_events_argument_global_user'
157    ),
158  );
159}
160
161/**
162 * Current revision author argument handler.
163 */
164function revisioning_events_argument_current_revision_author($node) {
165  $current_vid = node_tools_get_current_node_revision_id($node->nid);
166  $uid = $node->revision_uid;
167  if ($node->vid != $current_vid) {
168    $current = node_load($node->nid, $current_vid);
169    $uid = $current->revision_uid;
170  }
171  $user = user_load($uid);
172  return $user;
173}
174
175/**
176 * Target revision author argument handler.
177 */
178function revisioning_events_argument_target_revision_author($node) {
179  $user = user_load($node->revision_uid);
180  return $user;
181}
182
183/**
184 * Current revision event argument handler.
185 */
186function revisioning_events_argument_current_revision($node) {
187  $current_vid = node_tools_get_current_node_revision_id($node->nid);
188  if ($node->vid != $current_vid) {
189    $current = node_load($node->nid, $current_vid);
190    return $current;
191  }
192  return $node;
193}
194
195/*************************** Rules Actions ************************************/
196
197/**
198 * Implementation of hook_rules_action_info().
199 */
200function revisioning_rules_action_info() {
201  $default = array(
202    'module' => 'Revisioning',
203  );
204  return array(
205    'revisioning_rules_action_publish_latest' => $default + array(
206      'label' => t('Publish the most recent pending revision'),
207      'arguments' => array(
208        'node' => array('type' => 'node', 'label' => t('content')),
209      ),
210    ),
211    'revisioning_rules_action_create_pending_revision' => $default + array(
212      'label' => t('Create a new pending revision of a node'),
213      'arguments' => array(
214        'node' => array('type' => 'node', 'label' => t('content')),
215      ),
216    ),
217    'revisioning_rules_action_load_current' => $default + array(
218      'label' => t('Load current revision of content'),
219      'arguments' => array(
220        'node' => array('type' => 'node', 'label' => t('content')),
221      ),
222      'new variables' => array(
223        'loaded_current_revision' => array(
224          'type' => 'node',
225          'label' => t('Loaded current revision of content'),
226          'save' => FALSE,
227          'label callback' => 'revisioning_rules_loaded_current_label',
228        ),
229      ),
230    ),
231  );
232}
233
234/**
235 * Label callback for "revisioning_rules_action_load_current" action.
236 */
237function revisioning_rules_action_load_current_label($settings, $argument_labels) {
238  return t('Load current revision of "@node"', $argument_labels);
239}
240
241/**
242 * Label callback for "loaded_current_revision" variable.
243 */
244function revisioning_rules_loaded_current_label($settings, $argument_labels) {
245  return t('Loaded current revision of "@node"', $argument_labels);
246}
247
248
249/**
250 * Action: publish most recent pending revision.
251 */
252function revisioning_rules_action_publish_latest($node) {
253  $published = _revisioning_publish_latest_revision($node);
254}
255
256/**
257 * Action: create pending revision.
258 */
259function revisioning_rules_action_create_pending_revision($node) {
260  revisioning_create_pending_revision_action($node);
261  return array('node' => $node);
262}
263
264/**
265 * Action: load current revision of provided node.
266 */
267function revisioning_rules_action_load_current($node) {
268  $current_vid = node_tools_get_current_node_revision_id($node->nid);
269  if ($node->vid != $current_vid) {
270    $current = node_load($node->nid, $current_vid);
271    return array('loaded_current_revision' => $current);
272  }
273  return array('loaded_current_revision' => $node);
274}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.