Removing translation directories
[project/ctools.git] / help / export-ui.html
CommitLineData
a40482ac
SB
1Most user interfaces for exportables are very similar, so CTools includes a tool to provide the framework for the most common UI. This tool is a plugin of the 'export_ui' type. In order to create a UI for your exportable object with this tool, you first need to ensure that your module supports the plugin:
2
3<pre>
4function HOOK_ctools_plugin_directory($module, $plugin) {
5 if ($module == 'ctools' && $plugin == 'export_ui') {
6 return 'plugins/' . $plugin;
7 }
8}
9</pre>
10
11Then, you need to create a plugin .inc file describing your UI. Most of the UI runs with sane but simple defaults, so for the very simplest UI you don't need to do very much. This is a very simple example plugin for the 'example' export type:
12
13<pre>
14$plugin = array(
15 // The name of the table as found in the schema in hook_install. This
16 // must be an exportable type with the 'export' section defined.
17 'schema' => 'example',
18
19 // The access permission to use. If not provided it will default to
20 // 'administer site configuration'
21 'access' => 'administer example',
22
23 // You can actually define large chunks of the menu system here. Nothing
24 // is required here. If you leave out the values, the prefix will default
25 // to admin/structure and the item will default to the plugin name.
26 'menu' => array(
27 'menu prefix' => 'admin/structure',
28 'menu item' => 'example',
29 // Title of the top level menu. Note this should not be translated,
30 // as the menu system will translate it.
31 'menu title' => 'Example',
32 // Description of the top level menu, which is usually needed for
33 // menu items in an administration list. Will be translated
34 // by the menu system.
35 'menu description' => 'Administer site example objects.',
36 ),
37
38 // These are required to provide proper strings for referring to the
39 // actual type of exportable. "proper" means it will appear at the
40 // beginning of a sentence.
41 'title singular' => t('example'),
42 'title singular proper' => t('Example'),
43 'title plural' => t('examples'),
44 'title plural proper' => t('Examples'),
45
46 // This will provide you with a form for editing the properties on your
47 // exportable, with validate and submit handler.
48 //
49 // The item being edited will be in $form_state['item'].
50 //
51 // The submit handler is only responsible for moving data from
52 // $form_state['values'] to $form_state['item'].
53 //
54 // All callbacks will accept &$form and &$form_state as arguments.
55 'form' => array(
56 'settings' => 'example_ctools_export_ui_form',
57 'validate' => 'example_ctools_export_ui_form_validate',
58 'submit' => 'example_ctools_export_ui_form_submit',
59 ),
60
61);
62</pre>
63
64For a more complete list of what you can set in your plugin, please see ctools_export_ui_defaults() in includes/export-ui.inc to see what the defaults are.
65
66<h3>More advanced UIs</h3>
67The bulk of this UI is built on an class called ctools_export_ui, which is itself stored in ctools/plugins/export_ui as the default plugin. Many UIs will have more complex needs than the defaults provide. Using OO and overriding methods can allow an implementation to use the basics and still provide more where it is needed. To utilize this, first add a 'handler' directive to your plugin .inc file:
68
69<pre>
70 'handler' => array(
71 'class' => 'ctools_export_ui_example',
72 'parent' => 'ctools_export_ui',
73 ),
74</pre>
75
76Then create your class in ctools_export_ui_example.class.php in your plugins directory:
77
78<pre>
79class ctools_export_ui_example extends ctools_export_ui {
80
81}
82</pre>
83
84You can override any method found in the class (see the source file for details). In particular, there are several list methods that are good candidates for overriding if you need to provide richer data for listing, sorting or filtering. If you need multi-step add/edit forms, you can override edit_page(), add_page(), clone_page(), and import_page() to put your wizard in place of the basic editing system. For an example of how to use multi-step wizards, see the import_page() method.