function redhen_connection_entity_access in RedHen CRM 8
Implements hook_entity_access().
File
- modules/
redhen_connection/ redhen_connection.module, line 100 - Contains redhen_connection.module..
Code
function redhen_connection_entity_access(EntityInterface $entity, $operation, AccountInterface $account) {
$connection_plugin_manager = \Drupal::service('plugin.manager.connection_permission');
$plugin_definitions = $connection_plugin_manager
->getDefinitions();
foreach ($plugin_definitions as $plugin_id => $plugin_definition) {
$plugin_instance = $connection_plugin_manager
->createInstance($plugin_id);
if ($entity
->getEntityTypeId() === $plugin_instance
->get('subject_entity_type')) {
if (!empty($plugin_instance
->get('subject_entity_bundle'))) {
if ($plugin_instance
->get('subject_entity_bundle') != $entity
->bundle()) {
continue;
}
}
$contact = Contact::loadByUser($account);
if ($contact) {
return $plugin_instance
->hasRolePermissions($entity, $operation, $contact);
}
}
}
return new AccessResultNeutral();
}