publishcontent_test.module 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * @file
  4. * A dummy module for listing all nodes with their publish, unpublish
  5. * callback links to test permissions with.
  6. */
  7. /**
  8. * Implements hook_menu().
  9. */
  10. function publishcontent_test_menu() {
  11. $items = array();
  12. $items['publishcontent-links'] = array(
  13. 'title' => 'Node access test',
  14. 'page callback' => 'publishcontent_test_nodes',
  15. 'access arguments' => array('access content'),
  16. 'type' => MENU_SUGGESTED_ITEM,
  17. );
  18. return $items;
  19. }
  20. /**
  21. * Menu callback.
  22. *
  23. * List all nodes on the site with publish, unpublish links.
  24. */
  25. function publishcontent_test_nodes() {
  26. $output = '';
  27. $query = new EntityFieldQuery();
  28. $result = $query->entityCondition('entity_type', 'node')
  29. ->execute();
  30. if (!empty($result['node'])) {
  31. $output .= '<ul>';
  32. foreach (node_load_multiple(array_keys($result['node'])) as $node) {
  33. $op = '';
  34. if (empty($node->status) && publishcontent_publish_access($node)) {
  35. $op = 'publish';
  36. }
  37. elseif (!empty($node->status) && publishcontent_unpublish_access($node)) {
  38. $op = 'unpublish';
  39. }
  40. else {
  41. continue;
  42. }
  43. $output .= '<li>' . $node->title . ' ' . l("{$op}-{$node->nid}", "node/{$node->nid}/{$op}/" . drupal_get_token(), array('query' => drupal_get_destination())) . '</li>';
  44. }
  45. $output .= '</ul>';
  46. }
  47. return $output;
  48. }