'node_access_test', 'gid' => 888, 'grant_view' => 1, 'grant_update' => 0, 'grant_delete' => 0, 'priority' => 999, ); return $grants; } /** * Implements hook_permission(). * * Sets up permissions for this module. */ function node_access_test_permission() { return array('node test view' => array('title' => 'View content')); } /** * Implements hook_menu(). * * Sets up a page that lists nodes. */ function node_access_test_menu() { $items = array(); $items['node_access_test_page'] = array( 'title' => 'Node access test', 'page callback' => 'node_access_test_page', 'access arguments' => array('access content'), 'type' => MENU_SUGGESTED_ITEM, ); $items['node_access_entity_test_page'] = array( 'title' => 'Node access test', 'page callback' => 'node_access_entity_test_page', 'access arguments' => array('access content'), 'type' => MENU_SUGGESTED_ITEM, ); return $items; } /** * Page callback for node access test page. * * Page should say "No nodes" if there are no nodes, and "Yes, # nodes" (with * the number filled in) if there were nodes the user could access. Also, the * database query is shown, and a list of the node IDs, for debugging purposes. * And if there is a query exception, the page says "Exception" and gives the * error. */ function node_access_test_page() { $output = ''; try { $query = db_select('node', 'mytab') ->fields('mytab'); $query->addTag('node_access'); $result = $query->execute()->fetchAll(); if (count($result)) { $output .= '

Yes, ' . count($result) . ' nodes

'; $output .= ''; } else { $output .= '

No nodes

'; } $output .= '

' . ((string) $query ) . '

'; } catch (Exception $e) { $output = '

Exception

'; $output .= '

' . $e->getMessage() . '

'; } return $output; } /** * Page callback for node access entity test page. * * Page should say "No nodes" if there are no nodes, and "Yes, # nodes" (with * the number filled in) if there were nodes the user could access. Also, the * database query is shown, and a list of the node IDs, for debugging purposes. * And if there is a query exception, the page says "Exception" and gives the * error. */ function node_access_entity_test_page() { $output = ''; try { $query = new EntityFieldQuery; $result = $query->fieldCondition('body', 'value', 'A', 'STARTS_WITH')->execute(); if (!empty($result['node'])) { $output .= '

Yes, ' . count($result['node']) . ' nodes

'; $output .= ''; } else { $output .= '

No nodes

'; } } catch (Exception $e) { $output = '

Exception

'; $output .= '

' . $e->getMessage() . '

'; } return $output; }