ctools_plugin_example.module 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * @file
  4. * Working sample module to demonstrate CTools 3 plugins.
  5. *
  6. * This sample module is only intended to demonstrate how external modules can
  7. * provide ctools plugins. There is no useful functionality, and it's only
  8. * intended for developers or for educational use.
  9. *
  10. * As far as possible, everything is kept very simple, not exercising all of
  11. * the capabilities of CTools or Panels.
  12. *
  13. * Although the ctools documentation suggests that strict naming conventions
  14. * be followed, this code attempts to follow only the conventions which are
  15. * required (the hooks), in order to demonstrate the difference. You can
  16. * certainly use the conventions, but it's important to know the difference
  17. * between a convention and a requirement.
  18. *
  19. * The advanced_help module is required, because both CTools and this module
  20. * provide help that way.
  21. *
  22. * There is a demonstration panel provided at /ctools_plugin_example/123
  23. */
  24. /**
  25. * Implements hook_menu.
  26. */
  27. function ctools_plugin_example_menu() {
  28. $items = array();
  29. $items["admin/settings/ctools_plugin_example"] = array(
  30. 'title' => 'CTools plugin example',
  31. 'description' => t("Demonstration code, advanced help, and a demo panel to show how to build ctools plugins."),
  32. 'page callback' => 'ctools_plugin_example_explanation_page',
  33. 'access arguments' => array('administer site configuration'),
  34. 'type' => MENU_NORMAL_ITEM,
  35. );
  36. return $items;
  37. }
  38. /**
  39. * Implements hook_ctools_plugin_directory().
  40. *
  41. * It simply tells panels where to find the .inc files that define various
  42. * args, contexts, content_types. In this case the subdirectories of
  43. * ctools_plugin_example/panels are used.
  44. */
  45. function ctools_plugin_example_ctools_plugin_directory($module, $plugin) {
  46. if ($module == 'ctools' && !empty($plugin)) {
  47. return "plugins/$plugin";
  48. }
  49. }
  50. /**
  51. * Implement hook_ctools_plugin_api().
  52. *
  53. * If you do this, CTools will pick up default panels pages in
  54. * <modulename>.pages_default.inc.
  55. */
  56. function ctools_plugin_example_ctools_plugin_api($module, $api) {
  57. // @todo -- this example should explain how to put it in a different file.
  58. if ($module == 'panels_mini' && $api == 'panels_default') {
  59. return array('version' => 1);
  60. }
  61. if ($module == 'page_manager' && $api == 'pages_default') {
  62. return array('version' => 1);
  63. }
  64. }
  65. /**
  66. * Just provide an explanation page for the admin section.
  67. *
  68. * @return unknown_type
  69. */
  70. function ctools_plugin_example_explanation_page() {
  71. $content = '<p>' . t("The CTools Plugin Example is simply a developer's demo of how to create plugins for CTools. It provides no useful functionality for an ordinary user.") . '</p>';
  72. $content .= '<p>' . t(
  73. 'There is a demo panel demonstrating much of the functionality provided at
  74. <a href="@demo_url">CTools demo panel</a>, and you can find documentation on the examples at
  75. !ctools_plugin_example_help.
  76. CTools itself provides documentation at !ctools_help. Mostly, though, the code itself is intended to be the teacher.
  77. You can find it in %path.',
  78. array(
  79. '@demo_url' => url('ctools_plugin_example/xxxxx'),
  80. '!ctools_plugin_example_help' => theme('advanced_help_topic', array('module' => 'ctools_plugin_example', 'topic' => 'Chaos-Tools--CTools--Plugin-Examples', 'type' => 'title')),
  81. '!ctools_help' => theme('advanced_help_topic', array('module' => 'ctools', 'topic' => 'plugins', 'type' => 'title')),
  82. '%path' => drupal_get_path('module', 'ctools_plugin_example'),
  83. )) . '</p>';
  84. return $content;
  85. }