search_api_test_hooks.module 1020 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. /**
  3. * @file
  4. * Tests all the hooks defined by the Search API module.
  5. */
  6. use Drupal\search_api\Query\QueryInterface;
  7. use Drupal\search_api\Query\ResultSetInterface;
  8. use Drupal\search_api\Utility\Utility;
  9. /**
  10. * Implements hook_search_api_query_TAG_alter().
  11. */
  12. function search_api_test_hooks_search_api_query_andrew_hill_alter(QueryInterface &$query) {
  13. // Exclude the node with ID 2 from the search results.
  14. $query->setOption('tag query alter hook', TRUE);
  15. $index = $query->getIndex();
  16. $fields = $index->getFields();
  17. foreach ($index->getDatasources() as $datasource_id => $datasource) {
  18. if ($datasource->getEntityTypeId() == 'node') {
  19. $field = Utility::createCombinedId($datasource_id, 'nid');
  20. if (isset($fields[$field])) {
  21. $query->addCondition($field, 2, '<>');
  22. }
  23. }
  24. }
  25. }
  26. /**
  27. * Implements hook_search_api_results_TAG_alter().
  28. */
  29. function search_api_test_hooks_search_api_results_andrew_hill_alter(ResultSetInterface &$results) {
  30. drupal_set_message('Llama');
  31. }