handler_field_saved_search_link.inc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * @file
  4. * Contains the SearchApiSavedSearchesViewsHandlerFieldName class.
  5. */
  6. /**
  7. * Views field handler for displaying a saved search's name, optionally linked to the search page.
  8. */
  9. class SearchApiSavedSearchesViewsHandlerFieldLink extends views_handler_field {
  10. public function option_definition() {
  11. $options = parent::option_definition();
  12. $options['text'] = array('default' => '');
  13. return $options;
  14. }
  15. public function options_form(&$form, &$form_state) {
  16. $form['text'] = array(
  17. '#type' => 'textfield',
  18. '#title' => t('Link label'),
  19. '#default_value' => $this->options['text'],
  20. );
  21. parent::options_form($form, $form_state);
  22. // The path is set by render() so don't allow to set it.
  23. $form['alter']['path'] = array('#access' => FALSE);
  24. $form['alter']['external'] = array('#access' => FALSE);
  25. }
  26. public function query() {
  27. $this->ensure_my_table();
  28. $this->add_additional_fields();
  29. }
  30. public function render($values) {
  31. $search = !empty($values->id) ? search_api_saved_search_load($values->id) : NULL;
  32. if (search_api_saved_search_edit_access(NULL, $search)) {
  33. $url = $url = 'search-api/saved-search/' . $search->id;
  34. switch ($this->real_field) {
  35. case 'edit_link':
  36. $default_label = t('edit');
  37. $url .= '/edit';
  38. break;
  39. case 'delete_link':
  40. $default_label = t('delete');
  41. $url .= '/delete';
  42. break;
  43. default:
  44. return;
  45. }
  46. $this->options['alter']['make_link'] = TRUE;
  47. $this->options['alter']['path'] = $url;
  48. return $this->options['text'] ? $this->options['text'] : $default_label;
  49. }
  50. }
  51. }