nid.inc 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * @file
  4. * Plugin to provide an argument handler for a node 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("Node: ID"),
  12. 'keyword' => 'node',
  13. 'description' => t('Creates a node context from a node ID argument.'),
  14. 'context' => 'ctools_argument_nid_context',
  15. 'placeholder form' => array(
  16. '#type' => 'textfield',
  17. '#description' => t('Enter the node ID of a node for this argument'),
  18. ),
  19. 'no ui' => TRUE,
  20. );
  21. /**
  22. * Discover if this argument gives us the node we crave.
  23. */
  24. function ctools_argument_nid_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. $node = node_load($arg);
  37. if (!$node) {
  38. return FALSE;
  39. }
  40. return ctools_context_create('node', $node);
  41. }