Projet

Général

Profil

Paste
Télécharger (2,95 ko) Statistiques
| Branche: | Révision:

root / htmltest / sites / all / modules / ctools / help / plugins-implementing.html @ a5572547

1 85ad3d82 Assos Assos
<p>There are two parts to implementing a plugin: telling the system where it is, and implementing one or more .inc files that contain the plugin data.</p>
2
3
<h2>Telling the system where your plugins live</h2>
4
<h3>How a module implements plugins</h3>
5
<p>To implement any plugins at all, you must implement a single function for all plugins: <strong>hook_ctools_plugin_directory</strong>. Every time a module loads plugins, this hook will be called to see which modules implement those plugins and in what directory those plugins will live.</p>
6
7
<pre>
8
function hook_ctools_plugin_directory($module, $plugin) {
9
  if ($module == 'panels' && $plugin == 'content_types') {
10
    return 'plugins/content_types';
11
  }
12
}
13
</pre>
14
15
<p>The directory returned should be relative to your module. Another common usage is to simply return that you implement all plugins owned by a given module (or modules):</p>
16
17
<pre>
18
function hook_ctools_plugin_directory($module, $plugin) {
19
  if ($module == 'panels') {
20
    return 'plugins/' . $plugin;
21
  }
22
}
23
</pre>
24
25
<p>Typically, it is recommended that all plugins be placed into the 'plugins' directory for clarity and maintainability. Inside the directory, any number of subdirectories can be used. For plugins that require extra files, such as templates, css, javascript or image files, this is highly recommended:</p>
26
<pre>
27
mymodule.module
28
mymodule.info
29
plugins/
30
    content_types/
31
        my_content_type.inc
32
    layouts/
33
        my_layout.inc
34
        my_layout.css
35
        my_layout.tpl.php
36
        my_layout_image.png
37
</pre>
38
39
<h3>How a theme implements plugins</h3>
40
<p>Themes can implement plugins if the plugin owner specified that it's possible in its hook_ctools_plugin_type() call. If so, it is generally exactly the same as modules, except for one important difference: themes don't get hook_ctools_plugin_directory(). Instead, themes add a line to their .info file:</p>
41
42
<pre>
43
plugins[module][type] = directory
44
</pre>
45
46
<h2>How to structure the .inc file</h2>
47
48
<p>The top of the .inc file should contain an array that defines the plugin. This array is simply defined in the global namespace of the file and does not need a function. Note that previous versions of this plugin system required a specially named function. While this function will still work, its use is now discouraged, as it is annoying to name properly.</p>
49
50
<p>This array should look something like this:</p>
51
52
<pre>
53
$plugin = array(
54
  'key' => 'value',
55
);
56
</pre>
57
58
<p>Several values will be filled in for you automatically, but you can override them if necessary. They include 'name', 'path', 'file' and 'module'. Additionally, the plugin owner can provide other defaults as well.</p>
59
60
<p>There are no required keys by the plugin system itself. The only requirements in the $plugin array will be defined by the plugin type.</p>
61
62
<p>After this array, if your plugin needs functions, they can be declared. Different plugin types have different needs here, so exactly what else will be needed will change from type to type.</p>