86d7db135e00f237444e887ef9ee45b200c2092d
[yaffs-website] / web / core / modules / system / src / MenuAccessControlHandler.php
1 <?php
2
3 namespace Drupal\system;
4
5 use Drupal\Core\Access\AccessResult;
6 use Drupal\Core\Entity\EntityInterface;
7 use Drupal\Core\Entity\EntityAccessControlHandler;
8 use Drupal\Core\Session\AccountInterface;
9
10 /**
11  * Defines the access control handler for the menu entity type.
12  *
13  * @see \Drupal\system\Entity\Menu
14  */
15 class MenuAccessControlHandler extends EntityAccessControlHandler {
16
17   /**
18    * {@inheritdoc}
19    */
20   protected $viewLabelOperation = TRUE;
21
22   /**
23    * {@inheritdoc}
24    */
25   protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
26     // There are no restrictions on viewing the label of a date format.
27     if ($operation === 'view label') {
28       return AccessResult::allowed();
29     }
30     // Locked menus could not be deleted.
31     elseif ($operation === 'delete') {
32       if ($entity->isLocked()) {
33         return AccessResult::forbidden('The Menu config entity is locked.')->addCacheableDependency($entity);
34       }
35       else {
36         return parent::checkAccess($entity, $operation, $account)->addCacheableDependency($entity);
37       }
38     }
39
40     return parent::checkAccess($entity, $operation, $account);
41   }
42
43 }