You are here

public function PremiumContent::preprocessSearchQuery in Node Option Premium 8

Preprocesses a search query.

Parameters

\Drupal\search_api\Query\QueryInterface $query: The object representing the query to be executed.

Overrides ProcessorPluginBase::preprocessSearchQuery

File

src/Plugin/search_api/processor/PremiumContent.php, line 138

Class

PremiumContent
Adds premium information to the indexes.

Namespace

Drupal\nopremium\Plugin\search_api\processor

Code

public function preprocessSearchQuery(QueryInterface $query) {
  if (!$query
    ->getOption('search_api_bypass_access')) {
    $account = $query
      ->getOption('search_api_access_account', $this
      ->getCurrentUser());
    if (is_numeric($account)) {
      $account = User::load($account);
    }
    if ($account instanceof AccountInterface) {
      try {
        $this
          ->addPremiumAccess($query, $account);
      } catch (SearchApiException $e) {
        $this
          ->logException($e);
      }
    }
    else {
      $account = $query
        ->getOption('search_api_access_account', $this
        ->getCurrentUser());
      if ($account instanceof AccountInterface) {
        $account = $account
          ->id();
      }
      if (!is_scalar($account)) {
        $account = var_export($account, TRUE);
      }
      $this
        ->getLogger()
        ->warning('An illegal user UID was given for node access: @uid.', [
        '@uid' => $account,
      ]);
    }
  }
}