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