no_context_content_type.inc 3.8 KB

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