LanguageAccessControlHandler.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace Drupal\language;
  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 language entity type.
  9. *
  10. * @see \Drupal\language\Entity\Language
  11. */
  12. class LanguageAccessControlHandler extends EntityAccessControlHandler {
  13. /**
  14. * {@inheritdoc}
  15. */
  16. protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
  17. switch ($operation) {
  18. case 'view':
  19. return parent::checkAccess($entity, $operation, $account);
  20. case 'update':
  21. /* @var \Drupal\Core\Language\LanguageInterface $entity */
  22. return AccessResult::allowedIf(!$entity->isLocked())->addCacheableDependency($entity)
  23. ->andIf(parent::checkAccess($entity, $operation, $account));
  24. case 'delete':
  25. /* @var \Drupal\Core\Language\LanguageInterface $entity */
  26. return AccessResult::allowedIf(!$entity->isLocked())->addCacheableDependency($entity)
  27. ->andIf(AccessResult::allowedIf(!$entity->isDefault())->addCacheableDependency($entity))
  28. ->andIf(parent::checkAccess($entity, $operation, $account));
  29. default:
  30. // No opinion.
  31. return AccessResult::neutral();
  32. }
  33. }
  34. }