permissions_by_entity.module in Permissions by Term 8
Same filename and directory in other branches
Module file for Permission by Entity.
File
modules/permissions_by_entity/permissions_by_entity.moduleView source
<?php
/**
* @file
* Module file for Permission by Entity.
*/
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Session\AccountInterface;
/**
* Implements hook_entity_access().
*/
function permissions_by_entity_entity_access(EntityInterface $entity, $operation, AccountInterface $account) {
/** @var \Drupal\permissions_by_entity\Service\AccessChecker $accessChecker */
if ($operation === 'view' && $entity instanceof FieldableEntityInterface) {
$accessChecker = \Drupal::service('permissions_by_entity.access_checker');
// Do not just return a neutral result if access allowed by the module.
return $accessChecker
->isAccessAllowed($entity, $account
->id()) ? AccessResult::allowed() : AccessResult::forbidden('Access revoked by permissions_by_entity module.');
}
return AccessResult::neutral();
}
Functions
Name | Description |
---|---|
permissions_by_entity_entity_access | Implements hook_entity_access(). |