nid.inc 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * @file
  4. *
  5. * Plugin to provide an argument handler for a node 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("Node: ID"),
  13. 'keyword' => 'node',
  14. 'description' => t('Creates a node context from a node ID argument.'),
  15. 'context' => 'ctools_argument_nid_context',
  16. 'placeholder form' => array(
  17. '#type' => 'textfield',
  18. '#description' => t('Enter the node ID of a node for this argument'),
  19. ),
  20. 'no ui' => TRUE,
  21. );
  22. /**
  23. * Discover if this argument gives us the node we crave.
  24. */
  25. function ctools_argument_nid_context($arg = NULL, $conf = NULL, $empty = FALSE) {
  26. // If unset it wants a generic, unfilled context.
  27. if ($empty) {
  28. return ctools_context_create_empty('node');
  29. }
  30. // We can accept either a node object or a pure nid.
  31. if (is_object($arg)) {
  32. return ctools_context_create('node', $arg);
  33. }
  34. if (!is_numeric($arg)) {
  35. return FALSE;
  36. }
  37. $node = node_load($arg);
  38. if (!$node) {
  39. return FALSE;
  40. }
  41. return ctools_context_create('node', $node);
  42. }