You are here

protected static function TemporaryQueryGuard::getAccessResultsFromEntityFilterHook in JSON:API 8

Same name and namespace in other branches
  1. 8.2 src/Access/TemporaryQueryGuard.php \Drupal\jsonapi\Access\TemporaryQueryGuard::getAccessResultsFromEntityFilterHook()

Gets the combined access result for each JSONAPI_FILTER_AMONG_* subset.

This invokes hook_jsonapi_entity_filter_access() and hook_jsonapi_ENTITY_TYPE_filter_access() and combines the results from all of the modules into a single set of results.

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type for which to check filter access.

\Drupal\Core\Session\AccountInterface $account: The account for which to check access.

Return value

\Drupal\Core\Access\AccessResultInterface[] The array of access results, keyed by subset. See hook_jsonapi_entity_filter_access() for details.

1 call to TemporaryQueryGuard::getAccessResultsFromEntityFilterHook()
TemporaryQueryGuard::getAccessConditionForKnownSubsets in src/Access/TemporaryQueryGuard.php
Gets an access condition for the allowed JSONAPI_FILTER_AMONG_* subsets.

File

src/Access/TemporaryQueryGuard.php, line 450

Class

TemporaryQueryGuard
Adds sufficient access control to collection queries.

Namespace

Drupal\jsonapi\Access

Code

protected static function getAccessResultsFromEntityFilterHook(EntityTypeInterface $entity_type, AccountInterface $account) {

  /* @var \Drupal\Core\Access\AccessResultInterface[] $combined_access_results */
  $combined_access_results = [
    JSONAPI_FILTER_AMONG_ALL => AccessResult::neutral(),
    JSONAPI_FILTER_AMONG_PUBLISHED => AccessResult::neutral(),
    JSONAPI_FILTER_AMONG_ENABLED => AccessResult::neutral(),
    JSONAPI_FILTER_AMONG_OWN => AccessResult::neutral(),
  ];

  // Invoke hook_jsonapi_entity_filter_access() and
  // hook_jsonapi_ENTITY_TYPE_filter_access() for each module and merge its
  // results with the combined results.
  foreach ([
    'jsonapi_entity_filter_access',
    'jsonapi_' . $entity_type
      ->id() . '_filter_access',
  ] as $hook) {
    foreach (static::$moduleHandler
      ->getImplementations($hook) as $module) {
      $module_access_results = static::$moduleHandler
        ->invoke($module, $hook, [
        $entity_type,
        $account,
      ]);
      if ($module_access_results) {
        foreach ($module_access_results as $subset => $access_result) {
          $combined_access_results[$subset] = $combined_access_results[$subset]
            ->orIf($access_result);
        }
      }
    }
  }
  return $combined_access_results;
}