You are here

class ConnectionConnectionPermission in RedHen CRM 8

Provide permissions for the connection entity of a redhen_connection.

Plugin annotation


@ConnectionPermission(
 id = "connection_connection_permission",
 label = @Translation("Connection"),
 description = @Translation("Applies to both current users connection and secondary connections. Sitewide permissions will override this permission."),
 subject_entity_type = "redhen_connection",
 subject_entity_bundle = "",
 influencer_entity_type = "",
)

Hierarchy

Expanded class hierarchy of ConnectionConnectionPermission

File

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

Namespace

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

  /**
   * A Redhen Contact Object.
   *
   * @var \Drupal\Core\Entity\EntityInterface
   */
  private $contact;

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

  /**
   * {@inheritdoc}
   */
  public function getInfluencers(EntityInterface $subject_entity) {

    // Return the connections for current contact and the subject.
    return $this->redhenConnectionConnections
      ->getConnectedEntities($this->contact, $subject_entity
      ->getType());
  }

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

}

Members

Namesort descending Modifiers Type Description Overrides
ConnectionConnectionPermission::$contact private property A Redhen Contact Object.
ConnectionConnectionPermission::getInfluencers public function Get the influencer entity. Overrides ConnectionPermissionBase::getInfluencers
ConnectionConnectionPermission::getPermissionKey public function Get the entity key. Overrides ConnectionPermissionBase::getPermissionKey
ConnectionConnectionPermission::hasRolePermissions public function Determine if the contact execute the operation on the subject entity. Overrides ConnectionPermissionBase::hasRolePermissions
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.