simplecontext_arg.inc 1.7 KB

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