relcontext_from_simplecontext.inc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * @file
  4. * Sample relationship plugin.
  5. *
  6. * We take a simplecontext, look in it for what we need to make a relcontext, and make it.
  7. * In the real world, this might be getting a taxonomy id from a node, for example.
  8. */
  9. /**
  10. * Plugins are described by creating a $plugin array which will be used
  11. * by the system that includes this file.
  12. */
  13. $plugin = array(
  14. 'title' => t("Relcontext from simplecontext"),
  15. 'keyword' => 'relcontext',
  16. 'description' => t('Adds a relcontext from existing simplecontext.'),
  17. 'required context' => new ctools_context_required(t('Simplecontext'), 'simplecontext'),
  18. 'context' => 'ctools_relcontext_from_simplecontext_context',
  19. 'settings form' => 'ctools_relcontext_from_simplecontext_settings_form',
  20. );
  21. /**
  22. * Return a new context based on an existing context.
  23. */
  24. function ctools_relcontext_from_simplecontext_context($context = NULL, $conf) {
  25. // If unset it wants a generic, unfilled context, which is just NULL.
  26. if (empty($context->data)) {
  27. return ctools_context_create_empty('relcontext', NULL);
  28. }
  29. // You should do error-checking here.
  30. // Create the new context from some element of the parent context.
  31. // In this case, we'll pass in the whole context so it can be used to
  32. // create the relcontext.
  33. return ctools_context_create('relcontext', $context);
  34. }
  35. /**
  36. * Settings form for the relationship.
  37. */
  38. function ctools_relcontext_from_simplecontext_settings_form($conf) {
  39. // We won't configure it in this case.
  40. return array();
  41. }