You are here

class ConnectionAccessCheck in RedHen CRM 8

Hierarchy

Expanded class hierarchy of ConnectionAccessCheck

1 string reference to 'ConnectionAccessCheck'
redhen_connection.services.yml in modules/redhen_connection/redhen_connection.services.yml
modules/redhen_connection/redhen_connection.services.yml
1 service uses ConnectionAccessCheck
redhen_connection.access_check in modules/redhen_connection/redhen_connection.services.yml
Drupal\redhen_connection\Access\ConnectionAccessCheck

File

modules/redhen_connection/src/Access/ConnectionAccessCheck.php, line 16

Namespace

Drupal\redhen_connection\Access
View source
class ConnectionAccessCheck implements AccessInterface {

  /**
   * Checks access to the RedHen operation on the given route.
   *
   * The route's '_redhen_connection_access' requirement should specify an
   * operation as a string, where available operations are:
   * 'view', 'view label', 'update', and 'delete'.
   *
   * For example, this route configuration invokes a permissions check for
   * 'update' access to entities of type 'redhen_org':
   * @code
   * pattern: '/foo/{redhen_org}/bar'
   * requirements:
   *   _redhen_connection_access: 'update'
   * @endcode
   *
   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   *   The parameterized route.
   * @param \Drupal\Core\Session\AccountInterface $account
   *   The user account.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   The access result.
   */
  public function access(RouteMatchInterface $route_match, AccountInterface $account) {
    $route = $route_match
      ->getRouteObject();
    $operation = $route
      ->getRequirement('_redhen_connection_access');
    $entity = $this
      ->getEntity($route_match);
    if ($entity) {
      return $entity
        ->access($operation, $account, TRUE);
    }
    return AccessResult::neutral();
  }

  /**
   * Get the RedHen entity object from the given route.
   *
   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   *   The parameterized route.
   *
   * @return \Drupal\Core\Entity\EntityInterface|null
   *   The entity object or NULL if there is no RedHen parameter in the route.
   */
  protected function getEntity(RouteMatchInterface $route_match) {
    $connection = $route_match
      ->getParameter('redhen_connection');
    if ($connection) {
      if ($connection instanceof ConnectionInterface) {
        return $connection;
      }
      return Connection::load($connection);
    }
    $contact = $route_match
      ->getParameter('redhen_contact');
    if ($contact) {
      if ($contact instanceof ContactInterface) {
        return $contact;
      }
      return Contact::load($contact);
    }
    $org = $route_match
      ->getParameter('redhen_org');
    if ($org) {
      if ($org instanceof OrgInterface) {
        return $org;
      }
      return Org::load($org);
    }
    return NULL;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConnectionAccessCheck::access public function Checks access to the RedHen operation on the given route.
ConnectionAccessCheck::getEntity protected function Get the RedHen entity object from the given route.