Stripping CVS keywords
[project/ctools.git] / ctools.api.php
CommitLineData
a40482ac 1<?php
a40482ac
SB
2
3/**
4 * @file
5 * Hooks provided by the Chaos Tool Suite.
6 *
7 * This file is divided into static hooks (hooks with string literal names) and
8 * dynamic hooks (hooks with pattern-derived string names).
9 */
10
11/**
12 * @addtogroup hooks
13 * @{
14 */
15
16/**
17 * This hook is used to inform the CTools plugin system about the location of a
18 * directory that should be searched for files containing plugins of a
19 * particular type. CTools invokes this same hook for all plugins, using the
20 * two passed parameters to indicate the specific type of plugin for which it
21 * is searching.
22 *
23 * The $plugin_type parameter is self-explanatory - it is the string name of the
24 * plugin type (e.g., Panels' 'layouts' or 'styles'). The $owner parameter is
25 * necessary because CTools internally namespaces plugins by the module that
26 * owns them. This is an extension of Drupal best practices on avoiding global
27 * namespace pollution by prepending your module name to all its functions.
28 * Consequently, it is possible for two different modules to create a plugin
29 * type with exactly the same name and have them operate in harmony. In fact,
30 * this system renders it impossible for modules to encroach on other modules'
31 * plugin namespaces.
32 *
33 * Given this namespacing, it is important that implementations of this hook
34 * check BOTH the $owner and $plugin_type parameters before returning a path.
35 * If your module does not implement plugins for the requested module/plugin
36 * combination, it is safe to return nothing at all (or NULL). As a convenience,
37 * it is also safe to return a path that does not exist for plugins your module
38 * does not implement - see form 2 for a use case.
39 *
40 * Note that modules implementing a plugin also must implement this hook to
41 * instruct CTools as to the location of the plugins. See form 3 for a use case.
42 *
43 * The conventional structure to return is "plugins/$plugin_type" - that is, a
44 * 'plugins' subdirectory in your main module directory, with individual
45 * directories contained therein named for the plugin type they contain.
46 *
47 * @param string $owner
48 * The system name of the module owning the plugin type for which a base
49 * directory location is being requested.
50 * @param string $plugin_type
51 * The name of the plugin type for which a base directory is being requested.
52 * @return string
53 * The path where CTools' plugin system should search for plugin files,
54 * relative to your module's root. Omit leading and trailing slashes.
55 */
56function hook_ctools_plugin_directory($owner, $plugin_type) {
57 // Form 1 - for a module implementing only the 'content_types' plugin owned
58 // by CTools, this would cause the plugin system to search the
59 // <moduleroot>/plugins/content_types directory for .inc plugin files.
60 if ($owner == 'ctools' && $plugin_type == 'content_types') {
61 return 'plugins/content_types';
62 }
63
64 // Form 2 - if your module implements only Panels plugins, and has 'layouts'
65 // and 'styles' plugins but no 'cache' or 'display_renderers', it is OK to be
66 // lazy and return a directory for a plugin you don't actually implement (so
67 // long as that directory doesn't exist). This lets you avoid ugly in_array()
68 // logic in your conditional, and also makes it easy to add plugins of those
69 // types later without having to change this hook implementation.
70 if ($owner == 'panels') {
71 return "plugins/$plugin_type";
72 }
73
74 // Form 3 - CTools makes no assumptions about where your plugins are located,
75 // so you still have to implement this hook even for plugins created by your
76 // own module.
77 if ($owner == 'mymodule') {
78 // Yes, this is exactly like Form 2 - just a different reasoning for it.
79 return "plugins/$plugin_type";
80 }
81 // Finally, if nothing matches, it's safe to return nothing at all (or NULL).
82}
83
84/**
85 * @} End of "addtogroup hooks".
86 */