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