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