Page 1
“This suite is primarily a set of APIs and tools to improve thedeveloper experience”
Controlling the Chaos
What is Ctools?
Page 2
1
Plugins2
Exportables
3
Ajax Responder
4
Form tools5 Object Caching
7
6
9
8
What is Ctools?Contexts
Modal dialog
Dependant
Content
10
Form Wizard
Page 3
What is Ctools?
Exportables01
“Tools to make it easier for modules to have objects thatlive in database or live in code, such as 'default views'.”
Page 4
What is Ctools?
AJAX Responder02
“Tools to make it easier for the server to handle AJAXrequests and tell the client what to do with them.”
Page 5
What is Ctools?
Form Wizard03
“An API to make multi-step forms much easier.”
Page 6
What is Ctools?
Modal Dialog04
“Tool to make it simple to put a form in a modal dialog.”
Page 7
What is Ctools?
Object Caching05
“Tool to make it easier to edit an object across multiplepage requests and cache the editing work.”
Page 8
What is Ctools?
Contexts06
“The notion of wrapping objects in a unified wrapper andproviding an API to create and accept these contexts asinput.”
Page 9
What is Ctools?
Plugins07
“Tools to make it easy for modules to let other modulesimplement plugins from .inc files.”
Page 10
What is Ctools?
Dependant08
“A simple form widget to make form items appear anddisappear based upon the selections in another item.”
Page 11
What is Ctools?
Content09
“Pluggable content types used as panes in Panels andother modules like Dashboard.”
Page 12
What is Ctools?
Form Tools10
“Tools to make it easier for forms to deal with AJAX.”
Page 13
What is Ctools?
Exportables11
“Tools to make it easier for modules to have objects thatlive in database or live in code, such as 'default views'.”
Page 14
What are Exportables?
A standardized way to define “configuration presets”.
Can be stored in the database or in code
Built in export/import functionality
Page 15
Advantages of ExportablesPortability of configuration settings
Allows configuration to use version control
Allows override/revert functionality
Avoids loading data from database
Allows for Drush and Features integration
Page 16
Using Exportables
Setup your project
Page 17
Implement hook_schemaexportable_demo.install
Page 18
Implement hook_schema
Export section is unique to exportables
exportable_demo.install
Page 19
Implement hook_install
Don't forget to call hook_install
module.install
Page 20
Define the UI
Use Ctools plugins to define the UI
exportable_demo.module
Page 21
Define the UI/plugin/export_ui/exportable_demo_ctools_export_ui.inc
Page 22
Define the UI/plugin/export_ui/exportable_demo_ctools_export_ui.inc
Page 23
Default Presetsexportable_demo.module
Tell Ctools that we support our default presets
Page 24
Default Presets
Define the actual preset
exportable_demo.module
Page 25
3rd Party Module Presetsthird_party.module
Tell Ctools that we support our default presets
Page 26
3rd Party Module Presetsthird_party.module
Define the actual preset
Page 27
What is Ctools?
AJAX Responder02
“Tools to make it easier for the server to handle AJAXrequests and tell the client what to do with them.”
Page 28
Advantages Ajax ResponderAjax without javascript
Part of “core” in Drupal 7
Much simpler than AHAH
Fails gracefully automatically
SEO Compatible
Page 29
Define the AJAX callback
Using Ajax Responderajax_demo.module
Page 30
Requires two hook_menu items
Using Ajax Responderajax_demo.module
Page 31
Using Ajax Responder
Add a link
ajax_demo.module
Page 32
Ajax Responder Commands
Ajax in php
Command functions all take the form:
ctools_ajax_command_[COMMAND_NAME]
Page 33
1
append
2
replace
3
prepend
4 after
5 before
7
6
9
8
Ajax Responder Commandsremove
changed
alert
css
10 attr
Page 34
11
redirect
12
settings
13
data
14 reload
15 submit
6
Ajax Responder Commands
Page 35
What is Ctools?
Form Wizard03
“An API to make multi-step forms much easier.”
Page 36
Advantages of Form WizardMultistep forms are hard in Drupal
More like FAPI
Allows for better organization of UI
Allows for better organization of code
Page 37
hook_menu callbackform_demo.module
Add required wizard and cache includes
Setup multistep array, form settings, callbacks, Labels and IDs
Load form from cache
Render the actual form
This is the hardest part
Page 38
hook_menu callbackform_demo.module
Add wizard and cache includes
Page 39
hook_menu callbackform_demo.module - form_demo_page()
Multistep array: form settings
Page 40
hook_menu callbackform_demo.module - form_demo_page()
Multistep array: form IDs and labels
Page 41
hook_menu callbackform_demo.module - form_demo_page()
Setup form cache
Page 42
hook_menu callbackform_demo.module - form_demo_page()
Render the form
Page 43
Define form step 1form_demo.module
Just a normal hook_form
Page 44
Define form step 1form_demo.module
Normal hook_form_validate too!
Page 45
Define form step 1form_demo.module
Not quite a normal hook_form_submit
Page 46
Define form step 2form_demo.module
Use choices from step 1 in step 2
Page 47
Define form step 2form_demo.module
Not quite a normal hook_form_submit
Page 48
Define form step 2form_demo.module
Even in last submit, dont' save
Page 49
Define form callbacksform_demo.module
Finish Callback – finally we can save
Page 50
Define form callbacksform_demo.module
Next callback – set the cache
Page 51
Define form callbacksform_demo.module
Cancel callback
Page 52
Define form callbacksform_demo.module
Used for passing data between steps
Page 53
What is Ctools?
Modal Dialog04
“Tool to make it simple to put a form in a modal dialog.”
Page 54
Advantages Modal DialogModal popup without javascript
Standardized way of creating modal
Build to handle forms
Easy to theme
Page 55
Implement hook_menumodal_demo.module
Two menu items, page and modal
Page 56
hook_menu callbackmodal_demo.module
Add js libraries and create link
Page 57
hook_menu callbackmodal_demo.module
Create Modal with any form
Page 58
Modal dialog themingmodal_demo.module
Add an array of settings
Page 59
Modal dialog themingmodal_demo.module
More modal options
Page 60
Modal dialog themingCtools-ajax-sample.js
Must be in Drupal.theme.prototype namespace
Page 61
ReferencesExportables:
http://drupal.org/node/928026
Ajax Responder: http://zroger.com/node/30
Multistep forms: http://www.nicklewis.org/using-chaos-tools-form-wizard-
build-multistep-forms-drupal-6
Modal dialog http://zroger.com/node/31