node_edit.inc 1.2 KB

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