You are here

function _search_api_saved_searches_load_searches in Search API Saved Searches 8

Loads all saved searches, optionally filtering by UID or e-mail address.

Parameters

int|null $uid: (optional) The owner UID to filter for, if any.

string|null $mail: (optional) The e-mail address to filter for, if any.

Return value

\Drupal\search_api_saved_searches\SavedSearchInterface[] The requested saved searches.

3 calls to _search_api_saved_searches_load_searches()
_search_api_saved_searches_adapt_mail in ./search_api_saved_searches.module
Updates a user's saved searches to reflect a changed mail address.
_search_api_saved_searches_claim_anonymous_searches in ./search_api_saved_searches.module
Reacts to the creation or activation of a new user account.
_search_api_saved_searches_deactivate_searches in ./search_api_saved_searches.module
Deactivates all saved searches for a specific user account.

File

./search_api_saved_searches.module, line 247
Allows visitors to bookmark searches and get notifications for new results.

Code

function _search_api_saved_searches_load_searches($uid = NULL, $mail = NULL) {
  try {
    $query = \Drupal::entityQuery('search_api_saved_search');
    if ($mail !== NULL) {
      $query
        ->condition('mail', $mail);
    }
    if ($uid !== NULL) {
      $query
        ->condition('uid', $uid);
    }
    $ids = $query
      ->accessCheck(FALSE)
      ->execute();
    if (!$ids) {
      return [];
    }

    /** @var \Drupal\search_api_saved_searches\SavedSearchInterface[] $searches */
    $searches = \Drupal::entityTypeManager()
      ->getStorage('search_api_saved_search')
      ->loadMultiple($ids);
    return $searches;
  } catch (\Exception $e) {
    watchdog_exception('search_api_saved_searches', $e);
    return [];
  }
}