handler_filter_language.inc 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * @file
  4. * Contains the SearchApiViewsHandlerFilterLanguage class.
  5. */
  6. /**
  7. * Views filter handler class for handling the special "Item language" field.
  8. *
  9. * Definition items:
  10. * - options: An array of possible values for this field.
  11. */
  12. class SearchApiViewsHandlerFilterLanguage extends SearchApiViewsHandlerFilterOptions {
  13. /**
  14. * {@inheritdoc}
  15. */
  16. protected function get_value_options() {
  17. parent::get_value_options();
  18. $this->value_options = array(
  19. 'current' => t("Current user's language"),
  20. 'default' => t('Default site language'),
  21. ) + $this->value_options;
  22. }
  23. /**
  24. * Add this filter to the query.
  25. */
  26. public function query() {
  27. global $language_content;
  28. if (!is_array($this->value)) {
  29. $this->value = $this->value ? array($this->value) : array();
  30. }
  31. foreach ($this->value as $i => $v) {
  32. if ($v == 'current') {
  33. $this->value[$i] = $language_content->language;
  34. }
  35. elseif ($v == 'default') {
  36. $this->value[$i] = language_default('language');
  37. }
  38. }
  39. parent::query();
  40. }
  41. }