devel_node_access.api.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * @file
  4. * Hook provided by the Devel Node Access module.
  5. */
  6. /**
  7. * @addtogroup hooks
  8. * @{
  9. */
  10. /**
  11. * Explain your records in the {node_access} table.
  12. *
  13. * In order to help developers and administrators understand the forces
  14. * that control access to any given node, the DNA module provides the
  15. * Devel Node Access block, which lists all the grant records in the
  16. * {node_access} table for that node.
  17. *
  18. * However, every Node Access module is free in how it defines and uses the
  19. * 'realm' and 'gid' fields in its records in the {node_access} table, and
  20. * it's often difficult to interpret them. This hook passes each record
  21. * that DNA wants to display, and the owning module is expected to return
  22. * an explanation of that record.
  23. *
  24. * The explanation should not be localized (not be passed through t()), so
  25. * that administrators seeking help can present English explanations.
  26. *
  27. * @param $row
  28. * The record from the {node_access} table, as object. The member fields are:
  29. * nid, gid, realm, grant_view, grant_update, grant_delete.
  30. *
  31. * @return
  32. * A string with a (short!) explanation of the given {node_access} row,
  33. * to be displayed in DNA's 'Devel Node Access' block. It will be displayed
  34. * as HTML; any variable parts must already be sanitized.
  35. *
  36. * @see hook_node_access_records()
  37. * @see devel_node_access_node_access_explain()
  38. *
  39. * @ingroup node_access
  40. */
  41. function hook_node_access_explain($row) {
  42. if ($row->realm == 'mymodule_myrealm') {
  43. if ($row->grant_view) {
  44. $role = user_role_load($row->gid);
  45. return 'Role ' . drupal_placeholder($role->name) . ' may view this node.';
  46. }
  47. else {
  48. return 'No access.';
  49. }
  50. }
  51. }
  52. /**
  53. * Acknowledge ownership of 'alien' grant records.
  54. *
  55. * Some node access modules store grant records directly into the {node_access}
  56. * table rather than returning them through hook_node_access_records(). This
  57. * practice is not recommended and DNA will flag all such records as 'alien'.
  58. *
  59. * If this is unavoidable, a module can confess to being the owner of these
  60. * grant records, so that DNA can properly attribute them.
  61. *
  62. * @see hook_node_access_records()
  63. *
  64. * @ingroup node_access
  65. */
  66. function hook_node_access_acknowledge($grant) {
  67. if ($grant['realm'] == 'mymodule_all' && $grant['nid'] == 0) {
  68. return TRUE;
  69. }
  70. }
  71. /**
  72. * @} End of "addtogroup hooks".
  73. */