references_handler_argument.inc 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /**
  3. * @file
  4. * Provide handler to replace reference with title.
  5. */
  6. class references_handler_argument extends views_handler_argument_numeric {
  7. /**
  8. * Use entity title for % placeholders in argument titles.
  9. */
  10. function title_query() {
  11. // Use the same table and field than those used for summary lists
  12. // ('name table', 'name field').
  13. $table_data = views_fetch_data($this->name_table);
  14. $table_info = $table_data['table']['join'][$this->table];
  15. $table = $table_info['table'];
  16. $key_field = $table_info['field'];
  17. $title_field = $this->name_field;
  18. $results = db_select($table, 'base_table')
  19. ->fields('base_table', array($key_field, $title_field))
  20. ->condition("base_table.$key_field", $this->value)
  21. ->execute()
  22. // Grab results as 'key => title' array.
  23. ->fetchAllKeyed();
  24. // Sanitize titles and put them back in the correct order in an unkeyed
  25. // array.
  26. $titles = array();
  27. foreach ($this->value as $key) {
  28. if (isset($results[$key])) {
  29. $titles[] = check_plain($results[$key]);
  30. }
  31. }
  32. return $titles;
  33. }
  34. }