node.pages.inc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. <?php
  2. /**
  3. * @file
  4. * Page callbacks for adding, editing, deleting, and revisions management for content.
  5. */
  6. /**
  7. * Menu callback; presents the node editing form.
  8. */
  9. function node_page_edit($node) {
  10. $type_name = node_type_get_name($node);
  11. drupal_set_title(t('<em>Edit @type</em> @title', array('@type' => $type_name, '@title' => $node->title)), PASS_THROUGH);
  12. return drupal_get_form($node->type . '_node_form', $node);
  13. }
  14. /**
  15. * Page callback: Displays add content links for available content types.
  16. *
  17. * Redirects to node/add/[type] if only one content type is available.
  18. *
  19. * @see node_menu()
  20. */
  21. function node_add_page() {
  22. $item = menu_get_item();
  23. $content = system_admin_menu_block($item);
  24. // Bypass the node/add listing if only one content type is available.
  25. if (count($content) == 1) {
  26. $item = array_shift($content);
  27. drupal_goto($item['href']);
  28. }
  29. return theme('node_add_list', array('content' => $content));
  30. }
  31. /**
  32. * Returns HTML for a list of available node types for node creation.
  33. *
  34. * @param $variables
  35. * An associative array containing:
  36. * - content: An array of content types.
  37. *
  38. * @ingroup themeable
  39. */
  40. function theme_node_add_list($variables) {
  41. $content = $variables['content'];
  42. $output = '';
  43. if ($content) {
  44. $output = '<dl class="node-type-list">';
  45. foreach ($content as $item) {
  46. $output .= '<dt>' . l($item['title'], $item['href'], $item['localized_options']) . '</dt>';
  47. $output .= '<dd>' . filter_xss_admin($item['description']) . '</dd>';
  48. }
  49. $output .= '</dl>';
  50. }
  51. else {
  52. $output = '<p>' . t('You have not created any content types yet. Go to the <a href="@create-content">content type creation page</a> to add a new content type.', array('@create-content' => url('admin/structure/types/add'))) . '</p>';
  53. }
  54. return $output;
  55. }
  56. /**
  57. * Returns a node submission form.
  58. */
  59. function node_add($type) {
  60. global $user;
  61. $types = node_type_get_types();
  62. $node = (object) array('uid' => $user->uid, 'name' => (isset($user->name) ? $user->name : ''), 'type' => $type, 'language' => LANGUAGE_NONE);
  63. drupal_set_title(t('Create @name', array('@name' => $types[$type]->name)), PASS_THROUGH);
  64. $output = drupal_get_form($type . '_node_form', $node);
  65. return $output;
  66. }
  67. function node_form_validate($form, &$form_state) {
  68. // $form_state['node'] contains the actual entity being edited, but we must
  69. // not update it with form values that have not yet been validated, so we
  70. // create a pseudo-entity to use during validation.
  71. $node = (object) $form_state['values'];
  72. node_validate($node, $form, $form_state);
  73. entity_form_field_validate('node', $form, $form_state);
  74. }
  75. /**
  76. * Generate the node add/edit form array.
  77. */
  78. function node_form($form, &$form_state, $node) {
  79. global $user;
  80. // During initial form build, add the node entity to the form state for use
  81. // during form building and processing. During a rebuild, use what is in the
  82. // form state.
  83. if (!isset($form_state['node'])) {
  84. if (!isset($node->title)) {
  85. $node->title = NULL;
  86. }
  87. node_object_prepare($node);
  88. $form_state['node'] = $node;
  89. }
  90. else {
  91. $node = $form_state['node'];
  92. }
  93. // Some special stuff when previewing a node.
  94. if (isset($form_state['node_preview'])) {
  95. $form['#prefix'] = $form_state['node_preview'];
  96. $node->in_preview = TRUE;
  97. }
  98. else {
  99. unset($node->in_preview);
  100. }
  101. // Identify this as a node edit form.
  102. // @todo D8: Remove. Modules can implement hook_form_BASE_FORM_ID_alter() now.
  103. $form['#node_edit_form'] = TRUE;
  104. $form['#attributes']['class'][] = 'node-form';
  105. if (!empty($node->type)) {
  106. $form['#attributes']['class'][] = 'node-' . $node->type . '-form';
  107. }
  108. // Basic node information.
  109. // These elements are just values so they are not even sent to the client.
  110. foreach (array('nid', 'vid', 'uid', 'created', 'type', 'language') as $key) {
  111. $form[$key] = array(
  112. '#type' => 'value',
  113. '#value' => isset($node->$key) ? $node->$key : NULL,
  114. );
  115. }
  116. // Changed must be sent to the client, for later overwrite error checking.
  117. $form['changed'] = array(
  118. '#type' => 'hidden',
  119. '#default_value' => isset($node->changed) ? $node->changed : NULL,
  120. );
  121. // Invoke hook_form() to get the node-specific bits. Can't use node_invoke(),
  122. // because hook_form() needs to be able to receive $form_state by reference.
  123. // @todo hook_form() implementations are unable to add #validate or #submit
  124. // handlers to the form buttons below. Remove hook_form() entirely.
  125. $function = node_type_get_base($node) . '_form';
  126. if (function_exists($function) && ($extra = $function($node, $form_state))) {
  127. $form = array_merge_recursive($form, $extra);
  128. }
  129. // If the node type has a title, and the node type form defined no special
  130. // weight for it, we default to a weight of -5 for consistency.
  131. if (isset($form['title']) && !isset($form['title']['#weight'])) {
  132. $form['title']['#weight'] = -5;
  133. }
  134. // @todo D8: Remove. Modules should access the node using $form_state['node'].
  135. $form['#node'] = $node;
  136. $form['additional_settings'] = array(
  137. '#type' => 'vertical_tabs',
  138. '#weight' => 99,
  139. );
  140. // Add a log field if the "Create new revision" option is checked, or if the
  141. // current user has the ability to check that option.
  142. $form['revision_information'] = array(
  143. '#type' => 'fieldset',
  144. '#title' => t('Revision information'),
  145. '#collapsible' => TRUE,
  146. // Collapsed by default when "Create new revision" is unchecked
  147. '#collapsed' => !$node->revision,
  148. '#group' => 'additional_settings',
  149. '#attributes' => array(
  150. 'class' => array('node-form-revision-information'),
  151. ),
  152. '#attached' => array(
  153. 'js' => array(drupal_get_path('module', 'node') . '/node.js'),
  154. ),
  155. '#weight' => 20,
  156. '#access' => $node->revision || user_access('administer nodes'),
  157. );
  158. $form['revision_information']['revision'] = array(
  159. '#type' => 'checkbox',
  160. '#title' => t('Create new revision'),
  161. '#default_value' => $node->revision,
  162. '#access' => user_access('administer nodes'),
  163. );
  164. // Check the revision log checkbox when the log textarea is filled in.
  165. // This must not happen if "Create new revision" is enabled by default, since
  166. // the state would auto-disable the checkbox otherwise.
  167. if (!$node->revision) {
  168. $form['revision_information']['revision']['#states'] = array(
  169. 'checked' => array(
  170. 'textarea[name="log"]' => array('empty' => FALSE),
  171. ),
  172. );
  173. }
  174. $form['revision_information']['log'] = array(
  175. '#type' => 'textarea',
  176. '#title' => t('Revision log message'),
  177. '#rows' => 4,
  178. '#default_value' => !empty($node->log) ? $node->log : '',
  179. '#description' => t('Provide an explanation of the changes you are making. This will help other authors understand your motivations.'),
  180. );
  181. // Node author information for administrators
  182. $form['author'] = array(
  183. '#type' => 'fieldset',
  184. '#access' => user_access('administer nodes'),
  185. '#title' => t('Authoring information'),
  186. '#collapsible' => TRUE,
  187. '#collapsed' => TRUE,
  188. '#group' => 'additional_settings',
  189. '#attributes' => array(
  190. 'class' => array('node-form-author'),
  191. ),
  192. '#attached' => array(
  193. 'js' => array(
  194. drupal_get_path('module', 'node') . '/node.js',
  195. array(
  196. 'type' => 'setting',
  197. 'data' => array('anonymous' => variable_get('anonymous', t('Anonymous'))),
  198. ),
  199. ),
  200. ),
  201. '#weight' => 90,
  202. );
  203. $form['author']['name'] = array(
  204. '#type' => 'textfield',
  205. '#title' => t('Authored by'),
  206. '#maxlength' => 60,
  207. '#autocomplete_path' => 'user/autocomplete',
  208. '#default_value' => !empty($node->name) ? $node->name : '',
  209. '#weight' => -1,
  210. '#description' => t('Leave blank for %anonymous.', array('%anonymous' => variable_get('anonymous', t('Anonymous')))),
  211. );
  212. $form['author']['date'] = array(
  213. '#type' => 'textfield',
  214. '#title' => t('Authored on'),
  215. '#maxlength' => 25,
  216. '#description' => t('Format: %time. The date format is YYYY-MM-DD and %timezone is the time zone offset from UTC. Leave blank to use the time of form submission.', array('%time' => !empty($node->date) ? date_format(date_create($node->date), 'Y-m-d H:i:s O') : format_date($node->created, 'custom', 'Y-m-d H:i:s O'), '%timezone' => !empty($node->date) ? date_format(date_create($node->date), 'O') : format_date($node->created, 'custom', 'O'))),
  217. '#default_value' => !empty($node->date) ? $node->date : '',
  218. );
  219. // Node options for administrators
  220. $form['options'] = array(
  221. '#type' => 'fieldset',
  222. '#access' => user_access('administer nodes'),
  223. '#title' => t('Publishing options'),
  224. '#collapsible' => TRUE,
  225. '#collapsed' => TRUE,
  226. '#group' => 'additional_settings',
  227. '#attributes' => array(
  228. 'class' => array('node-form-options'),
  229. ),
  230. '#attached' => array(
  231. 'js' => array(drupal_get_path('module', 'node') . '/node.js'),
  232. ),
  233. '#weight' => 95,
  234. );
  235. $form['options']['status'] = array(
  236. '#type' => 'checkbox',
  237. '#title' => t('Published'),
  238. '#default_value' => $node->status,
  239. );
  240. $form['options']['promote'] = array(
  241. '#type' => 'checkbox',
  242. '#title' => t('Promoted to front page'),
  243. '#default_value' => $node->promote,
  244. );
  245. $form['options']['sticky'] = array(
  246. '#type' => 'checkbox',
  247. '#title' => t('Sticky at top of lists'),
  248. '#default_value' => $node->sticky,
  249. );
  250. // Add the buttons.
  251. $form['actions'] = array('#type' => 'actions');
  252. $form['actions']['submit'] = array(
  253. '#type' => 'submit',
  254. '#access' => variable_get('node_preview_' . $node->type, DRUPAL_OPTIONAL) != DRUPAL_REQUIRED || (!form_get_errors() && isset($form_state['node_preview'])),
  255. '#value' => t('Save'),
  256. '#weight' => 5,
  257. '#submit' => array('node_form_submit'),
  258. );
  259. $form['actions']['preview'] = array(
  260. '#access' => variable_get('node_preview_' . $node->type, DRUPAL_OPTIONAL) != DRUPAL_DISABLED,
  261. '#type' => 'submit',
  262. '#value' => t('Preview'),
  263. '#weight' => 10,
  264. '#submit' => array('node_form_build_preview'),
  265. );
  266. if (!empty($node->nid) && node_access('delete', $node)) {
  267. $form['actions']['delete'] = array(
  268. '#type' => 'submit',
  269. '#value' => t('Delete'),
  270. '#weight' => 15,
  271. '#submit' => array('node_form_delete_submit'),
  272. );
  273. }
  274. // This form uses a button-level #submit handler for the form's main submit
  275. // action. node_form_submit() manually invokes all form-level #submit handlers
  276. // of the form. Without explicitly setting #submit, Form API would auto-detect
  277. // node_form_submit() as submit handler, but that is the button-level #submit
  278. // handler for the 'Save' action. To maintain backwards compatibility, a
  279. // #submit handler is auto-suggested for custom node type modules.
  280. $form['#validate'][] = 'node_form_validate';
  281. if (!isset($form['#submit']) && function_exists($node->type . '_node_form_submit')) {
  282. $form['#submit'][] = $node->type . '_node_form_submit';
  283. }
  284. $form += array('#submit' => array());
  285. field_attach_form('node', $node, $form, $form_state, entity_language('node', $node));
  286. return $form;
  287. }
  288. /**
  289. * Button submit function: handle the 'Delete' button on the node form.
  290. */
  291. function node_form_delete_submit($form, &$form_state) {
  292. $destination = array();
  293. if (isset($_GET['destination'])) {
  294. $destination = drupal_get_destination();
  295. unset($_GET['destination']);
  296. }
  297. $node = $form['#node'];
  298. $form_state['redirect'] = array('node/' . $node->nid . '/delete', array('query' => $destination));
  299. }
  300. function node_form_build_preview($form, &$form_state) {
  301. $node = node_form_submit_build_node($form, $form_state);
  302. $form_state['node_preview'] = node_preview($node);
  303. $form_state['rebuild'] = TRUE;
  304. }
  305. /**
  306. * Generate a node preview.
  307. */
  308. function node_preview($node) {
  309. if (node_access('create', $node) || node_access('update', $node)) {
  310. _field_invoke_multiple('load', 'node', array($node->nid => $node));
  311. // Load the user's name when needed.
  312. if (isset($node->name)) {
  313. // The use of isset() is mandatory in the context of user IDs, because
  314. // user ID 0 denotes the anonymous user.
  315. if ($user = user_load_by_name($node->name)) {
  316. $node->uid = $user->uid;
  317. $node->picture = $user->picture;
  318. }
  319. else {
  320. $node->uid = 0; // anonymous user
  321. }
  322. }
  323. elseif ($node->uid) {
  324. $user = user_load($node->uid);
  325. $node->name = $user->name;
  326. $node->picture = $user->picture;
  327. }
  328. $node->changed = REQUEST_TIME;
  329. $nodes = array($node->nid => $node);
  330. field_attach_prepare_view('node', $nodes, 'full');
  331. // Display a preview of the node.
  332. if (!form_get_errors()) {
  333. $node->in_preview = TRUE;
  334. $output = theme('node_preview', array('node' => $node));
  335. unset($node->in_preview);
  336. }
  337. drupal_set_title(t('Preview'), PASS_THROUGH);
  338. return $output;
  339. }
  340. }
  341. /**
  342. * Returns HTML for a node preview for display during node creation and editing.
  343. *
  344. * @param $variables
  345. * An associative array containing:
  346. * - node: The node object which is being previewed.
  347. *
  348. * @ingroup themeable
  349. */
  350. function theme_node_preview($variables) {
  351. $node = $variables['node'];
  352. $output = '<div class="preview">';
  353. $preview_trimmed_version = FALSE;
  354. $elements = node_view(clone $node, 'teaser');
  355. $trimmed = drupal_render($elements);
  356. $elements = node_view($node, 'full');
  357. $full = drupal_render($elements);
  358. // Do we need to preview trimmed version of post as well as full version?
  359. if ($trimmed != $full) {
  360. drupal_set_message(t('The trimmed version of your post shows what your post looks like when promoted to the main page or when exported for syndication.<span class="no-js"> You can insert the delimiter "&lt;!--break--&gt;" (without the quotes) to fine-tune where your post gets split.</span>'));
  361. $output .= '<h3>' . t('Preview trimmed version') . '</h3>';
  362. $output .= $trimmed;
  363. $output .= '<h3>' . t('Preview full version') . '</h3>';
  364. $output .= $full;
  365. }
  366. else {
  367. $output .= $full;
  368. }
  369. $output .= "</div>\n";
  370. return $output;
  371. }
  372. function node_form_submit($form, &$form_state) {
  373. $node = node_form_submit_build_node($form, $form_state);
  374. $insert = empty($node->nid);
  375. node_save($node);
  376. $node_link = l(t('view'), 'node/' . $node->nid);
  377. $watchdog_args = array('@type' => $node->type, '%title' => $node->title);
  378. $t_args = array('@type' => node_type_get_name($node), '%title' => $node->title);
  379. if ($insert) {
  380. watchdog('content', '@type: added %title.', $watchdog_args, WATCHDOG_NOTICE, $node_link);
  381. drupal_set_message(t('@type %title has been created.', $t_args));
  382. }
  383. else {
  384. watchdog('content', '@type: updated %title.', $watchdog_args, WATCHDOG_NOTICE, $node_link);
  385. drupal_set_message(t('@type %title has been updated.', $t_args));
  386. }
  387. if ($node->nid) {
  388. $form_state['values']['nid'] = $node->nid;
  389. $form_state['nid'] = $node->nid;
  390. $form_state['redirect'] = 'node/' . $node->nid;
  391. }
  392. else {
  393. // In the unlikely case something went wrong on save, the node will be
  394. // rebuilt and node form redisplayed the same way as in preview.
  395. drupal_set_message(t('The post could not be saved.'), 'error');
  396. $form_state['rebuild'] = TRUE;
  397. }
  398. // Clear the page and block caches.
  399. cache_clear_all();
  400. }
  401. /**
  402. * Updates the form state's node entity by processing this submission's values.
  403. *
  404. * This is the default builder function for the node form. It is called
  405. * during the "Save" and "Preview" submit handlers to retrieve the entity to
  406. * save or preview. This function can also be called by a "Next" button of a
  407. * wizard to update the form state's entity with the current step's values
  408. * before proceeding to the next step.
  409. *
  410. * @see node_form()
  411. */
  412. function node_form_submit_build_node($form, &$form_state) {
  413. // @todo Legacy support for modules that extend the node form with form-level
  414. // submit handlers that adjust $form_state['values'] prior to those values
  415. // being used to update the entity. Module authors are encouraged to instead
  416. // adjust the node directly within a hook_node_submit() implementation. For
  417. // Drupal 8, evaluate whether the pattern of triggering form-level submit
  418. // handlers during button-level submit processing is worth supporting
  419. // properly, and if so, add a Form API function for doing so.
  420. unset($form_state['submit_handlers']);
  421. form_execute_handlers('submit', $form, $form_state);
  422. $node = $form_state['node'];
  423. entity_form_submit_build_entity('node', $node, $form, $form_state);
  424. node_submit($node);
  425. foreach (module_implements('node_submit') as $module) {
  426. $function = $module . '_node_submit';
  427. $function($node, $form, $form_state);
  428. }
  429. return $node;
  430. }
  431. /**
  432. * Menu callback -- ask for confirmation of node deletion
  433. */
  434. function node_delete_confirm($form, &$form_state, $node) {
  435. $form['#node'] = $node;
  436. // Always provide entity id in the same form key as in the entity edit form.
  437. $form['nid'] = array('#type' => 'value', '#value' => $node->nid);
  438. return confirm_form($form,
  439. t('Are you sure you want to delete %title?', array('%title' => $node->title)),
  440. 'node/' . $node->nid,
  441. t('This action cannot be undone.'),
  442. t('Delete'),
  443. t('Cancel')
  444. );
  445. }
  446. /**
  447. * Execute node deletion
  448. */
  449. function node_delete_confirm_submit($form, &$form_state) {
  450. if ($form_state['values']['confirm']) {
  451. $node = node_load($form_state['values']['nid']);
  452. node_delete($form_state['values']['nid']);
  453. watchdog('content', '@type: deleted %title.', array('@type' => $node->type, '%title' => $node->title));
  454. drupal_set_message(t('@type %title has been deleted.', array('@type' => node_type_get_name($node), '%title' => $node->title)));
  455. }
  456. $form_state['redirect'] = '<front>';
  457. }
  458. /**
  459. * Generate an overview table of older revisions of a node.
  460. */
  461. function node_revision_overview($node) {
  462. drupal_set_title(t('Revisions for %title', array('%title' => $node->title)), PASS_THROUGH);
  463. $header = array(t('Revision'), array('data' => t('Operations'), 'colspan' => 2));
  464. $revisions = node_revision_list($node);
  465. $rows = array();
  466. $revert_permission = FALSE;
  467. if ((user_access('revert revisions') || user_access('administer nodes')) && node_access('update', $node)) {
  468. $revert_permission = TRUE;
  469. }
  470. $delete_permission = FALSE;
  471. if ((user_access('delete revisions') || user_access('administer nodes')) && node_access('delete', $node)) {
  472. $delete_permission = TRUE;
  473. }
  474. foreach ($revisions as $revision) {
  475. $row = array();
  476. $operations = array();
  477. if ($revision->current_vid > 0) {
  478. $row[] = array('data' => t('!date by !username', array('!date' => l(format_date($revision->timestamp, 'short'), "node/$node->nid"), '!username' => theme('username', array('account' => $revision))))
  479. . (($revision->log != '') ? '<p class="revision-log">' . filter_xss($revision->log) . '</p>' : ''),
  480. 'class' => array('revision-current'));
  481. $operations[] = array('data' => drupal_placeholder(t('current revision')), 'class' => array('revision-current'), 'colspan' => 2);
  482. }
  483. else {
  484. $row[] = t('!date by !username', array('!date' => l(format_date($revision->timestamp, 'short'), "node/$node->nid/revisions/$revision->vid/view"), '!username' => theme('username', array('account' => $revision))))
  485. . (($revision->log != '') ? '<p class="revision-log">' . filter_xss($revision->log) . '</p>' : '');
  486. if ($revert_permission) {
  487. $operations[] = l(t('revert'), "node/$node->nid/revisions/$revision->vid/revert");
  488. }
  489. if ($delete_permission) {
  490. $operations[] = l(t('delete'), "node/$node->nid/revisions/$revision->vid/delete");
  491. }
  492. }
  493. $rows[] = array_merge($row, $operations);
  494. }
  495. $build['node_revisions_table'] = array(
  496. '#theme' => 'table',
  497. '#rows' => $rows,
  498. '#header' => $header,
  499. );
  500. return $build;
  501. }
  502. /**
  503. * Ask for confirmation of the reversion to prevent against CSRF attacks.
  504. */
  505. function node_revision_revert_confirm($form, $form_state, $node_revision) {
  506. $form['#node_revision'] = $node_revision;
  507. return confirm_form($form, t('Are you sure you want to revert to the revision from %revision-date?', array('%revision-date' => format_date($node_revision->revision_timestamp))), 'node/' . $node_revision->nid . '/revisions', '', t('Revert'), t('Cancel'));
  508. }
  509. function node_revision_revert_confirm_submit($form, &$form_state) {
  510. $node_revision = $form['#node_revision'];
  511. $node_revision->revision = 1;
  512. $node_revision->log = t('Copy of the revision from %date.', array('%date' => format_date($node_revision->revision_timestamp)));
  513. node_save($node_revision);
  514. watchdog('content', '@type: reverted %title revision %revision.', array('@type' => $node_revision->type, '%title' => $node_revision->title, '%revision' => $node_revision->vid));
  515. drupal_set_message(t('@type %title has been reverted back to the revision from %revision-date.', array('@type' => node_type_get_name($node_revision), '%title' => $node_revision->title, '%revision-date' => format_date($node_revision->revision_timestamp))));
  516. $form_state['redirect'] = 'node/' . $node_revision->nid . '/revisions';
  517. }
  518. function node_revision_delete_confirm($form, $form_state, $node_revision) {
  519. $form['#node_revision'] = $node_revision;
  520. return confirm_form($form, t('Are you sure you want to delete the revision from %revision-date?', array('%revision-date' => format_date($node_revision->revision_timestamp))), 'node/' . $node_revision->nid . '/revisions', t('This action cannot be undone.'), t('Delete'), t('Cancel'));
  521. }
  522. function node_revision_delete_confirm_submit($form, &$form_state) {
  523. $node_revision = $form['#node_revision'];
  524. node_revision_delete($node_revision->vid);
  525. watchdog('content', '@type: deleted %title revision %revision.', array('@type' => $node_revision->type, '%title' => $node_revision->title, '%revision' => $node_revision->vid));
  526. drupal_set_message(t('Revision from %revision-date of @type %title has been deleted.', array('%revision-date' => format_date($node_revision->revision_timestamp), '@type' => node_type_get_name($node_revision), '%title' => $node_revision->title)));
  527. $form_state['redirect'] = 'node/' . $node_revision->nid;
  528. if (db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid', array(':nid' => $node_revision->nid))->fetchField() > 1) {
  529. $form_state['redirect'] .= '/revisions';
  530. }
  531. }