You are here

class SecondaryContactConnectionPermission in RedHen CRM 8

Provide permission for contacts that share a redhen_connection.

Plugin annotation


@ConnectionPermission(
 id = "secondary_contact_connection_permission",
 label = @Translation("Secondary Contact"),
 description = @Translation("A contact connected to the same entity via connection of the same type. Sitewide permissions will override this setting."),
 subject_entity_type = "redhen_contact",
 subject_entity_bundle = "",
 influencer_entity_type = "redhen_org",
)

Hierarchy

Expanded class hierarchy of SecondaryContactConnectionPermission

File

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

Namespace

Drupal\redhen_connection\Plugin\ConnectionPermission
View source
class SecondaryContactConnectionPermission extends ConnectionPermissionBase implements ConnectionPermissionInterface {

  /**
   * {@inheritdoc}
   */
  public function getPermissionKey() {
    return 'contact';
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

  /**
   * {@inheritdoc}
   */
  public function hasRolePermissions(EntityInterface $subject_entity, $operation, Contact $contact) {
    $access = new AccessResultNeutral();
    $influencers = $this
      ->getInfluencers($subject_entity);
    foreach ($influencers as $influencer) {
      $access = $this->redhenConnectionConnections
        ->checkConnectionPermission($contact, $influencer, $operation, $this
        ->getPermissionKey());
      if ($access
        ->isAllowed()) {
        return $access;
      }
    }
    return $access;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConnectionPermissionBase::$redhenConnectionConnections public property Connection Service.
ConnectionPermissionBase::get public function Get values from plugin definition.
ConnectionPermissionBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
SecondaryContactConnectionPermission::getInfluencers public function Get the influencer entity. Overrides ConnectionPermissionBase::getInfluencers
SecondaryContactConnectionPermission::getPermissionKey public function Get the entity key. Overrides ConnectionPermissionBase::getPermissionKey
SecondaryContactConnectionPermission::hasRolePermissions public function Determine if the contact execute the operation on the subject entity. Overrides ConnectionPermissionBase::hasRolePermissions