Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / language / src / LanguageAccessControlHandler.php
1 <?php
2
3 namespace Drupal\language;
4
5 use Drupal\Core\Access\AccessResult;
6 use Drupal\Core\Entity\EntityAccessControlHandler;
7 use Drupal\Core\Entity\EntityInterface;
8 use Drupal\Core\Session\AccountInterface;
9
10 /**
11  * Defines the access control handler for the language entity type.
12  *
13  * @see \Drupal\language\Entity\Language
14  */
15 class LanguageAccessControlHandler extends EntityAccessControlHandler {
16
17   /**
18    * {@inheritdoc}
19    */
20   protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
21     switch ($operation) {
22       case 'view':
23         return parent::checkAccess($entity, $operation, $account);
24
25       case 'update':
26         /* @var \Drupal\Core\Language\LanguageInterface $entity */
27         return AccessResult::allowedIf(!$entity->isLocked())->addCacheableDependency($entity)
28           ->andIf(parent::checkAccess($entity, $operation, $account));
29
30       case 'delete':
31         /* @var \Drupal\Core\Language\LanguageInterface $entity */
32         return AccessResult::allowedIf(!$entity->isLocked())->addCacheableDependency($entity)
33           ->andIf(AccessResult::allowedIf(!$entity->isDefault())->addCacheableDependency($entity))
34           ->andIf(parent::checkAccess($entity, $operation, $account));
35
36       default:
37         // No opinion.
38         return AccessResult::neutral();
39     }
40   }
41
42 }