You are here

public static function EntityAccessHelper::getEntityAccessResult in Open Social 8.9

Same name and namespace in other branches
  1. 8 modules/custom/entity_access_by_field/src/EntityAccessHelper.php \Drupal\entity_access_by_field\EntityAccessHelper::getEntityAccessResult()
  2. 8.2 modules/custom/entity_access_by_field/src/EntityAccessHelper.php \Drupal\entity_access_by_field\EntityAccessHelper::getEntityAccessResult()
  3. 8.3 modules/custom/entity_access_by_field/src/EntityAccessHelper.php \Drupal\entity_access_by_field\EntityAccessHelper::getEntityAccessResult()
  4. 8.4 modules/custom/entity_access_by_field/src/EntityAccessHelper.php \Drupal\entity_access_by_field\EntityAccessHelper::getEntityAccessResult()
  5. 8.5 modules/custom/entity_access_by_field/src/EntityAccessHelper.php \Drupal\entity_access_by_field\EntityAccessHelper::getEntityAccessResult()
  6. 8.6 modules/custom/entity_access_by_field/src/EntityAccessHelper.php \Drupal\entity_access_by_field\EntityAccessHelper::getEntityAccessResult()
  7. 8.7 modules/custom/entity_access_by_field/src/EntityAccessHelper.php \Drupal\entity_access_by_field\EntityAccessHelper::getEntityAccessResult()
  8. 8.8 modules/custom/entity_access_by_field/src/EntityAccessHelper.php \Drupal\entity_access_by_field\EntityAccessHelper::getEntityAccessResult()
  9. 10.3.x modules/custom/entity_access_by_field/src/EntityAccessHelper.php \Drupal\entity_access_by_field\EntityAccessHelper::getEntityAccessResult()
  10. 10.0.x modules/custom/entity_access_by_field/src/EntityAccessHelper.php \Drupal\entity_access_by_field\EntityAccessHelper::getEntityAccessResult()
  11. 10.1.x modules/custom/entity_access_by_field/src/EntityAccessHelper.php \Drupal\entity_access_by_field\EntityAccessHelper::getEntityAccessResult()
  12. 10.2.x modules/custom/entity_access_by_field/src/EntityAccessHelper.php \Drupal\entity_access_by_field\EntityAccessHelper::getEntityAccessResult()

Gets the Entity access for the given node.

1 call to EntityAccessHelper::getEntityAccessResult()
entity_access_by_field_node_access in modules/custom/entity_access_by_field/entity_access_by_field.module
Implements hook_node_access().

File

modules/custom/entity_access_by_field/src/EntityAccessHelper.php, line 103

Class

EntityAccessHelper
Helper class for checking entity access.

Namespace

Drupal\entity_access_by_field

Code

public static function getEntityAccessResult(NodeInterface $node, $op, AccountInterface $account) {
  $access = EntityAccessHelper::nodeAccessCheck($node, $op, $account);
  $moduleHandler = \Drupal::service('module_handler');

  // If the social_event_invite module is enabled and a person got invited
  // then allow access to view the node.
  // Todo:: Come up with a better solution for this code.
  if ($moduleHandler
    ->moduleExists('social_event_invite')) {
    if ($op == 'view') {
      $conditions = [
        'field_account' => $account
          ->id(),
        'field_event' => $node
          ->id(),
      ];

      // Load the current Event enrollments so we can check duplicates.
      $storage = \Drupal::entityTypeManager()
        ->getStorage('event_enrollment');
      $enrollments = $storage
        ->loadByProperties($conditions);
      if ($enrollment = array_pop($enrollments)) {
        if ($enrollment->field_request_or_invite_status && (int) $enrollment->field_request_or_invite_status->value !== EventEnrollmentInterface::REQUEST_OR_INVITE_DECLINED && (int) $enrollment->field_request_or_invite_status->value !== EventEnrollmentInterface::INVITE_INVALID_OR_EXPIRED) {
          $access = 2;
        }
      }
    }
  }
  switch ($access) {
    case 2:
      return AccessResult::allowed()
        ->cachePerPermissions()
        ->addCacheableDependency($node);
    case 1:
      return AccessResult::forbidden();
  }
  return AccessResult::neutral();
}