no_context_content_type.inc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * @file
  4. * "No context" sample content type. It operates with no context at all. It would
  5. * be basically the same as a 'custom content' block, but it's not even that
  6. * sophisticated.
  7. *
  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('CTools example no context content type'),
  15. 'description' => t('No context content type - requires and uses no context.'),
  16. // 'single' => TRUE means has no subtypes.
  17. 'single' => TRUE,
  18. // Constructor.
  19. 'content_types' => array('no_context_content_type'),
  20. // Name of a function which will render the block.
  21. 'render callback' => 'no_context_content_type_render',
  22. // The default context.
  23. 'defaults' => array(),
  24. // This explicitly declares the config form. Without this line, the func would be
  25. // ctools_plugin_example_no_context_content_type_edit_form.
  26. 'edit form' => 'no_context_content_type_edit_form',
  27. // Icon goes in the directory with the content type.
  28. 'icon' => 'icon_example.png',
  29. 'category' => array(t('CTools Examples'), -9),
  30. // this example does not provide 'admin info', which would populate the
  31. // panels builder page preview.
  32. );
  33. /**
  34. * Run-time rendering of the body of the block.
  35. *
  36. * @param $subtype
  37. * @param $conf
  38. * Configuration as done at admin time.
  39. * @param $args
  40. * @param $context
  41. * Context - in this case we don't have any.
  42. *
  43. * @return
  44. * An object with at least title and content members.
  45. */
  46. function no_context_content_type_render($subtype, $conf, $args, $context) {
  47. $block = new stdClass();
  48. $ctools_help = theme('advanced_help_topic', array('module' => 'ctools', 'topic' => 'plugins', 'type' => 'title'));
  49. $ctools_plugin_example_help = theme('advanced_help_topic', array('module' => 'ctools_plugin_example', 'topic' => 'Chaos-Tools--CTools--Plugin-Examples', 'type' => 'title'));
  50. // The title actually used in rendering
  51. $block->title = check_plain("No-context content type");
  52. $block->content = t("
  53. <div>Welcome to the CTools Plugin Example demonstration content type.
  54. This block is a content type which requires no context at all. It's like a custom block,
  55. but not even that sophisticated.
  56. For more information on the example plugins, please see the advanced help for
  57. {$ctools_help} and {$ctools_plugin_example_help}
  58. </div>
  59. ");
  60. if (!empty($conf)) {
  61. $block->content .= '<div>The only information that can be displayed in this block comes from the code and its settings form: </div>';
  62. $block->content .= '<div style="border: 1px solid red;">' . var_export($conf, TRUE) . '</div>';
  63. }
  64. return $block;
  65. }
  66. /**
  67. * 'Edit form' callback for the content type.
  68. * This example just returns a form; validation and submission are standard drupal
  69. * Note that if we had not provided an entry for this in hook_content_types,
  70. * this could have had the default name
  71. * ctools_plugin_example_no_context_content_type_edit_form.
  72. *
  73. */
  74. function no_context_content_type_edit_form($form, &$form_state) {
  75. $conf = $form_state['conf'];
  76. $form['item1'] = array(
  77. '#type' => 'textfield',
  78. '#title' => t('Item1'),
  79. '#size' => 50,
  80. '#description' => t('The setting for item 1.'),
  81. '#default_value' => !empty($conf['item1']) ? $conf['item1'] : '',
  82. '#prefix' => '<div class="clear-block no-float">',
  83. '#suffix' => '</div>',
  84. );
  85. $form['item2'] = array(
  86. '#type' => 'textfield',
  87. '#title' => t('Item2'),
  88. '#size' => 50,
  89. '#description' => t('The setting for item 2'),
  90. '#default_value' => !empty($conf['item2']) ? $conf['item2'] : '',
  91. '#prefix' => '<div class="clear-block no-float">',
  92. '#suffix' => '</div>',
  93. );
  94. return $form;
  95. }
  96. function no_context_content_type_edit_form_submit($form, &$form_state) {
  97. foreach (array('item1', 'item2') as $key) {
  98. $form_state['conf'][$key] = $form_state['values'][$key];
  99. }
  100. }