taxonomy_menu_sync-1.0.4/src/TaxonomyMenuSyncAccessControlHandler.php
src/TaxonomyMenuSyncAccessControlHandler.php
<?php
namespace Drupal\taxonomy_menu_sync;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
/**
* Access controller for the taxonomy_menu_sync entity.
*
* @see \Drupal\taxonomy_menu_sync\Entity\TaxonomyMenuSync.
*/
class TaxonomyMenuSyncAccessControlHandler extends EntityAccessControlHandler {
/**
* {@inheritdoc}
*
* Link the activities to the permissions. checkAccess is called with the
* $operation as defined in the routing.yml file.
*/
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
switch ($operation) {
case 'view':
return AccessResult::allowedIfHasPermission($account, 'view taxonomy_menu_sync entity');
case 'edit':
return AccessResult::allowedIfHasPermission($account, 'edit taxonomy_menu_sync entity');
case 'delete':
return AccessResult::allowedIfHasPermission($account, 'delete taxonomy_menu_sync entity');
}
return AccessResult::allowed();
}
/**
* {@inheritdoc}
*
* Separate from the checkAccess because the entity does not yet exist, it
* will be created during the 'add' process.
*/
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
return AccessResult::allowedIfHasPermission($account, 'add taxonomy_menu_sync entity');
}
}
