node_edit.inc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * @file
  4. *
  5. * Plugin to provide an argument handler for a Node edit form
  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 edit form: node ID"),
  13. // keyword to use for %substitution
  14. 'keyword' => 'node',
  15. 'description' => t('Creates a node edit form context from a node ID argument.'),
  16. 'context' => 'ctools_node_edit_context',
  17. 'placeholder form' => array(
  18. '#type' => 'textfield',
  19. '#description' => t('Enter the node ID of a node for this argument'),
  20. ),
  21. );
  22. /**
  23. * Discover if this argument gives us the node we crave.
  24. */
  25. function ctools_node_edit_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_edit_form');
  29. }
  30. // We can accept either a node object or a pure nid.
  31. if (is_object($arg)) {
  32. return ctools_context_create('node_edit_form', $arg);
  33. }
  34. if (!is_numeric($arg)) {
  35. return FALSE;
  36. }
  37. $node = node_load($arg);
  38. if (!$node) {
  39. return NULL;
  40. }
  41. // This will perform a node_access check, so we don't have to.
  42. return ctools_context_create('node_edit_form', $node);
  43. }