simplecontext_arg.inc 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * @file
  4. *
  5. * Sample plugin to provide an argument handler for a simplecontext.
  6. *
  7. * Given any argument to the page, simplecontext will get it
  8. * and turn it into a piece of data (a "context") just by adding some text to it.
  9. * Normally, the argument would be a key into some database (like the node
  10. * database, for example, and the result of using the argument would be to load
  11. * a specific "context" or data item that we can use elsewhere.
  12. */
  13. /**
  14. * Plugins are described by creating a $plugin array which will be used
  15. * by the system that includes this file.
  16. */
  17. $plugin = array(
  18. 'title' => t("Simplecontext arg"),
  19. // keyword to use for %substitution
  20. 'keyword' => 'simplecontext',
  21. 'description' => t('Creates a "simplecontext" from the arg.'),
  22. 'context' => 'simplecontext_arg_context',
  23. // 'settings form' => 'simplecontext_arg_settings_form',
  24. // placeholder_form is used in panels preview, for example, so we can
  25. // preview without getting the arg from a URL
  26. 'placeholder form' => array(
  27. '#type' => 'textfield',
  28. '#description' => t('Enter the simplecontext arg'),
  29. ),
  30. );
  31. /**
  32. * Get the simplecontext context using the arg. In this case we're just going
  33. * to manufacture the context from the data in the arg, but normally it would
  34. * be an API call, db lookup, etc.
  35. */
  36. function simplecontext_arg_context($arg = NULL, $conf = NULL, $empty = FALSE) {
  37. // If $empty == TRUE it wants a generic, unfilled context.
  38. if ($empty) {
  39. return ctools_context_create_empty('simplecontext');
  40. }
  41. // Do whatever error checking is required, returning FALSE if it fails the test
  42. // Normally you'd check
  43. // for a missing object, one you couldn't create, etc.
  44. if (empty($arg)) {
  45. return FALSE;
  46. }
  47. return ctools_context_create('simplecontext', $arg);
  48. }