MenuAccessController.php 835 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11
<?php

/**
 * @file
 * Contains \Drupal\system\MenuAccessController.
 */

namespace Drupal\system;

use Drupal\Core\Entity\EntityAccessController;
use Drupal\Core\Entity\EntityInterface;
12
use Drupal\user\Plugin\Core\Entity\User;
13 14 15 16 17 18 19 20 21 22 23

/**
 * Defines an access controller for the menu entity.
 *
 * @see \Drupal\system\Plugin\Core\Entity\Menu
 */
class MenuAccessController extends EntityAccessController {

  /**
   * {@inheritdoc}
   */
24
  protected function checkAccess(EntityInterface $entity, $operation, $langcode, User $account) {
25 26 27 28 29 30 31 32 33 34
    if ($operation == 'delete') {
      // System-defined menus may not be deleted.
      // @todo Refactor https://drupal.org/node/1882552
      $system_menus = menu_list_system_menus();
      return !isset($system_menus[$entity->id()]);
    }
    return user_access('administer menu', $account);
  }

}