TermAccessControlHandler.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace Drupal\taxonomy;
  3. use Drupal\Core\Access\AccessResult;
  4. use Drupal\Core\Entity\EntityAccessControlHandler;
  5. use Drupal\Core\Entity\EntityInterface;
  6. use Drupal\Core\Session\AccountInterface;
  7. /**
  8. * Defines the access control handler for the taxonomy term entity type.
  9. *
  10. * @see \Drupal\taxonomy\Entity\Term
  11. */
  12. class TermAccessControlHandler extends EntityAccessControlHandler {
  13. /**
  14. * {@inheritdoc}
  15. */
  16. protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
  17. switch ($operation) {
  18. case 'view':
  19. return AccessResult::allowedIfHasPermission($account, 'access content');
  20. case 'update':
  21. return AccessResult::allowedIfHasPermissions($account, ["edit terms in {$entity->bundle()}", 'administer taxonomy'], 'OR');
  22. case 'delete':
  23. return AccessResult::allowedIfHasPermissions($account, ["delete terms in {$entity->bundle()}", 'administer taxonomy'], 'OR');
  24. default:
  25. // No opinion.
  26. return AccessResult::neutral();
  27. }
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
  33. return AccessResult::allowedIfHasPermission($account, 'administer taxonomy');
  34. }
  35. }