rid.inc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * @file
  4. * Plugin to provide an argument handler for a node revision id.
  5. */
  6. /**
  7. * Plugins are described by creating a $plugin array which will be used
  8. * by the system that includes this file.
  9. */
  10. $plugin = array(
  11. 'title' => t("Revision: ID"),
  12. 'keyword' => 'revision',
  13. 'description' => t('Creates a node context from a revision ID argument.'),
  14. 'context' => 'ctools_argument_rid_context',
  15. 'placeholder form' => array(
  16. '#type' => 'textfield',
  17. '#description' => t('Enter the revision ID of a node for this argument'),
  18. ),
  19. );
  20. /**
  21. * Discover if this argument gives us the node we crave.
  22. */
  23. function ctools_argument_rid_context($arg = NULL, $conf = NULL, $empty = FALSE) {
  24. // If unset it wants a generic, unfilled context.
  25. if ($empty) {
  26. return ctools_context_create_empty('node');
  27. }
  28. // We can accept either a node object or a pure nid.
  29. if (is_object($arg)) {
  30. return ctools_context_create('node', $arg);
  31. }
  32. if (!is_numeric($arg)) {
  33. return FALSE;
  34. }
  35. $nid = db_query('SELECT nid FROM {node_revision} WHERE vid = :vid', array(':vid' => $arg))->fetchField();
  36. $node = node_load($nid, $arg);
  37. if (!$node) {
  38. return FALSE;
  39. }
  40. return ctools_context_create('node', $node);
  41. }