You are here

public function ConnectionService::checkConnectionPermission in RedHen CRM 8

Check entity access via its connections & current user's connection roles.

Parameters

\Drupal\Core\Entity\EntityInterface $endpoint1: Endpoint 1 of the connection.

\Drupal\Core\Entity\EntityInterface $endpoint2: Endpoint 2 of the connection.

string $operation: The entity operation (view, view label, update, delete, create)

string $permission_key: Key for checking permissions against.

Return value

\Drupal\Core\Access\AccessResultInterface Access result, either neutral or allowed.

Overrides ConnectionServiceInterface::checkConnectionPermission

File

modules/redhen_connection/src/ConnectionService.php, line 176

Class

ConnectionService
Provides an interface for getting connections between entities.

Namespace

Drupal\redhen_connection

Code

public function checkConnectionPermission(EntityInterface $endpoint1, EntityInterface $endpoint2, $operation, $permission_key) {
  $connections = $this
    ->getConnections($endpoint1, $endpoint2);
  foreach ($connections as $connection) {

    /** @var \Drupal\redhen_connection\Entity\ConnectionInterface $connection */
    $role = $connection
      ->get('role')->entity;
    if (!$role) {
      return new AccessResultNeutral();
    }
    $permissions = $role
      ->get('permissions');
    if (is_array($permissions[$permission_key]) && in_array($operation, $permissions[$permission_key])) {
      return new AccessResultAllowed();
    }
  }
  return new AccessResultNeutral();
}