relcontext_from_simplecontext.inc 1.5 KB

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