handler_filter_language.inc 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. if (!is_array($this->value)) {
  40. $this->value = $this->value ? array($this->value) : array();
  41. }
  42. foreach ($this->value as $i => $v) {
  43. if ($v == 'current') {
  44. $this->value[$i] = $language_content->language;
  45. }
  46. elseif ($v == 'default') {
  47. $this->value[$i] = language_default('language');
  48. }
  49. }
  50. parent::query();
  51. }
  52. }