search_api_views.module

Tracking 7.x-1.x branch
  1. drupal
    1. 7 contributions/search_api/contrib/search_api_views/search_api_views.module

Functions & methods

NameDescription
search_api_views_search_api_index_deleteImplements hook_search_api_index_delete().
search_api_views_search_api_index_insertImplements hook_search_api_index_insert().
search_api_views_search_api_index_updateImplements hook_search_api_index_update().
search_api_views_views_apiImplements hook_views_api().
_search_api_views_index_unavailableFunction for reacting to a disabled or deleted search index.

File

View source
  1. <?php
  2. /**
  3. * Implements hook_views_api().
  4. */
  5. function search_api_views_views_api() {
  6. return array(
  7. 'api' => '3.0-alpha1',
  8. );
  9. }
  10. /**
  11. * Implements hook_search_api_index_insert().
  12. */
  13. function search_api_views_search_api_index_insert(SearchApiIndex $index) {
  14. // Make the new index available for views.
  15. views_invalidate_cache();
  16. }
  17. /**
  18. * Implements hook_search_api_index_update().
  19. */
  20. function search_api_views_search_api_index_update(SearchApiIndex $index) {
  21. if (!$index->enabled && $index->original->enabled) {
  22. _search_api_views_index_unavailable($index);
  23. }
  24. }
  25. /**
  26. * Implements hook_search_api_index_delete().
  27. */
  28. function search_api_views_search_api_index_delete(SearchApiIndex $index) {
  29. _search_api_views_index_unavailable($index);
  30. }
  31. /**
  32. * Function for reacting to a disabled or deleted search index.
  33. */
  34. function _search_api_views_index_unavailable(SearchApiIndex $index) {
  35. $names = array();
  36. $table = 'search_api_index_' . $index->machine_name;
  37. foreach (views_get_all_views() as $name => $view) {
  38. if (empty($view->disabled) && $view->base_table == $table) {
  39. $names[] = $name;
  40. // @todo: if ($index_deleted) $view->delete()?
  41. }
  42. }
  43. if ($names) {
  44. views_invalidate_cache();
  45. drupal_set_message(t('The following views were using the index %name: @views. You should disable or delete them.', array('%name' => $index->name, '@views' => implode(', ', $names))), 'warning');
  46. }
  47. }