1. 8.3.x core/modules/node/node.admin.inc
  2. 8.0.x core/modules/node/node.admin.inc
  3. 8.1.x core/modules/node/node.admin.inc
  4. 8.2.x core/modules/node/node.admin.inc
  5. 8.4.x core/modules/node/node.admin.inc
  6. 6.x modules/node/node.admin.inc
  7. 7.x modules/node/node.admin.inc

Content administration and module settings UI.

File

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. * Implements callback_batch_operation().
  315. *
  316. * Executes a batch operation for node_mass_update().
  317. *
  318. * @param array $nodes
  319. * An array of node IDs.
  320. * @param array $updates
  321. * Associative array of updates.
  322. * @param array $context
  323. * An array of contextual key/values.
  324. */
  325. function _node_mass_update_batch_process($nodes, $updates, &$context) {
  326. if (!isset($context['sandbox']['progress'])) {
  327. $context['sandbox']['progress'] = 0;
  328. $context['sandbox']['max'] = count($nodes);
  329. $context['sandbox']['nodes'] = $nodes;
  330. }
  331. // Process nodes by groups of 5.
  332. $count = min(5, count($context['sandbox']['nodes']));
  333. for ($i = 1; $i <= $count; $i++) {
  334. // For each nid, load the node, reset the values, and save it.
  335. $nid = array_shift($context['sandbox']['nodes']);
  336. $node = _node_mass_update_helper($nid, $updates);
  337. // Store result for post-processing in the finished callback.
  338. $context['results'][] = l($node->title, 'node/' . $node->nid);
  339. // Update our progress information.
  340. $context['sandbox']['progress']++;
  341. }
  342. // Inform the batch engine that we are not finished,
  343. // and provide an estimation of the completion level we reached.
  344. if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
  345. $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
  346. }
  347. }
  348. /**
  349. * Implements callback_batch_finished().
  350. *
  351. * Reports the status of batch operation for node_mass_update().
  352. *
  353. * @param bool $success
  354. * A boolean indicating whether the batch mass update operation successfully
  355. * concluded.
  356. * @param int $results
  357. * The number of nodes updated via the batch mode process.
  358. * @param array $operations
  359. * An array of function calls (not used in this function).
  360. */
  361. function _node_mass_update_batch_finished($success, $results, $operations) {
  362. if ($success) {
  363. drupal_set_message(t('The update has been performed.'));
  364. }
  365. else {
  366. drupal_set_message(t('An error occurred and processing did not complete.'), 'error');
  367. $message = format_plural(count($results), '1 item successfully processed:', '@count items successfully processed:');
  368. $message .= theme('item_list', array('items' => $results));
  369. drupal_set_message($message);
  370. }
  371. }
  372. /**
  373. * Page callback: Form constructor for the content administration form.
  374. *
  375. * @see node_admin_nodes()
  376. * @see node_admin_nodes_submit()
  377. * @see node_admin_nodes_validate()
  378. * @see node_filter_form()
  379. * @see node_filter_form_submit()
  380. * @see node_menu()
  381. * @see node_multiple_delete_confirm()
  382. * @see node_multiple_delete_confirm_submit()
  383. * @ingroup forms
  384. */
  385. function node_admin_content($form, $form_state) {
  386. if (isset($form_state['values']['operation']) && $form_state['values']['operation'] == 'delete') {
  387. return node_multiple_delete_confirm($form, $form_state, array_filter($form_state['values']['nodes']));
  388. }
  389. $form['filter'] = node_filter_form();
  390. $form['#submit'][] = 'node_filter_form_submit';
  391. $form['admin'] = node_admin_nodes();
  392. return $form;
  393. }
  394. /**
  395. * Form builder: Builds the node administration overview.
  396. *
  397. * @see node_admin_nodes_submit()
  398. * @see node_admin_nodes_validate()
  399. * @see node_filter_form()
  400. * @see node_filter_form_submit()
  401. * @see node_multiple_delete_confirm()
  402. * @see node_multiple_delete_confirm_submit()
  403. *
  404. * @ingroup forms
  405. */
  406. function node_admin_nodes() {
  407. $admin_access = user_access('administer nodes');
  408. // Build the 'Update options' form.
  409. $form['options'] = array(
  410. '#type' => 'fieldset',
  411. '#title' => t('Update options'),
  412. '#attributes' => array('class' => array('container-inline')),
  413. '#access' => $admin_access,
  414. );
  415. $options = array();
  416. foreach (module_invoke_all('node_operations') as $operation => $array) {
  417. $options[$operation] = $array['label'];
  418. }
  419. $form['options']['operation'] = array(
  420. '#type' => 'select',
  421. '#title' => t('Operation'),
  422. '#title_display' => 'invisible',
  423. '#options' => $options,
  424. '#default_value' => 'approve',
  425. );
  426. $form['options']['submit'] = array(
  427. '#type' => 'submit',
  428. '#value' => t('Update'),
  429. '#validate' => array('node_admin_nodes_validate'),
  430. '#submit' => array('node_admin_nodes_submit'),
  431. );
  432. // Enable language column if translation module is enabled or if we have any
  433. // node with language.
  434. $multilanguage = (module_exists('translation') || db_query_range("SELECT 1 FROM {node} WHERE language <> :language", 0, 1, array(':language' => LANGUAGE_NONE))->fetchField());
  435. // Build the sortable table header.
  436. $header = array(
  437. 'title' => array('data' => t('Title'), 'field' => 'n.title'),
  438. 'type' => array('data' => t('Type'), 'field' => 'n.type'),
  439. 'author' => t('Author'),
  440. 'status' => array('data' => t('Status'), 'field' => 'n.status'),
  441. 'changed' => array('data' => t('Updated'), 'field' => 'n.changed', 'sort' => 'desc')
  442. );
  443. if ($multilanguage) {
  444. $header['language'] = array('data' => t('Language'), 'field' => 'n.language');
  445. }
  446. $header['operations'] = array('data' => t('Operations'));
  447. $query = db_select('node', 'n')->extend('PagerDefault')->extend('TableSort');
  448. $query->addTag('node_admin_filter');
  449. node_build_filter_query($query);
  450. if (!user_access('bypass node access')) {
  451. // If the user is able to view their own unpublished nodes, allow them
  452. // to see these in addition to published nodes. Check that they actually
  453. // have some unpublished nodes to view before adding the condition.
  454. 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()) {
  455. $query->condition(db_or()
  456. ->condition('n.status', 1)
  457. ->condition('n.nid', $own_unpublished, 'IN')
  458. );
  459. }
  460. else {
  461. // If not, restrict the query to published nodes.
  462. $query->condition('n.status', 1);
  463. }
  464. }
  465. $nids = $query
  466. ->fields('n',array('nid'))
  467. ->limit(50)
  468. ->orderByHeader($header)
  469. ->addTag('node_access')
  470. ->execute()
  471. ->fetchCol();
  472. $nodes = node_load_multiple($nids);
  473. // Prepare the list of nodes.
  474. $languages = language_list();
  475. $destination = drupal_get_destination();
  476. $options = array();
  477. foreach ($nodes as $node) {
  478. $langcode = entity_language('node', $node);
  479. $uri = entity_uri('node', $node);
  480. if ($langcode != LANGUAGE_NONE && isset($languages[$langcode])) {
  481. $uri['options']['language'] = $languages[$langcode];
  482. }
  483. $options[$node->nid] = array(
  484. 'title' => array(
  485. 'data' => array(
  486. '#type' => 'link',
  487. '#title' => $node->title,
  488. '#href' => $uri['path'],
  489. '#options' => $uri['options'],
  490. '#suffix' => ' ' . theme('mark', array('type' => node_mark($node->nid, $node->changed))),
  491. ),
  492. ),
  493. 'type' => check_plain(node_type_get_name($node)),
  494. 'author' => theme('username', array('account' => $node)),
  495. 'status' => $node->status ? t('published') : t('not published'),
  496. 'changed' => format_date($node->changed, 'short'),
  497. );
  498. if ($multilanguage) {
  499. if ($langcode == LANGUAGE_NONE || isset($languages[$langcode])) {
  500. $options[$node->nid]['language'] = $langcode == LANGUAGE_NONE ? t('Language neutral') : t($languages[$langcode]->name);
  501. }
  502. else {
  503. $options[$node->nid]['language'] = t('Undefined language (@langcode)', array('@langcode' => $langcode));
  504. }
  505. }
  506. // Build a list of all the accessible operations for the current node.
  507. $operations = array();
  508. if (node_access('update', $node)) {
  509. $operations['edit'] = array(
  510. 'title' => t('edit'),
  511. 'href' => 'node/' . $node->nid . '/edit',
  512. 'query' => $destination,
  513. );
  514. }
  515. if (node_access('delete', $node)) {
  516. $operations['delete'] = array(
  517. 'title' => t('delete'),
  518. 'href' => 'node/' . $node->nid . '/delete',
  519. 'query' => $destination,
  520. );
  521. }
  522. $options[$node->nid]['operations'] = array();
  523. if (count($operations) > 1) {
  524. // Render an unordered list of operations links.
  525. $options[$node->nid]['operations'] = array(
  526. 'data' => array(
  527. '#theme' => 'links__node_operations',
  528. '#links' => $operations,
  529. '#attributes' => array('class' => array('links', 'inline')),
  530. ),
  531. );
  532. }
  533. elseif (!empty($operations)) {
  534. // Render the first and only operation as a link.
  535. $link = reset($operations);
  536. $options[$node->nid]['operations'] = array(
  537. 'data' => array(
  538. '#type' => 'link',
  539. '#title' => $link['title'],
  540. '#href' => $link['href'],
  541. '#options' => array('query' => $link['query']),
  542. ),
  543. );
  544. }
  545. }
  546. // Only use a tableselect when the current user is able to perform any
  547. // operations.
  548. if ($admin_access) {
  549. $form['nodes'] = array(
  550. '#type' => 'tableselect',
  551. '#header' => $header,
  552. '#options' => $options,
  553. '#empty' => t('No content available.'),
  554. );
  555. }
  556. // Otherwise, use a simple table.
  557. else {
  558. $form['nodes'] = array(
  559. '#theme' => 'table',
  560. '#header' => $header,
  561. '#rows' => $options,
  562. '#empty' => t('No content available.'),
  563. );
  564. }
  565. $form['pager'] = array('#markup' => theme('pager'));
  566. return $form;
  567. }
  568. /**
  569. * Validate node_admin_nodes form submissions.
  570. *
  571. * Checks whether any nodes have been selected to perform the chosen 'Update
  572. * option' on.
  573. *
  574. * @see node_admin_nodes()
  575. * @see node_admin_nodes_submit()
  576. * @see node_filter_form()
  577. * @see node_filter_form_submit()
  578. * @see node_multiple_delete_confirm()
  579. * @see node_multiple_delete_confirm_submit()
  580. */
  581. function node_admin_nodes_validate($form, &$form_state) {
  582. // Error if there are no items to select.
  583. if (!is_array($form_state['values']['nodes']) || !count(array_filter($form_state['values']['nodes']))) {
  584. form_set_error('', t('No items selected.'));
  585. }
  586. }
  587. /**
  588. * Process node_admin_nodes form submissions.
  589. *
  590. * Executes the chosen 'Update option' on the selected nodes.
  591. *
  592. * @see node_admin_nodes()
  593. * @see node_admin_nodes_validate()
  594. * @see node_filter_form()
  595. * @see node_filter_form_submit()
  596. * @see node_multiple_delete_confirm()
  597. * @see node_multiple_delete_confirm_submit()
  598. */
  599. function node_admin_nodes_submit($form, &$form_state) {
  600. $operations = module_invoke_all('node_operations');
  601. $operation = $operations[$form_state['values']['operation']];
  602. // Filter out unchecked nodes
  603. $nodes = array_filter($form_state['values']['nodes']);
  604. if ($function = $operation['callback']) {
  605. // Add in callback arguments if present.
  606. if (isset($operation['callback arguments'])) {
  607. $args = array_merge(array($nodes), $operation['callback arguments']);
  608. }
  609. else {
  610. $args = array($nodes);
  611. }
  612. call_user_func_array($function, $args);
  613. cache_clear_all();
  614. }
  615. else {
  616. // We need to rebuild the form to go to a second step. For example, to
  617. // show the confirmation form for the deletion of nodes.
  618. $form_state['rebuild'] = TRUE;
  619. }
  620. }
  621. /**
  622. * Multiple node deletion confirmation form for node_admin_content().
  623. *
  624. * @see node_admin_nodes()
  625. * @see node_admin_nodes_submit()
  626. * @see node_admin_nodes_validate()
  627. * @see node_filter_form()
  628. * @see node_filter_form_submit()
  629. * @see node_multiple_delete_confirm_submit()
  630. * @ingroup forms
  631. */
  632. function node_multiple_delete_confirm($form, &$form_state, $nodes) {
  633. $form['nodes'] = array('#prefix' => '<ul>', '#suffix' => '</ul>', '#tree' => TRUE);
  634. // array_filter returns only elements with TRUE values
  635. foreach ($nodes as $nid => $value) {
  636. $title = db_query('SELECT title FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchField();
  637. $form['nodes'][$nid] = array(
  638. '#type' => 'hidden',
  639. '#value' => $nid,
  640. '#prefix' => '<li>',
  641. '#suffix' => check_plain($title) . "</li>\n",
  642. );
  643. }
  644. $form['operation'] = array('#type' => 'hidden', '#value' => 'delete');
  645. $form['#submit'][] = 'node_multiple_delete_confirm_submit';
  646. $confirm_question = format_plural(count($nodes),
  647. 'Are you sure you want to delete this item?',
  648. 'Are you sure you want to delete these items?');
  649. return confirm_form($form,
  650. $confirm_question,
  651. 'admin/content', t('This action cannot be undone.'),
  652. t('Delete'), t('Cancel'));
  653. }
  654. /**
  655. * Form submission handler for node_multiple_delete_confirm().
  656. *
  657. * @see node_admin_nodes()
  658. * @see node_admin_nodes_submit()
  659. * @see node_admin_nodes_validate()
  660. * @see node_filter_form()
  661. * @see node_filter_form_submit()
  662. * @see node_multiple_delete_confirm()
  663. */
  664. function node_multiple_delete_confirm_submit($form, &$form_state) {
  665. if ($form_state['values']['confirm']) {
  666. node_delete_multiple(array_keys($form_state['values']['nodes']));
  667. cache_clear_all();
  668. $count = count($form_state['values']['nodes']);
  669. watchdog('content', 'Deleted @count posts.', array('@count' => $count));
  670. drupal_set_message(format_plural($count, 'Deleted 1 post.', 'Deleted @count posts.'));
  671. }
  672. $form_state['redirect'] = 'admin/content';
  673. }

Functions

Namesort descending Description
node_admin_content Page callback: Form constructor for the content administration form.
node_admin_nodes Form builder: Builds the node administration overview.
node_admin_nodes_submit Process node_admin_nodes form submissions.
node_admin_nodes_validate Validate node_admin_nodes form submissions.
node_build_filter_query Applies filters for node administration filters based on session.
node_configure_rebuild_confirm Menu callback: confirm rebuilding of permissions.
node_configure_rebuild_confirm_submit Handler for wipe confirmation
node_filters List node administration filters that can be applied.
node_filter_form Returns the node administration filters form array to node_admin_content().
node_filter_form_submit Form submission handler for node_filter_form().
node_mass_update Make mass update of nodes, changing all nodes in the $nodes array to update them with the field values in $updates.
node_multiple_delete_confirm Multiple node deletion confirmation form for node_admin_content().
node_multiple_delete_confirm_submit Form submission handler for node_multiple_delete_confirm().
node_node_operations Implements hook_node_operations().
_node_mass_update_batch_finished Implements callback_batch_finished().
_node_mass_update_batch_process Implements callback_batch_operation().
_node_mass_update_helper Updates individual nodes when fewer than 10 are queued.