You are here

private function KernelEventListener::handleAccessToTermAutocompleteLists in Permissions by Term 8.2

1 call to KernelEventListener::handleAccessToTermAutocompleteLists()
KernelEventListener::onKernelRequest in src/Listener/KernelEventListener.php
Access restriction on kernel request.

File

src/Listener/KernelEventListener.php, line 184

Class

KernelEventListener
Class KernelEventListener.

Namespace

Drupal\permissions_by_term\Listener

Code

private function handleAccessToTermAutocompleteLists(GetResponseEvent $event) {

  // Restrict access to taxonomy terms by autocomplete list.
  if ($event
    ->getRequest()->attributes
    ->get('target_type') === 'taxonomy_term' && $event
    ->getRequest()->attributes
    ->get('_route') === 'system.entity_autocomplete') {
    $query_string = $event
      ->getRequest()
      ->get('q');
    $query_string = trim($query_string);
    $tid = $this->term
      ->getTermIdByName($query_string);
    $term = $this->term
      ->getTerm();
    $termLangcode = \Drupal::languageManager()
      ->getCurrentLanguage()
      ->getId();
    if ($term instanceof Term) {
      $termLangcode = $term
        ->language()
        ->getId();
    }
    if (!$this->accessCheckService
      ->isAccessAllowedByDatabase($tid, \Drupal::currentUser()
      ->id(), $termLangcode)) {
      throw new AccessDeniedHttpException();
    }
  }
}