You are here

public function ConnectionConnectionPermission::hasRolePermissions in RedHen CRM 8

Determine if the contact execute the operation on the subject entity.

Parameters

\Drupal\Core\Entity\EntityInterface $subject_entity: The entity that is being accessed.

string $operation: The operation that is being performed (view, update, delete, view label).

\Drupal\redhen_contact\Entity\Contact $contact: The Redhen contact object.

Return value

bool True is access is allowed, false if neutral.

Overrides ConnectionPermissionBase::hasRolePermissions

File

modules/redhen_connection/src/Plugin/ConnectionPermission/ConnectionConnectionPermission.php, line 51

Class

ConnectionConnectionPermission
Provide permissions for the connection entity of a redhen_connection.

Namespace

Drupal\redhen_connection\Plugin\ConnectionPermission

Code

public function hasRolePermissions(EntityInterface $subject_entity, $operation, Contact $contact) {
  $this->contact = $contact;
  $access = new AccessResultNeutral();

  // Only check permissions for connections that are of a type with contacts.
  $connection_type = ConnectionType::load($subject_entity
    ->getType());
  if ($connection_type
    ->getEndpointEntityTypeId(1) == 'redhen_contact' || $connection_type
    ->getEndpointEntityTypeId(2) == 'redhen_contact') {
    $influencers = $this
      ->getInfluencers($subject_entity);
    if ($influencers) {
      foreach ($influencers as $influencer) {
        $access = $this->redhenConnectionConnections
          ->checkConnectionPermission($contact, $influencer, $operation, $this
          ->getPermissionKey());
        if ($access
          ->isAllowed()) {
          return $access;
        }
      }
    }
  }
  return $access;
}