relcontext_content_type.inc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * @file
  4. * Content type that displays the relcontext context type.
  5. *
  6. * This example is for use with the relcontext relationship to show
  7. * how we can get a relationship-context into a data type.
  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. // Used in add content dialogs.
  15. 'title' => t('CTools example relcontext content type'),
  16. 'admin info' => 'ctools_plugin_example_relcontext_content_type_admin_info',
  17. 'content_types' => 'relcontext_content_type',
  18. 'single' => TRUE,
  19. 'render callback' => 'relcontext_content_type_render',
  20. // Icon goes in the directory with the content type. Here, in plugins/content_types.
  21. 'icon' => 'icon_example.png',
  22. 'description' => t('Relcontext content type - works with relcontext context.'),
  23. 'required context' => new ctools_context_required(t('Relcontext'), 'relcontext'),
  24. 'category' => array(t('CTools Examples'), -9),
  25. 'edit form' => 'relcontext_edit_form',
  26. // This example does not provide 'admin info', which would populate the
  27. // panels builder page preview.
  28. );
  29. /**
  30. * Run-time rendering of the body of the block.
  31. *
  32. * @param $subtype
  33. * @param $conf
  34. * Configuration as done at admin time
  35. * @param $args
  36. * @param $context
  37. * Context - in this case we don't have any
  38. *
  39. * @return
  40. * An object with at least title and content members
  41. */
  42. function relcontext_content_type_render($subtype, $conf, $args, $context) {
  43. $data = $context->data;
  44. $block = new stdClass();
  45. // Don't forget to check this data if it's untrusted.
  46. // The title actually used in rendering.
  47. $block->title = "Relcontext content type";
  48. $block->content = t("
  49. This is a block of data created by the Relcontent content type.
  50. Data in the block may be assembled from static text (like this) or from the
  51. content type settings form (\$conf) for the content type, or from the context
  52. that is passed in. <br />
  53. In our case, the configuration form (\$conf) has just one field, 'config_item_1;
  54. and it's configured with:
  55. ");
  56. if (!empty($conf)) {
  57. $block->content .= '<div style="border: 1px solid red;">' . var_export($conf['config_item_1'], TRUE) . '</div>';
  58. }
  59. if (!empty($context)) {
  60. $block->content .= '<br />The args ($args) were <div style="border: 1px solid yellow;" >' .
  61. var_export($args, TRUE) . '</div>';
  62. }
  63. $block->content .= '<br />And the relcontext context ($context->data->description)
  64. (which was created from a
  65. simplecontext context) was <div style="border: 1px solid green;" >' .
  66. print_r($context->data->description, TRUE) . '</div>';
  67. return $block;
  68. }
  69. /**
  70. * 'Edit' callback for the content type.
  71. * This example just returns a form.
  72. */
  73. function relcontext_edit_form($form, &$form_state) {
  74. $conf = $form_state['conf'];
  75. $form['config_item_1'] = array(
  76. '#type' => 'textfield',
  77. '#title' => t('Config Item 1 (relcontext)'),
  78. '#size' => 50,
  79. '#description' => t('Setting for relcontext.'),
  80. '#default_value' => !empty($conf['config_item_1']) ? $conf['config_item_1'] : '',
  81. '#prefix' => '<div class="clear-block no-float">',
  82. '#suffix' => '</div>',
  83. );
  84. return $form;
  85. }
  86. function relcontext_edit_form_submit($form, &$form_state) {
  87. foreach (element_children($form) as $key) {
  88. if (!empty($form_state['values'][$key])) {
  89. $form_state['conf'][$key] = $form_state['values'][$key];
  90. }
  91. }
  92. }