relcontext.inc 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * @file
  4. * Sample ctools context type plugin that
  5. * is used in this demo to create a relcontext from an existing simplecontext.
  6. */
  7. /**
  8. * Plugins are described by creating a $plugin array which will be used
  9. * by the system that includes this file.
  10. */
  11. $plugin = array(
  12. 'title' => t("Relcontext"),
  13. 'description' => t('A relcontext object.'),
  14. // Function to create the relcontext.
  15. 'context' => 'ctools_plugin_example_context_create_relcontext',
  16. // Function that does the settings.
  17. 'settings form' => 'relcontext_settings_form',
  18. 'keyword' => 'relcontext',
  19. 'context name' => 'relcontext',
  20. );
  21. /**
  22. * Create a context, either from manual configuration (form) or from an argument on the URL.
  23. *
  24. * @param $empty
  25. * If true, just return an empty context.
  26. * @param $data
  27. * If from settings form, an array as from a form. If from argument, a string.
  28. * @param $conf
  29. * TRUE if the $data is coming from admin configuration, FALSE if it's from a URL arg.
  30. *
  31. * @return
  32. * a Context object.
  33. */
  34. function ctools_plugin_example_context_create_relcontext($empty, $data = NULL, $conf = FALSE) {
  35. $context = new ctools_context('relcontext');
  36. $context->plugin = 'relcontext';
  37. if ($empty) {
  38. return $context;
  39. }
  40. if ($conf) {
  41. if (!empty($data)) {
  42. $context->data = new stdClass();
  43. // For this simple item we'll just create our data by stripping non-alpha and
  44. // adding 'sample_relcontext_setting' to it.
  45. $context->data->description = 'relcontext_from__' . preg_replace('/[^a-z]/i', '', $data['sample_relcontext_setting']);
  46. $context->data->description .= '_from_configuration_sample_simplecontext_setting';
  47. $context->title = t("Relcontext context from simplecontext");
  48. return $context;
  49. }
  50. }
  51. else {
  52. // $data is coming from an arg - it's just a string.
  53. // This is used for keyword.
  54. $context->title = "relcontext_" . $data->data->description;
  55. $context->argument = $data->argument;
  56. // Make up a bogus context.
  57. $context->data = new stdClass();
  58. // For this simple item we'll just create our data by stripping non-alpha and
  59. // prepend 'relcontext_' and adding '_created_from_from_simplecontext' to it.
  60. $context->data->description = 'relcontext_' . preg_replace('/[^a-z]/i', '', $data->data->description);
  61. $context->data->description .= '_created_from_simplecontext';
  62. return $context;
  63. }
  64. }
  65. function relcontext_settings_form($conf, $external = FALSE) {
  66. $form = array();
  67. $form['sample_relcontext_setting'] = array(
  68. '#type' => 'textfield',
  69. '#title' => t('Relcontext setting'),
  70. '#size' => 50,
  71. '#description' => t('Just an example setting.'),
  72. '#default_value' => !empty($conf['sample_relcontext_setting']) ? $conf['sample_relcontext_setting'] : '',
  73. '#prefix' => '<div class="clear-block no-float">',
  74. '#suffix' => '</div>',
  75. );
  76. return $form;
  77. }