node.admin.inc

  1. 7.x drupal-7.x/modules/node/node.admin.inc
  2. 6.x drupal-6.x/modules/node/node.admin.inc

Content administration and module settings UI.

File

drupal-7.x/modules/node/node.admin.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Content administration and module settings UI.
  5. */
  6. /**
  7. * Menu callback: confirm rebuilding of permissions.
  8. *
  9. * @see node_configure_rebuild_confirm_submit()
  10. * @see node_menu()
  11. * @ingroup forms
  12. */
  13. function node_configure_rebuild_confirm() {
  14. return confirm_form(array(), t('Are you sure you want to rebuild the permissions on site content?'),
  15. 'admin/reports/status', t('This action rebuilds all permissions on site content, and may be a lengthy process. This action cannot be undone.'), t('Rebuild permissions'), t('Cancel'));
  16. }
  17. /**
  18. * Handler for wipe confirmation
  19. *
  20. * @see node_configure_rebuild_confirm()
  21. */
  22. function node_configure_rebuild_confirm_submit($form, &$form_state) {
  23. node_access_rebuild(TRUE);
  24. $form_state['redirect'] = 'admin/reports/status';
  25. }
  26. /**
  27. * Implements hook_node_operations().
  28. */
  29. function node_node_operations() {
  30. $operations = array(
  31. 'publish' => array(
  32. 'label' => t('Publish selected content'),
  33. 'callback' => 'node_mass_update',
  34. 'callback arguments' => array('updates' => array('status' => NODE_PUBLISHED)),
  35. ),
  36. 'unpublish' => array(
  37. 'label' => t('Unpublish selected content'),
  38. 'callback' => 'node_mass_update',
  39. 'callback arguments' => array('updates' => array('status' => NODE_NOT_PUBLISHED)),
  40. ),
  41. 'promote' => array(
  42. 'label' => t('Promote selected content to front page'),
  43. 'callback' => 'node_mass_update',
  44. 'callback arguments' => array('updates' => array('status' => NODE_PUBLISHED, 'promote' => NODE_PROMOTED)),
  45. ),
  46. 'demote' => array(
  47. 'label' => t('Demote selected content from front page'),
  48. 'callback' => 'node_mass_update',
  49. 'callback arguments' => array('updates' => array('promote' => NODE_NOT_PROMOTED)),
  50. ),
  51. 'sticky' => array(
  52. 'label' => t('Make selected content sticky'),
  53. 'callback' => 'node_mass_update',
  54. 'callback arguments' => array('updates' => array('status' => NODE_PUBLISHED, 'sticky' => NODE_STICKY)),
  55. ),
  56. 'unsticky' => array(
  57. 'label' => t('Make selected content not sticky'),
  58. 'callback' => 'node_mass_update',
  59. 'callback arguments' => array('updates' => array('sticky' => NODE_NOT_STICKY)),
  60. ),
  61. 'delete' => array(
  62. 'label' => t('Delete selected content'),
  63. 'callback' => NULL,
  64. ),
  65. );
  66. return $operations;
  67. }
  68. /**
  69. * List node administration filters that can be applied.
  70. *
  71. * @return
  72. * An associative array of filters.
  73. */
  74. function node_filters() {
  75. // Regular filters
  76. $filters['status'] = array(
  77. 'title' => t('status'),
  78. 'options' => array(
  79. '[any]' => t('any'),
  80. 'status-1' => t('published'),
  81. 'status-0' => t('not published'),
  82. 'promote-1' => t('promoted'),
  83. 'promote-0' => t('not promoted'),
  84. 'sticky-1' => t('sticky'),
  85. 'sticky-0' => t('not sticky'),
  86. ),
  87. );
  88. // Include translation states if we have this module enabled
  89. if (module_exists('translation')) {
  90. $filters['status']['options'] += array(
  91. 'translate-0' => t('Up to date translation'),
  92. 'translate-1' => t('Outdated translation'),
  93. );
  94. }
  95. $filters['type'] = array(
  96. 'title' => t('type'),
  97. 'options' => array(
  98. '[any]' => t('any'),
  99. ) + node_type_get_names(),
  100. );
  101. // Language filter if there is a list of languages
  102. if ($languages = module_invoke('locale', 'language_list')) {
  103. $languages = array(LANGUAGE_NONE => t('Language neutral')) + $languages;
  104. $filters['language'] = array(
  105. 'title' => t('language'),
  106. 'options' => array(
  107. '[any]' => t('any'),
  108. ) + $languages,
  109. );
  110. }
  111. return $filters;
  112. }
  113. /**
  114. * Applies filters for node administration filters based on session.
  115. *
  116. * @param $query
  117. * A SelectQuery to which the filters should be applied.
  118. */
  119. function node_build_filter_query(SelectQueryInterface $query) {
  120. // Build query
  121. $filter_data = isset($_SESSION['node_overview_filter']) ? $_SESSION['node_overview_filter'] : array();
  122. foreach ($filter_data as $index => $filter) {
  123. list($key, $value) = $filter;
  124. switch ($key) {
  125. case 'status':
  126. // Note: no exploitable hole as $key/$value have already been checked when submitted
  127. list($key, $value) = explode('-', $value, 2);
  128. case 'type':
  129. case 'language':
  130. $query->condition('n.' . $key, $value);
  131. break;
  132. }
  133. }
  134. }
  135. /**
  136. * Returns the node administration filters form array to node_admin_content().
  137. *
  138. * @see node_admin_nodes()
  139. * @see node_admin_nodes_submit()
  140. * @see node_admin_nodes_validate()
  141. * @see node_filter_form_submit()
  142. * @see node_multiple_delete_confirm()
  143. * @see node_multiple_delete_confirm_submit()
  144. *
  145. * @ingroup forms
  146. */
  147. function node_filter_form() {
  148. $session = isset($_SESSION['node_overview_filter']) ? $_SESSION['node_overview_filter'] : array();
  149. $filters = node_filters();
  150. $i = 0;
  151. $form['filters'] = array(
  152. '#type' => 'fieldset',
  153. '#title' => t('Show only items where'),
  154. '#theme' => 'exposed_filters__node',
  155. );
  156. foreach ($session as $filter) {
  157. list($type, $value) = $filter;
  158. if ($type == 'term') {
  159. // Load term name from DB rather than search and parse options array.
  160. $value = module_invoke('taxonomy', 'term_load', $value);
  161. $value = $value->name;
  162. }
  163. elseif ($type == 'language') {
  164. $value = $value == LANGUAGE_NONE ? t('Language neutral') : module_invoke('locale', 'language_name', $value);
  165. }
  166. else {
  167. $value = $filters[$type]['options'][$value];
  168. }
  169. $t_args = array('%property' => $filters[$type]['title'], '%value' => $value);
  170. if ($i++) {
  171. $form['filters']['current'][] = array('#markup' => t('and where %property is %value', $t_args));
  172. }
  173. else {
  174. $form['filters']['current'][] = array('#markup' => t('where %property is %value', $t_args));
  175. }
  176. if (in_array($type, array('type', 'language'))) {
  177. // Remove the option if it is already being filtered on.
  178. unset($filters[$type]);
  179. }
  180. }
  181. $form['filters']['status'] = array(
  182. '#type' => 'container',
  183. '#attributes' => array('class' => array('clearfix')),
  184. '#prefix' => ($i ? '<div class="additional-filters">' . t('and where') . '</div>' : ''),
  185. );
  186. $form['filters']['status']['filters'] = array(
  187. '#type' => 'container',
  188. '#attributes' => array('class' => array('filters')),
  189. );
  190. foreach ($filters as $key => $filter) {
  191. $form['filters']['status']['filters'][$key] = array(
  192. '#type' => 'select',
  193. '#options' => $filter['options'],
  194. '#title' => $filter['title'],
  195. '#default_value' => '[any]',
  196. );
  197. }
  198. $form['filters']['status']['actions'] = array(
  199. '#type' => 'actions',
  200. '#attributes' => array('class' => array('container-inline')),
  201. );
  202. $form['filters']['status']['actions']['submit'] = array(
  203. '#type' => 'submit',
  204. '#value' => count($session) ? t('Refine') : t('Filter'),
  205. );
  206. if (count($session)) {
  207. $form['filters']['status']['actions']['undo'] = array('#type' => 'submit', '#value' => t('Undo'));
  208. $form['filters']['status']['actions']['reset'] = array('#type' => 'submit', '#value' => t('Reset'));
  209. }
  210. drupal_add_js('misc/form.js');
  211. return $form;
  212. }
  213. /**
  214. * Form submission handler for node_filter_form().
  215. *
  216. * @see node_admin_content()
  217. * @see node_admin_nodes()
  218. * @see node_admin_nodes_submit()
  219. * @see node_admin_nodes_validate()
  220. * @see node_filter_form()
  221. * @see node_multiple_delete_confirm()
  222. * @see node_multiple_delete_confirm_submit()
  223. */
  224. function node_filter_form_submit($form, &$form_state) {
  225. $filters = node_filters();
  226. switch ($form_state['values']['op']) {
  227. case t('Filter'):
  228. case t('Refine'):
  229. // Apply every filter that has a choice selected other than 'any'.
  230. foreach ($filters as $filter => $options) {
  231. if (isset($form_state['values'][$filter]) && $form_state['values'][$filter] != '[any]') {
  232. // Flatten the options array to accommodate hierarchical/nested options.
  233. $flat_options = form_options_flatten($filters[$filter]['options']);
  234. // Only accept valid selections offered on the dropdown, block bad input.
  235. if (isset($flat_options[$form_state['values'][$filter]])) {
  236. $_SESSION['node_overview_filter'][] = array($filter, $form_state['values'][$filter]);
  237. }
  238. }
  239. }
  240. break;
  241. case t('Undo'):
  242. array_pop($_SESSION['node_overview_filter']);
  243. break;
  244. case t('Reset'):
  245. $_SESSION['node_overview_filter'] = array();
  246. break;
  247. }
  248. }
  249. /**
  250. * Make mass update of nodes, changing all nodes in the $nodes array
  251. * to update them with the field values in $updates.
  252. *
  253. * IMPORTANT NOTE: This function is intended to work when called from a form
  254. * submission handler. Calling it outside of the form submission process may not
  255. * work correctly.
  256. *
  257. * @param array $nodes
  258. * Array of node nids to update.
  259. * @param array $updates
  260. * Array of key/value pairs with node field names and the value to update that
  261. * field to.
  262. */
  263. function node_mass_update($nodes, $updates) {
  264. // We use batch processing to prevent timeout when updating a large number
  265. // of nodes.
  266. if (count($nodes) > 10) {
  267. $batch = array(
  268. 'operations' => array(
  269. array('_node_mass_update_batch_process', array($nodes, $updates))
  270. ),
  271. 'finished' => '_node_mass_update_batch_finished',
  272. 'title' => t('Processing'),
  273. // We use a single multi-pass operation, so the default
  274. // 'Remaining x of y operations' message will be confusing here.
  275. 'progress_message' => '',
  276. 'error_message' => t('The update has encountered an error.'),
  277. // The operations do not live in the .module file, so we need to
  278. // tell the batch engine which file to load before calling them.
  279. 'file' => drupal_get_path('module', 'node') . '/node.admin.inc',
  280. );
  281. batch_set($batch);
  282. }
  283. else {
  284. foreach ($nodes as $nid) {
  285. _node_mass_update_helper($nid, $updates);
  286. }
  287. drupal_set_message(t('The update has been performed.'));
  288. }
  289. }
  290. /**
  291. * Updates individual nodes when fewer than 10 are queued.
  292. *
  293. * @param $nid
  294. * ID of node to update.
  295. * @param $updates
  296. * Associative array of updates.
  297. *
  298. * @return object
  299. * An updated node object.
  300. *
  301. * @see node_mass_update()
  302. */
  303. function _node_mass_update_helper($nid, $updates) {
  304. $node = node_load($nid, NULL, TRUE);
  305. // For efficiency manually save the original node before applying any changes.
  306. $node->original = clone $node;
  307. foreach ($updates as $name => $value) {
  308. $node->$name = $value;
  309. }
  310. node_save($node);
  311. return $node;
  312. }
  313. /**
  314. * Executes a batch operation for node_mass_update().
  315. *
  316. * @param array $nodes
  317. * An array of node IDs.
  318. * @param array $updates
  319. * Associative array of updates.
  320. * @param array $context
  321. * An array of contextual key/values.
  322. */
  323. function _node_mass_update_batch_process($nodes, $updates, &$context) {
  324. if (!isset($context['sandbox']['progress'])) {
  325. $context['sandbox']['progress'] = 0;
  326. $context['sandbox']['max'] = count($nodes);
  327. $context['sandbox']['nodes'] = $nodes;
  328. }
  329. // Process nodes by groups of 5.
  330. $count = min(5, count($context['sandbox']['nodes']));
  331. for ($i = 1; $i <= $count; $i++) {
  332. // For each nid, load the node, reset the values, and save it.
  333. $nid = array_shift($context['sandbox']['nodes']);
  334. $node = _node_mass_update_helper($nid, $updates);
  335. // Store result for post-processing in the finished callback.
  336. $context['results'][] = l($node->title, 'node/' . $node->nid);
  337. // Update our progress information.
  338. $context['sandbox']['progress']++;
  339. }
  340. // Inform the batch engine that we are not finished,
  341. // and provide an estimation of the completion level we reached.
  342. if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
  343. $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
  344. }
  345. }
  346. /**
  347. * Menu callback: Reports the status of batch operation for node_mass_update().
  348. *
  349. * @param bool $success
  350. * A boolean indicating whether the batch mass update operation successfully
  351. * concluded.
  352. * @param int $results
  353. * The number of nodes updated via the batch mode process.
  354. * @param array $operations
  355. * An array of function calls (not used in this function).
  356. */
  357. function _node_mass_update_batch_finished($success, $results, $operations) {
  358. if ($success) {
  359. drupal_set_message(t('The update has been performed.'));
  360. }
  361. else {
  362. drupal_set_message(t('An error occurred and processing did not complete.'), 'error');
  363. $message = format_plural(count($results), '1 item successfully processed:', '@count items successfully processed:');
  364. $message .= theme('item_list', array('items' => $results));
  365. drupal_set_message($message);
  366. }
  367. }
  368. /**
  369. * Page callback: Form constructor for the content administration form.
  370. *
  371. * @see node_admin_nodes()
  372. * @see node_admin_nodes_submit()
  373. * @see node_admin_nodes_validate()
  374. * @see node_filter_form()
  375. * @see node_filter_form_submit()
  376. * @see node_menu()
  377. * @see node_multiple_delete_confirm()
  378. * @see node_multiple_delete_confirm_submit()
  379. * @ingroup forms
  380. */
  381. function node_admin_content($form, $form_state) {
  382. if (isset($form_state['values']['operation']) && $form_state['values']['operation'] == 'delete') {
  383. return node_multiple_delete_confirm($form, $form_state, array_filter($form_state['values']['nodes']));
  384. }
  385. $form['filter'] = node_filter_form();
  386. $form['#submit'][] = 'node_filter_form_submit';
  387. $form['admin'] = node_admin_nodes();
  388. return $form;
  389. }
  390. /**
  391. * Form builder: Builds the node administration overview.
  392. *
  393. * @see node_admin_nodes_submit()
  394. * @see node_admin_nodes_validate()
  395. * @see node_filter_form()
  396. * @see node_filter_form_submit()
  397. * @see node_multiple_delete_confirm()
  398. * @see node_multiple_delete_confirm_submit()
  399. *
  400. * @ingroup forms
  401. */
  402. function node_admin_nodes() {
  403. $admin_access = user_access('administer nodes');
  404. // Build the 'Update options' form.
  405. $form['options'] = array(
  406. '#type' => 'fieldset',
  407. '#title' => t('Update options'),
  408. '#attributes' => array('class' => array('container-inline')),
  409. '#access' => $admin_access,
  410. );
  411. $options = array();
  412. foreach (module_invoke_all('node_operations') as $operation => $array) {
  413. $options[$operation] = $array['label'];
  414. }
  415. $form['options']['operation'] = array(
  416. '#type' => 'select',
  417. '#title' => t('Operation'),
  418. '#title_display' => 'invisible',
  419. '#options' => $options,
  420. '#default_value' => 'approve',
  421. );
  422. $form['options']['submit'] = array(
  423. '#type' => 'submit',
  424. '#value' => t('Update'),
  425. '#validate' => array('node_admin_nodes_validate'),
  426. '#submit' => array('node_admin_nodes_submit'),
  427. );
  428. // Enable language column if translation module is enabled or if we have any
  429. // node with language.
  430. $multilanguage = (module_exists('translation') || db_query_range("SELECT 1 FROM {node} WHERE language <> :language", 0, 1, array(':language' => LANGUAGE_NONE))->fetchField());
  431. // Build the sortable table header.
  432. $header = array(
  433. 'title' => array('data' => t('Title'), 'field' => 'n.title'),
  434. 'type' => array('data' => t('Type'), 'field' => 'n.type'),
  435. 'author' => t('Author'),
  436. 'status' => array('data' => t('Status'), 'field' => 'n.status'),
  437. 'changed' => array('data' => t('Updated'), 'field' => 'n.changed', 'sort' => 'desc')
  438. );
  439. if ($multilanguage) {
  440. $header['language'] = array('data' => t('Language'), 'field' => 'n.language');
  441. }
  442. $header['operations'] = array('data' => t('Operations'));
  443. $query = db_select('node', 'n')->extend('PagerDefault')->extend('TableSort');
  444. node_build_filter_query($query);
  445. if (!user_access('bypass node access')) {
  446. // If the user is able to view their own unpublished nodes, allow them
  447. // to see these in addition to published nodes. Check that they actually
  448. // have some unpublished nodes to view before adding the condition.
  449. if (user_access('view own unpublished content') && $own_unpublished = db_query('SELECT nid FROM {node} WHERE uid = :uid AND status = :status', array(':uid' => $GLOBALS['user']->uid, ':status' => 0))->fetchCol()) {
  450. $query->condition(db_or()
  451. ->condition('n.status', 1)
  452. ->condition('n.nid', $own_unpublished, 'IN')
  453. );
  454. }
  455. else {
  456. // If not, restrict the query to published nodes.
  457. $query->condition('n.status', 1);
  458. }
  459. }
  460. $nids = $query
  461. ->fields('n',array('nid'))
  462. ->limit(50)
  463. ->orderByHeader($header)
  464. ->addTag('node_access')
  465. ->execute()
  466. ->fetchCol();
  467. $nodes = node_load_multiple($nids);
  468. // Prepare the list of nodes.
  469. $languages = language_list();
  470. $destination = drupal_get_destination();
  471. $options = array();
  472. foreach ($nodes as $node) {
  473. $langcode = entity_language('node', $node);
  474. $l_options = $langcode != LANGUAGE_NONE && isset($languages[$langcode]) ? array('language' => $languages[$langcode]) : array();
  475. $options[$node->nid] = array(
  476. 'title' => array(
  477. 'data' => array(
  478. '#type' => 'link',
  479. '#title' => $node->title,
  480. '#href' => 'node/' . $node->nid,
  481. '#options' => $l_options,
  482. '#suffix' => ' ' . theme('mark', array('type' => node_mark($node->nid, $node->changed))),
  483. ),
  484. ),
  485. 'type' => check_plain(node_type_get_name($node)),
  486. 'author' => theme('username', array('account' => $node)),
  487. 'status' => $node->status ? t('published') : t('not published'),
  488. 'changed' => format_date($node->changed, 'short'),
  489. );
  490. if ($multilanguage) {
  491. if ($langcode == LANGUAGE_NONE || isset($languages[$langcode])) {
  492. $options[$node->nid]['language'] = $langcode == LANGUAGE_NONE ? t('Language neutral') : t($languages[$langcode]->name);
  493. }
  494. else {
  495. $options[$node->nid]['language'] = t('Undefined language (@langcode)', array('@langcode' => $langcode));
  496. }
  497. }
  498. // Build a list of all the accessible operations for the current node.
  499. $operations = array();
  500. if (node_access('update', $node)) {
  501. $operations['edit'] = array(
  502. 'title' => t('edit'),
  503. 'href' => 'node/' . $node->nid . '/edit',
  504. 'query' => $destination,
  505. );
  506. }
  507. if (node_access('delete', $node)) {
  508. $operations['delete'] = array(
  509. 'title' => t('delete'),
  510. 'href' => 'node/' . $node->nid . '/delete',
  511. 'query' => $destination,
  512. );
  513. }
  514. $options[$node->nid]['operations'] = array();
  515. if (count($operations) > 1) {
  516. // Render an unordered list of operations links.
  517. $options[$node->nid]['operations'] = array(
  518. 'data' => array(
  519. '#theme' => 'links__node_operations',
  520. '#links' => $operations,
  521. '#attributes' => array('class' => array('links', 'inline')),
  522. ),
  523. );
  524. }
  525. elseif (!empty($operations)) {
  526. // Render the first and only operation as a link.
  527. $link = reset($operations);
  528. $options[$node->nid]['operations'] = array(
  529. 'data' => array(
  530. '#type' => 'link',
  531. '#title' => $link['title'],
  532. '#href' => $link['href'],
  533. '#options' => array('query' => $link['query']),
  534. ),
  535. );
  536. }
  537. }
  538. // Only use a tableselect when the current user is able to perform any
  539. // operations.
  540. if ($admin_access) {
  541. $form['nodes'] = array(
  542. '#type' => 'tableselect',
  543. '#header' => $header,
  544. '#options' => $options,
  545. '#empty' => t('No content available.'),
  546. );
  547. }
  548. // Otherwise, use a simple table.
  549. else {
  550. $form['nodes'] = array(
  551. '#theme' => 'table',
  552. '#header' => $header,
  553. '#rows' => $options,
  554. '#empty' => t('No content available.'),
  555. );
  556. }
  557. $form['pager'] = array('#markup' => theme('pager'));
  558. return $form;
  559. }
  560. /**
  561. * Validate node_admin_nodes form submissions.
  562. *
  563. * Checks whether any nodes have been selected to perform the chosen 'Update
  564. * option' on.
  565. *
  566. * @see node_admin_nodes()
  567. * @see node_admin_nodes_submit()
  568. * @see node_filter_form()
  569. * @see node_filter_form_submit()
  570. * @see node_multiple_delete_confirm()
  571. * @see node_multiple_delete_confirm_submit()
  572. */
  573. function node_admin_nodes_validate($form, &$form_state) {
  574. // Error if there are no items to select.
  575. if (!is_array($form_state['values']['nodes']) || !count(array_filter($form_state['values']['nodes']))) {
  576. form_set_error('', t('No items selected.'));
  577. }
  578. }
  579. /**
  580. * Process node_admin_nodes form submissions.
  581. *
  582. * Executes the chosen 'Update option' on the selected nodes.
  583. *
  584. * @see node_admin_nodes()
  585. * @see node_admin_nodes_validate()
  586. * @see node_filter_form()
  587. * @see node_filter_form_submit()
  588. * @see node_multiple_delete_confirm()
  589. * @see node_multiple_delete_confirm_submit()
  590. */
  591. function node_admin_nodes_submit($form, &$form_state) {
  592. $operations = module_invoke_all('node_operations');
  593. $operation = $operations[$form_state['values']['operation']];
  594. // Filter out unchecked nodes
  595. $nodes = array_filter($form_state['values']['nodes']);
  596. if ($function = $operation['callback']) {
  597. // Add in callback arguments if present.
  598. if (isset($operation['callback arguments'])) {
  599. $args = array_merge(array($nodes), $operation['callback arguments']);
  600. }
  601. else {
  602. $args = array($nodes);
  603. }
  604. call_user_func_array($function, $args);
  605. cache_clear_all();
  606. }
  607. else {
  608. // We need to rebuild the form to go to a second step. For example, to
  609. // show the confirmation form for the deletion of nodes.
  610. $form_state['rebuild'] = TRUE;
  611. }
  612. }
  613. /**
  614. * Multiple node deletion confirmation form for node_admin_content().
  615. *
  616. * @see node_admin_nodes()
  617. * @see node_admin_nodes_submit()
  618. * @see node_admin_nodes_validate()
  619. * @see node_filter_form()
  620. * @see node_filter_form_submit()
  621. * @see node_multiple_delete_confirm_submit()
  622. * @ingroup forms
  623. */
  624. function node_multiple_delete_confirm($form, &$form_state, $nodes) {
  625. $form['nodes'] = array('#prefix' => '<ul>', '#suffix' => '</ul>', '#tree' => TRUE);
  626. // array_filter returns only elements with TRUE values
  627. foreach ($nodes as $nid => $value) {
  628. $title = db_query('SELECT title FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchField();
  629. $form['nodes'][$nid] = array(
  630. '#type' => 'hidden',
  631. '#value' => $nid,
  632. '#prefix' => '<li>',
  633. '#suffix' => check_plain($title) . "</li>\n",
  634. );
  635. }
  636. $form['operation'] = array('#type' => 'hidden', '#value' => 'delete');
  637. $form['#submit'][] = 'node_multiple_delete_confirm_submit';
  638. $confirm_question = format_plural(count($nodes),
  639. 'Are you sure you want to delete this item?',
  640. 'Are you sure you want to delete these items?');
  641. return confirm_form($form,
  642. $confirm_question,
  643. 'admin/content', t('This action cannot be undone.'),
  644. t('Delete'), t('Cancel'));
  645. }
  646. /**
  647. * Form submission handler for node_multiple_delete_confirm().
  648. *
  649. * @see node_admin_nodes()
  650. * @see node_admin_nodes_submit()
  651. * @see node_admin_nodes_validate()
  652. * @see node_filter_form()
  653. * @see node_filter_form_submit()
  654. * @see node_multiple_delete_confirm()
  655. */
  656. function node_multiple_delete_confirm_submit($form, &$form_state) {
  657. if ($form_state['values']['confirm']) {
  658. node_delete_multiple(array_keys($form_state['values']['nodes']));
  659. cache_clear_all();
  660. $count = count($form_state['values']['nodes']);
  661. watchdog('content', 'Deleted @count posts.', array('@count' => $count));
  662. drupal_set_message(format_plural($count, 'Deleted 1 post.', 'Deleted @count posts.'));
  663. }
  664. $form_state['redirect'] = 'admin/content';
  665. }