entity_query_access_test.module 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * @file
  4. * Helper module for testing EntityFieldQuery access on any type of entity.
  5. */
  6. /**
  7. * Implements hook_menu().
  8. */
  9. function entity_query_access_test_menu() {
  10. $items['entity-query-access/test/%'] = array(
  11. 'title' => "Retrieve a sample of entity query access data",
  12. 'page callback' => 'entity_query_access_test_sample_query',
  13. 'page arguments' => array(2),
  14. 'access callback' => TRUE,
  15. 'type' => MENU_CALLBACK,
  16. );
  17. return $items;
  18. }
  19. /**
  20. * Returns the results from an example EntityFieldQuery.
  21. */
  22. function entity_query_access_test_sample_query($field_name) {
  23. global $user;
  24. // Simulate user does not have access to view all nodes.
  25. $access = &drupal_static('node_access_view_all_nodes');
  26. $access[$user->uid] = FALSE;
  27. $query = new EntityFieldQuery();
  28. $query
  29. ->entityCondition('entity_type', 'test_entity_bundle_key')
  30. ->fieldCondition($field_name, 'value', 0, '>')
  31. ->entityOrderBy('entity_id', 'ASC');
  32. $results = array(
  33. 'items' => array(),
  34. 'title' => t('EntityFieldQuery results'),
  35. );
  36. foreach ($query->execute() as $entity_type => $entity_ids) {
  37. foreach ($entity_ids as $entity_id => $entity_stub) {
  38. $results['items'][] = format_string('Found entity of type @entity_type with id @entity_id', array('@entity_type' => $entity_type, '@entity_id' => $entity_id));
  39. }
  40. }
  41. if (count($results['items']) > 0) {
  42. $output = theme('item_list', $results);
  43. }
  44. else {
  45. $output = 'No results found with EntityFieldQuery.';
  46. }
  47. return $output;
  48. }