handler_filter_language.inc 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. * Provide a form for setting options.
  15. */
  16. public function value_form(&$form, &$form_state) {
  17. parent::value_form($form, $form_state);
  18. $form['value']['#options'] = array(
  19. 'current' => t("Current user's language"),
  20. 'default' => t('Default site language'),
  21. ) + $form['value']['#options'];
  22. }
  23. /**
  24. * Provides a summary of this filter's value for the admin UI.
  25. */
  26. public function admin_summary() {
  27. $tmp = $this->definition['options'];
  28. $this->definition['options']['current'] = t('current');
  29. $this->definition['options']['default'] = t('default');
  30. $ret = parent::admin_summary();
  31. $this->definition['options'] = $tmp;
  32. return $ret;
  33. }
  34. /**
  35. * Add this filter to the query.
  36. */
  37. public function query() {
  38. global $language_content;
  39. foreach ($this->value as $i => $v) {
  40. if ($v == 'current') {
  41. $this->value[$i] = $language_content->language;
  42. }
  43. elseif ($v == 'default') {
  44. $this->value[$i] = language_default('language');
  45. }
  46. }
  47. parent::query();
  48. }
  49. }