EntityAccessControllerInterface.php

You are here

Contains \Drupal\Core\Entity\EntityAccessControllerInterface.

Namespace

Drupal\Core\Entity

Interfaces

Namesort descending Description
EntityAccessControllerInterface Defines a common interface for entity access controller classes.

File

core/lib/Drupal/Core/Entity/EntityAccessControllerInterface.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * Contains \Drupal\Core\Entity\EntityAccessControllerInterface.
  5. */
  6. namespace Drupal\Core\Entity;
  7. use Drupal\Core\Field\FieldItemListInterface;
  8. use Drupal\Core\Extension\ModuleHandlerInterface;
  9. use Drupal\Core\Field\FieldDefinitionInterface;
  10. use Drupal\Core\Language\Language;
  11. use Drupal\Core\Session\AccountInterface;
  12. /**
  13. * Defines a common interface for entity access controller classes.
  14. */
  15. interface EntityAccessControllerInterface {
  16. /**
  17. * Checks access to an operation on a given entity or entity translation.
  18. *
  19. * Use \Drupal\Core\Entity\EntityAccessControllerInterface::createAccess()
  20. * to check access to create an entity.
  21. *
  22. * @param \Drupal\Core\Entity\EntityInterface $entity
  23. * The entity for which to check access.
  24. * @param string $operation
  25. * The operation access should be checked for.
  26. * Usually one of "view", "update" or "delete".
  27. * @param string $langcode
  28. * (optional) The language code for which to check access. Defaults to
  29. * Language::LANGCODE_DEFAULT.
  30. * @param \Drupal\Core\Session\AccountInterface $account
  31. * (optional) The user session for which to check access, or NULL to check
  32. * access for the current user. Defaults to NULL.
  33. *
  34. * @return bool
  35. * TRUE if access was granted, FALSE otherwise.
  36. */
  37. public function access(EntityInterface $entity, $operation, $langcode = Language::LANGCODE_DEFAULT, AccountInterface $account = NULL);
  38. /**
  39. * Checks access to create an entity.
  40. *
  41. * @param string $entity_bundle
  42. * (optional) The bundle of the entity. Required if the entity supports
  43. * bundles, defaults to NULL otherwise.
  44. * @param \Drupal\Core\Session\AccountInterface $account
  45. * (optional) The user session for which to check access, or NULL to check
  46. * access for the current user. Defaults to NULL.
  47. * @param array $context
  48. * (optional) An array of key-value pairs to pass additional context when
  49. * needed.
  50. */
  51. public function createAccess($entity_bundle = NULL, AccountInterface $account = NULL, array $context = array());
  52. /**
  53. * Clears all cached access checks.
  54. */
  55. public function resetCache();
  56. /**
  57. * Sets the module handler for this access controller.
  58. *
  59. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
  60. * The module handler.
  61. *
  62. * @return $this
  63. */
  64. public function setModuleHandler(ModuleHandlerInterface $module_handler);
  65. /**
  66. * Checks access to an operation on a given entity field.
  67. *
  68. * @param string $operation
  69. * The operation access should be checked for.
  70. * Usually one of "view" or "edit".
  71. * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
  72. * The field definition.
  73. * @param \Drupal\Core\Session\AccountInterface $account
  74. * (optional) The user session for which to check access, or NULL to check
  75. * access for the current user. Defaults to NULL.
  76. * @param \Drupal\Core\Field\FieldItemListInterface $items
  77. * (optional) The field values for which to check access, or NULL if access
  78. * is checked for the field definition, without any specific value
  79. * available. Defaults to NULL.
  80. */
  81. public function fieldAccess($operation, FieldDefinitionInterface $field_definition, AccountInterface $account = NULL, FieldItemListInterface $items = NULL);
  82. }