rid.inc 1.2 KB

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