You are here

function courier_system_entity_access in Courier 8

Same name and namespace in other branches
  1. 2.x courier_system/courier_system.module \courier_system_entity_access()

Implements hook_entity_access().

File

courier_system/courier_system.module, line 13

Code

function courier_system_entity_access(EntityInterface $entity, $operation, AccountInterface $account) {
  if ($operation == 'templates' && $entity instanceof TemplateCollectionInterface) {

    // Determine if template collection belongs to courier_system.

    /** @var \Drupal\courier\Service\GlobalTemplateCollectionManagerInterface $template_collection_manager */
    $template_collection_manager = \Drupal::service('courier.manager.global_template_collection');
    $gtc = $template_collection_manager
      ->getGlobalCollectionForLocalCollection($entity);
    if ($gtc && strpos($gtc
      ->id(), 'courier_system.') === 0) {
      return AccessResult::allowedIfHasPermission($account, 'administer account settings');
    }
  }
  return AccessResult::neutral();
}