You are here

public function SecondaryContactConnectionPermission::getInfluencers in RedHen CRM 8

Get the influencer entity.

Parameters

\Drupal\Core\Entity\EntityInterface $subject_entity: The subject entity.

Return value

array An array of Entities that influence the access of the subject entity.

Overrides ConnectionPermissionBase::getInfluencers

1 call to SecondaryContactConnectionPermission::getInfluencers()
SecondaryContactConnectionPermission::hasRolePermissions in modules/redhen_connection/src/Plugin/ConnectionPermission/SecondaryContactConnectionPermission.php
Determine if the contact execute the operation on the subject entity.

File

modules/redhen_connection/src/Plugin/ConnectionPermission/SecondaryContactConnectionPermission.php, line 35

Class

SecondaryContactConnectionPermission
Provide permission for contacts that share a redhen_connection.

Namespace

Drupal\redhen_connection\Plugin\ConnectionPermission

Code

public function getInfluencers(EntityInterface $subject_entity) {
  $influencers = [];

  // Get all connection types for this subject.
  $connection_types = $this->redhenConnectionConnections
    ->getConnectionTypes($subject_entity);

  // Loop over types and find contact and org connection types.
  foreach ($connection_types as $type) {
    $endpoints[] = $type
      ->getEndpointEntityTypeId(1);
    $endpoints[] = $type
      ->getEndpointEntityTypeId(2);

    // If both there is a contact and an org endpoint take further action.
    if (in_array($this
      ->get('subject_entity_type'), $endpoints) && in_array($this
      ->get('influencer_entity_type'), $endpoints)) {

      // Load up the org from the connection.
      $connected_entities = $this->redhenConnectionConnections
        ->getConnectedEntities($subject_entity, $type
        ->id());

      // Add the connected entities to the influencers array.
      foreach ($connected_entities as $entity) {
        $influencers[] = $entity;
      }
    }
  }
  return $influencers;
}