You are here

function _search_api_saved_searches_delete_searches in Search API Saved Searches 8

Deletes saved searches based on the specified criterion.

Parameters

string $field: The saved search field to match against.

mixed $value: The field value to look for.

2 calls to _search_api_saved_searches_delete_searches()
search_api_saved_searches_search_api_index_delete in ./search_api_saved_searches.module
Implements hook_ENTITY_TYPE_delete() for type "search_api_index".
search_api_saved_searches_user_delete in ./search_api_saved_searches.module
Implements hook_ENTITY_TYPE_delete() for type "user".

File

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

Code

function _search_api_saved_searches_delete_searches($field, $value) {
  $ids = \Drupal::entityQuery('search_api_saved_search')
    ->condition($field, $value)
    ->accessCheck(FALSE)
    ->execute();
  if (!$ids) {
    return;
  }
  try {
    $storage = \Drupal::entityTypeManager()
      ->getStorage('search_api_saved_search');
    $searches = $storage
      ->loadMultiple($ids);
    if ($searches) {
      $storage
        ->delete($searches);
    }
  } catch (\Exception $e) {
    $args['@field'] = $field;
    $args['@value'] = $value;
    watchdog_exception('search_api_saved_searches', $e, '%type while trying to delete saved searches (condition: @field = @value): @message in %function (line %line of %file).', $args);
  }
}