handler_filter_text.inc 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * @file
  4. * Contains SearchApiViewsHandlerFilterText.
  5. */
  6. /**
  7. * Views filter handler class for handling fulltext fields.
  8. */
  9. class SearchApiViewsHandlerFilterText extends SearchApiViewsHandlerFilter {
  10. /**
  11. * Provide a list of options for the operator form.
  12. */
  13. public function operator_options() {
  14. return array('=' => t('contains'), '<>' => t("doesn't contain"));
  15. }
  16. /**
  17. * Determines whether input from the exposed filters affects this filter.
  18. *
  19. * Overridden to not treat "All" differently.
  20. *
  21. * @param array $input
  22. * The user input from the exposed filters.
  23. *
  24. * @return bool
  25. * TRUE if the input should change the behavior of this filter.
  26. */
  27. public function accept_exposed_input($input) {
  28. if (empty($this->options['exposed'])) {
  29. return TRUE;
  30. }
  31. if (!empty($this->options['expose']['use_operator']) && !empty($this->options['expose']['operator_id']) && isset($input[$this->options['expose']['operator_id']])) {
  32. $this->operator = $input[$this->options['expose']['operator_id']];
  33. }
  34. if (!empty($this->options['expose']['identifier'])) {
  35. $value = $input[$this->options['expose']['identifier']];
  36. // Various ways to check for the absence of non-required input.
  37. if (empty($this->options['expose']['required'])) {
  38. if (($this->operator == 'empty' || $this->operator == 'not empty') && $value === '') {
  39. $value = ' ';
  40. }
  41. if (!empty($this->always_multiple) && $value === '') {
  42. return FALSE;
  43. }
  44. }
  45. if (isset($value)) {
  46. $this->value = $value;
  47. if (empty($this->always_multiple) && empty($this->options['expose']['multiple'])) {
  48. $this->value = array($value);
  49. }
  50. }
  51. else {
  52. return FALSE;
  53. }
  54. }
  55. return TRUE;
  56. }
  57. }