synonyms.views.inc 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. /**
  3. * @file
  4. * Views integration of Synonyms module.
  5. */
  6. /**
  7. * Implements hook_views_plugins_alter().
  8. */
  9. function synonyms_views_plugins_alter(&$plugins) {
  10. // Replace default taxonomy term argument validator with our extended version,
  11. // which can also handle a term synonym as an argument.
  12. $plugins['argument validator']['taxonomy_term']['handler'] = 'synonyms_views_plugin_argument_validate_taxonomy_term';
  13. }
  14. /**
  15. * Implements hook_field_views_data_alter().
  16. */
  17. function synonyms_field_views_data_alter(&$result, $field, $module) {
  18. if ($field['type'] == 'taxonomy_term_reference') {
  19. // Add synonyms friendly autocomplete filter.
  20. foreach ($field['storage']['details']['sql'] as $table) {
  21. $tid_column = reset($table);
  22. $tid_column = $tid_column['tid'];
  23. $table = array_keys($table);
  24. $table = $table[0];
  25. if (isset($result[$table][$tid_column]['filter'])) {
  26. $result[$table][$tid_column]['filter']['handler'] = 'synonyms_views_handler_filter_term_tid';
  27. }
  28. }
  29. }
  30. }