search_api_saved_searches.views.inc 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * @file
  4. * Defines Views hook implementations.
  5. */
  6. /**
  7. * Implements hook_views_data_alter().
  8. *
  9. * Adds relationships to the creator of a saved search, its settings and the
  10. * search index, as well as edit and delete links, and changes some field
  11. * handlers.
  12. */
  13. function search_api_saved_searches_views_data_alter(array &$data) {
  14. // Relationship: settings => index.
  15. $data['search_api_saved_searches_settings']['index_id']['relationship'] = array(
  16. 'base' => 'search_api_index',
  17. 'base field' => 'machine_name',
  18. 'title' => t('Search index'),
  19. 'label' => t('search index'),
  20. );
  21. // Relationship: search => user.
  22. $data['search_api_saved_search']['uid']['relationship'] = array(
  23. 'base' => 'users',
  24. 'base field' => 'uid',
  25. 'title' => t('User'),
  26. 'label' => t('user'),
  27. );
  28. // Relationship: search => settings.
  29. $data['search_api_saved_search']['settings_id']['relationship'] = array(
  30. 'base' => 'search_api_saved_searches_settings',
  31. 'base field' => 'delta',
  32. 'title' => t('Settings'),
  33. 'label' => t('settings'),
  34. );
  35. // Proper field type for notify_interval.
  36. $data['search_api_saved_search']['notify_interval']['field']['handler'] = 'SearchApiSavedSearchesViewsHandlerFieldInterval';
  37. $data['search_api_saved_search']['notify_interval']['field']['additional fields'] = array('id');
  38. // Use our own handler so we can link the name to the search results.
  39. $data['search_api_saved_search']['name']['field']['handler'] = 'SearchApiSavedSearchesViewsHandlerFieldName';
  40. $data['search_api_saved_search']['name']['field']['additional fields'] = array('id');
  41. // We have to do this here, not in hook_views_data(), since the table itself
  42. // comes from another module and one definition would overwrite the other.
  43. $data['search_api_saved_search']['edit_link']['field'] = array(
  44. 'title' => t('Edit link'),
  45. 'help' => t('Display a link that allows the user to edit the saved search, if they have the necessary permissions.'),
  46. 'handler' => 'SearchApiSavedSearchesViewsHandlerFieldLink',
  47. 'additional fields' => array('id'),
  48. );
  49. $data['search_api_saved_search']['delete_link']['field'] = array(
  50. 'title' => t('Delete link'),
  51. 'help' => t('Display a link that allows the user to delete the saved search, if they have the necessary permissions.'),
  52. 'handler' => 'SearchApiSavedSearchesViewsHandlerFieldLink',
  53. 'additional fields' => array('id'),
  54. );
  55. $data['search_api_saved_search']['results']['field'] = array(
  56. 'title' => t('Results'),
  57. 'help' => t('The saved search results of this search.'),
  58. 'handler' => 'entity_views_handler_field_text',
  59. 'additional fields' => array('id'),
  60. 'type' => 'list<token>',
  61. );
  62. }