NodeGrantDatabaseStorageInterface.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. namespace Drupal\node;
  3. use Drupal\Core\Session\AccountInterface;
  4. /**
  5. * Provides an interface for node access grant storage.
  6. *
  7. * @ingroup node_access
  8. */
  9. interface NodeGrantDatabaseStorageInterface {
  10. /**
  11. * Checks all grants for a given account.
  12. *
  13. * @param \Drupal\Core\Session\AccountInterface $account
  14. * A user object representing the user for whom the operation is to be
  15. * performed.
  16. *
  17. * @return int
  18. * Status of the access check.
  19. */
  20. public function checkAll(AccountInterface $account);
  21. /**
  22. * Alters a query when node access is required.
  23. *
  24. * @param mixed $query
  25. * Query that is being altered.
  26. * @param array $tables
  27. * A list of tables that need to be part of the alter.
  28. * @param string $op
  29. * The operation to be performed on the node. Possible values are:
  30. * - "view"
  31. * - "update"
  32. * - "delete"
  33. * - "create"
  34. * @param \Drupal\Core\Session\AccountInterface $account
  35. * A user object representing the user for whom the operation is to be
  36. * performed.
  37. * @param string $base_table
  38. * The base table of the query.
  39. *
  40. * @return int
  41. * Status of the access check.
  42. */
  43. public function alterQuery($query, array $tables, $op, AccountInterface $account, $base_table);
  44. /**
  45. * Writes a list of grants to the database, deleting previously saved ones.
  46. *
  47. * If a realm is provided, it will only delete grants from that realm, but
  48. * it will always delete a grant from the 'all' realm. Modules that use
  49. * node access can use this method when doing mass updates due to widespread
  50. * permission changes.
  51. *
  52. * Note: Don't call this method directly from a contributed module. Call
  53. * \Drupal\node\NodeAccessControlHandlerInterface::acquireGrants() instead.
  54. *
  55. * @param \Drupal\node\NodeInterface $node
  56. * The node whose grants are being written.
  57. * @param array $grants
  58. * A list of grants to write. Each grant is an array that must contain the
  59. * following keys: realm, gid, grant_view, grant_update, grant_delete.
  60. * The realm is specified by a particular module; the gid is as well, and
  61. * is a module-defined id to define grant privileges. each grant_* field
  62. * is a boolean value.
  63. * @param string $realm
  64. * (optional) If provided, read/write grants for that realm only. Defaults to
  65. * NULL.
  66. * @param bool $delete
  67. * (optional) If false, does not delete records. This is only for optimization
  68. * purposes, and assumes the caller has already performed a mass delete of
  69. * some form. Defaults to TRUE.
  70. */
  71. public function write(NodeInterface $node, array $grants, $realm = NULL, $delete = TRUE);
  72. /**
  73. * Deletes all node access entries.
  74. */
  75. public function delete();
  76. /**
  77. * Creates the default node access grant entry.
  78. */
  79. public function writeDefault();
  80. /**
  81. * Determines access to nodes based on node grants.
  82. *
  83. * @param \Drupal\node\NodeInterface $node
  84. * The entity for which to check 'create' access.
  85. * @param string $operation
  86. * The entity operation. Usually one of 'view', 'edit', 'create' or
  87. * 'delete'.
  88. * @param \Drupal\Core\Session\AccountInterface $account
  89. * The user for which to check access.
  90. *
  91. * @return \Drupal\Core\Access\AccessResultInterface
  92. * The access result, either allowed or neutral. If there are no node
  93. * grants, the default grant defined by writeDefault() is applied.
  94. *
  95. * @see hook_node_grants()
  96. * @see hook_node_access_records()
  97. * @see \Drupal\node\NodeGrantDatabaseStorageInterface::writeDefault()
  98. */
  99. public function access(NodeInterface $node, $operation, AccountInterface $account);
  100. /**
  101. * Counts available node grants.
  102. *
  103. * @return int
  104. * Returns the amount of node grants.
  105. */
  106. public function count();
  107. /**
  108. * Remove the access records belonging to certain nodes.
  109. *
  110. * @param array $nids
  111. * A list of node IDs. The grant records belonging to these nodes will be
  112. * deleted.
  113. */
  114. public function deleteNodeRecords(array $nids);
  115. }