flag_handler_argument_entity_id.inc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * @file
  4. * Contains the content ID argument handler.
  5. */
  6. /**
  7. * Handler to accept an argument of the content ID of any object.
  8. *
  9. * @ingroup views
  10. */
  11. class flag_handler_argument_entity_id extends views_handler_argument_numeric {
  12. /**
  13. * Returns the flag object associated with our argument.
  14. *
  15. * An argument is in some relationship. This function reaches out for this
  16. * relationship and reads its 'flag' option, which holds the flag name.
  17. */
  18. function get_flag() {
  19. return $this->view->relationship[$this->options['relationship']]->get_flag();
  20. }
  21. /**
  22. * Override the behavior of title(). Get the title of the appropriate objects.
  23. */
  24. function title_query() {
  25. if (!($flag = $this->get_flag())) {
  26. // Error message is printed by get_flag().
  27. return array();
  28. }
  29. $views_info = $flag->get_views_info();
  30. $titles = array();
  31. $placeholders = implode(', ', array_fill(0, count($this->value), '%d'));
  32. $result = db_select($views_info['views table'], 'o')
  33. ->fields('o', array($views_info['title field']))
  34. ->condition('o.' . $views_info['join field'], $this->value, 'IN')
  35. ->execute();
  36. foreach ($result as $title) {
  37. $titles[] = check_plain($title->$views_info['title field']);
  38. }
  39. return $titles;
  40. }
  41. }