source: sipes/modules_contrib/revisioning/revisioning.pages.inc @ 3514c84

stableversion-3.0
Last change on this file since 3514c84 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: 12.7 KB
Línea 
1<?php
2
3/**
4 * @file
5 * Rendering and altering of pages and forms used by Revisioning
6 */
7
8/**
9 * Implementation of hook_form_alter().
10 *
11 * Note: for cases where the FORM_ID is known a priori use
12 * revisioning_form_FORM_ID_form_alter(), e.g. revisioning_form_node_type_form_alter()
13 */
14function revisioning_form_alter(&$form, &$form_state, $form_id) {
15  // Alter the Create/Edit form
16  if (isset($form['#id']) && $form['#id'] == 'node-form') {
17    $content_type = $form['type']['#value'];
18    // Note that $form_id == $content_type_$form['#id']
19    $form['options']['#collapsed'] = FALSE;
20    // Only add this tick-box if user has the 'administer nodes' permission
21    if (user_access('administer nodes')) {
22      $form['revision_information']['revision_moderation'] = array(
23        '#title' => t('New revision in draft, pending moderation'),
24        '#type' => 'checkbox',
25        '#default_value' => node_tools_content_is_moderated($content_type)
26      );
27    }
28    else {
29      // Don't show tickbox, just set default on form
30      $form['revision_moderation'] = array(
31        '#type' => 'value',
32        '#value' => node_tools_content_is_moderated($content_type)
33      );
34    }
35
36    // In addition to node_form_submit() append our own handler to the list.
37    $form['buttons']['submit']['#submit'][] = '_revisioning_form_submit';
38
39    // Change the meaning of the 'Delete (all revisions)' button when editing
40    // a revision to be the deletion of the viewed revision, rather than the
41    // node.
42    if (isset($form['#node']->nid) && isset($form['#node']->vid)) {
43      $nid = $form['#node']->nid;
44      $vid = $form['#node']->vid;
45      if (isset($form['buttons']['delete']) && user_access('delete revisions') && $vid != node_tools_get_current_node_revision_id($nid)) {
46        $form['buttons']['delete']['#value'] =  t('Delete this revision');
47        $form['buttons']['delete']['#submit'][] = '_revisioning_delete_submit';
48      }
49    }
50  }
51}
52
53/**
54 * Implementation of hook_form_FORM_ID_form_alter().
55 *
56 * On content type edit form, add the "New revision in draft, pending moderation"
57 * tick-box and a couple of radio-boxes to select the new revision and
58 * auto-publish policies.
59 */
60function revisioning_form_node_type_form_alter(&$form, &$form_state) {
61  $form['workflow']['#collapsed'] = FALSE;
62  $form['workflow']['node_options']['#options']['revision_moderation'] = t('New revision in draft, pending moderation (requires "Create new revision")');
63
64  $content_type = $form['#node_type']->type;
65  $form['workflow']['revisioning'] = array(
66    '#type' => 'fieldset',
67    '#title' => t('New revision in draft'),
68    '#collapsible' => TRUE,
69    '#collapsed' => FALSE
70  );
71  $form['workflow']['revisioning']['new_revisions'] = array(
72    '#title' => t('Create new revision'),
73    '#type' => 'radios',
74    '#options' => array(
75      NEW_REVISION_WHEN_NOT_PENDING => t('Only when saving %type content that is not already in draft/pending moderation', array('%type' => $content_type)),
76      NEW_REVISION_EVERY_SAVE       => t('Every time %type content is updated, even when saving content in draft/pending moderation', array('%type' => $content_type))),
77    '#default_value' => (int)variable_get('new_revisions_'. $content_type, NEW_REVISION_WHEN_NOT_PENDING),
78    '#description' => t('Use less disk space and avoid cluttering your revisions list. With the first option ticked, modifications are saved to the same copy (i.e. no additional revisions are created) until the content is published.')
79    );
80  $form['workflow']['revisioning']['revisioning_auto_publish'] = array(
81    '#title' => t('Auto-publish drafts of @this type %type (for moderators)', array(
82      '@this' => empty($content_type) ? t('this') : '', '%type' => $content_type)),
83    '#type' => 'checkbox',
84    '#default_value' => (int)variable_get('revisioning_auto_publish_'. $content_type, FALSE),
85    '#description' => t('If this box is ticked and the logged-in user has one of the "publish revisions" permissions, then any draft of @this type %type is published immediately upon saving, without further review.', array(
86      '@this' => empty($content_type) ? t('this') : '', '%type' => $content_type))
87  );
88}
89
90/**
91 * Return a confirmation page for publishing a revision.
92 */
93function revisioning_publish_confirm($form_state, $node) {
94  $form['node_id']  = array('#type' => 'value', '#value' => $node->nid);
95  $form['title']    = array('#type' => 'value', '#value' => $node->title);
96  $form['revision'] = array('#type' => 'value', '#value' => $node->vid);
97  $form['type']     = array('#type' => 'value', '#value' => $node->type);
98  return confirm_form($form,
99    t('Are you sure you want to publish this revision of %title?', array('%title' => $node->title)),
100    'node/'. $node->nid .'/revisions',
101    t('Publishing this revision will make it visible to the public.'),
102    t('Publish'), t('Cancel'));
103}
104
105/**
106 * Submission handler for the publish_confirm form.
107 */
108function revisioning_publish_confirm_submit($form, &$form_state) {
109  $nid = $form_state['values']['node_id'];
110  $vid = $form_state['values']['revision'];
111  _revisioning_publish_revision($nid, $vid);
112  drupal_set_message(t('Revision has been published.'));
113
114  // [#886384]
115  global $base_url;
116  $url = $base_url . '/' . drupal_get_path_alias('node/'. $nid);
117  cache_clear_all($url, 'cache_page');
118
119  // Redirect to the same page as unpublish and revert
120  $form_state['redirect'] = "node/$nid/revisions";
121}
122
123/**
124 * Return a confirmation page for unpublishing the node.
125 */
126function revisioning_unpublish_confirm($form_state, $node) {
127  $form['node_id'] = array('#type' => 'value', '#value' => $node->nid);
128  $form['title']   = array('#type' => 'value', '#value' => $node->title);
129  $form['type']    = array('#type' => 'value', '#value' => $node->type);
130  return confirm_form($form,
131    t('Are you sure you want to unpublish %title?', array('%title' => $node->title)),
132    "node/$node->nid/revisions",
133    t('Unpublishing will remove this content from public view.'),
134    t('Unpublish'), t('Cancel'));
135}
136
137/**
138 * Submission handler for the unpublish_confirm form.
139 */
140function revisioning_unpublish_confirm_submit($form, &$form_state) {
141  $nid = $form_state['values']['node_id'];
142  _revisioning_unpublish_revision($nid);
143//$type = $form_state['values']['type']; // machine name, eg. 'story' rather than 'Story'
144  $title = $form_state['values']['title'];
145  drupal_set_message(t('%title is no longer publicly visible.', array('%title' => $title)));
146
147  // [#886384]
148  global $base_url;
149  $url = $base_url . '/' . drupal_get_path_alias('node/'. $nid);
150  cache_clear_all($url, 'cache_page');
151
152  // Redirect to the same page as publish and revert
153  $form_state['redirect'] = "node/$nid/revisions";
154}
155
156function revisioning_delete_archived_confirm($form_state, $node) {
157  $node->num_archived = revisioning_get_number_of_archived_revisions($node);
158  $form['node']  = array('#type' => 'value', '#value' => $node);
159  $t = format_plural($node->num_archived,
160    'Are you sure you want to delete the archived revision of %title?',
161    'Are you sure you want to delete all @count archived revisions of %title?',
162    array('%title' => $node->title)
163  );
164  return confirm_form($form, $t, 'node/' . $node->nid . '/revisions',
165    t('This action cannot be undone.'),
166    t('Delete archived'), t('Cancel'));
167}
168
169/**
170 * Submission handler for the delete_archived_confirm form.
171 */
172function revisioning_delete_archived_confirm_submit($form, &$form_state) {
173  $node = $form_state['values']['node'];
174  revisioning_delete_archived_revisions($node);
175  drupal_set_message(format_plural($node->num_archived, 'One archived revision deleted.', '@count archived revisions deleted.'));
176  $form_state['redirect'] = ($node->num_revisions - $node->num_archived > 1)
177    ? 'node/' . $node->nid . '/revisions'
178    : 'node/' . $node->nid;
179}
180
181/**
182 * Implementation of hook_form_FORM_ID_alter(), see
183 * node.pages.inc/node_revision_revert_confirm()
184 */
185function revisioning_form_node_revision_revert_confirm_alter(&$form, &$form_state) {
186  $node = $form['#node_revision'];
187  if (_revisioning_get_number_of_pending_revisions($node->nid) > 0) {
188    drupal_set_message(t('There is a pending revision. Are you sure you want to revert to an archived revision?'), 'warning');
189  }
190  array_unshift($form['#submit'], 'revisioning_revert_confirm_pre_submit');
191  $form['#submit'][] = 'revisioning_revert_confirm_post_submit';
192}
193
194/**
195 * Implementation of hook_form_FORM_ID_alter(), see
196 * node.pages.inc/node_revision_delete_confirm()
197 *
198 * We only add "pre" submit handler, because "post delete" event is already
199 * available via hook_nodeapi().
200 */
201function revisioning_form_node_revision_delete_confirm_alter(&$form, &$form_state) {
202  array_unshift($form['#submit'], 'revisioning_revision_delete_confirm_pre_submit');
203}
204
205/**
206 * Submission "pre" handler for the node_revision_delete_confirm form.
207 *
208 * Runs BEFORE the existing delete function in node.pages.inc
209 */
210function revisioning_revision_delete_confirm_pre_submit($form, &$form_state) {
211  $node = $form['#node_revision'];
212  $return = module_invoke_all('revisionapi', 'pre delete', $node);
213  if (in_array(FALSE, $return)) {
214    drupal_goto('node/'. $node->nid .'/revisions/'. $node->vid .'/view');
215    die;
216  }
217}
218
219/**
220 * Submission "pre" handler the revert_confirm form.
221 *
222 * Runs BEFORE the existing revert function in node.pages.inc
223 */
224function revisioning_revert_confirm_pre_submit($form, &$form_state) {
225  $node = $form['#node_revision'];
226  module_invoke_all('revisionapi', 'pre revert', $node);
227}
228
229/**
230 * Submission "post" handler for the revert_confirm form.
231 *
232 * Runs AFTER the existing revert function in node.pages.inc
233 *
234 * Note:
235 * It would be nice if publish and revert were symmetrical operations and that
236 * node_revision_revert_confirm_submit didn't save a physical copy of the
237 * revision (under a new vid), as this has the side-effect of making all
238 * "pending" revisions "archived". This is because the definition of "pending"
239 * is: "node_vid > current_vid".
240 * It would be better if "pending" relied on a separate flag rather than a field
241 * such as vid or timestamp that changes every time a piece of code executes a
242 * node_save().
243 */
244function revisioning_revert_confirm_post_submit($form, &$form_state) {
245  $node = $form['#node_revision'];
246//_revisioning_publish_node($node->nid); [#611988]
247  module_invoke_all('revisionapi', 'post revert', $node);
248}
249
250
251/**
252 * Return as a themed table a list of nodes that have pending revisions.
253 * access rights of the logged-in user.
254 *
255 * @param $op
256 *   Operation, one of 'view', 'update' or 'delete'.
257 * @param $user_filter
258 *   One of NO_FILTER, I_CREATED or I_LAST_MODIFIED.
259 * @return
260 *   themed HTML
261 */
262function _revisioning_show_pending_nodes($access = 'view', $user_filter = NO_FILTER) {
263  $is_moderated = user_access('administer nodes') ? NO_FILTER : TRUE;
264  $content_summary = module_grants_monitor_accessible_content_summary($access, NO_FILTER, $user_filter, $is_moderated, TRUE);
265  if (user_access('view revision status messages') && strpos($content_summary, 'No content') === FALSE && !user_access('administer nodes')) {
266    _revisioning_set_info_message();
267  }
268  return $content_summary;
269}
270
271function _revisioning_set_info_message() {
272  if (user_access('publish revisions')) {
273    $moderated_types = array();
274    foreach (node_get_types() as $type) {
275      if (node_tools_content_is_moderated($type->type) &&
276        (user_access('view revisions') || user_access('view revisions of any '. $type->type .' content'))) {
277        $moderated_types[] = $type->name;
278      }
279    }
280    if (count($moderated_types) > 0) {
281      drupal_set_message(t('You have permission to publish revisions of type(s): %moderated_types.',
282        array('%moderated_types' => implode(', ', $moderated_types))));
283    }
284  }
285}
286
287/**
288 * Handler for the 'Save' button on the edit form.
289 *
290 * When saving a new revision we shouldn't redirect to "View current", as
291 * that's not the one we've saved. However at this stage, via the form, we
292 * don't know the vid of the newly created revision, only the vid of the
293 * revision we've just edited, so we get latest revision id from the database.
294 */
295function _revisioning_form_submit($form, &$form_state) {
296  if (isset($form['#node']->nid)) {
297    $nid = $form['#node']->nid; // Don't use $form_state['nid'], will NOT be empty for a new node
298    // Don't redirect when creating new node or when the displayed vid is the current
299    if (($vid = revisioning_get_latest_revision_id($nid)) &&
300      $vid != node_tools_get_current_node_revision_id($nid)) {
301        $form_state['redirect'] = "node/$nid/revisions/$vid/view";
302    }
303  }
304}
305
306/**
307 * Handler for the 'Delete this revision' button on the edit form.
308 *
309 * Redirect to node/%/revisions/%/delete as opposed to node/%/delete
310 */
311function _revisioning_delete_submit(&$form, &$form_state) {
312  $nid = $form['#node']->nid;
313  $vid = $form['#node']->vid;
314  $form_state['redirect'][0] = "node/$nid/revisions/$vid/delete";
315}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.