ctools presentation
TRANSCRIPT
“This suite is primarily a set of APIs and tools to improve thedeveloper experience”
Controlling the Chaos
What is Ctools?
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
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'.”
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.”
What is Ctools?
Form Wizard03
“An API to make multi-step forms much easier.”
What is Ctools?
Modal Dialog04
“Tool to make it simple to put a form in a modal dialog.”
What is Ctools?
Object Caching05
“Tool to make it easier to edit an object across multiplepage requests and cache the editing work.”
What is Ctools?
Contexts06
“The notion of wrapping objects in a unified wrapper andproviding an API to create and accept these contexts asinput.”
What is Ctools?
Plugins07
“Tools to make it easy for modules to let other modulesimplement plugins from .inc files.”
What is Ctools?
Dependant08
“A simple form widget to make form items appear anddisappear based upon the selections in another item.”
What is Ctools?
Content09
“Pluggable content types used as panes in Panels andother modules like Dashboard.”
What is Ctools?
Form Tools10
“Tools to make it easier for forms to deal with AJAX.”
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'.”
What are Exportables?
A standardized way to define “configuration presets”.
Can be stored in the database or in code
Built in export/import functionality
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
Using Exportables
Setup your project
Implement hook_schemaexportable_demo.install
Implement hook_schema
Export section is unique to exportables
exportable_demo.install
Implement hook_install
Don't forget to call hook_install
module.install
Define the UI
Use Ctools plugins to define the UI
exportable_demo.module
Define the UI/plugin/export_ui/exportable_demo_ctools_export_ui.inc
Define the UI/plugin/export_ui/exportable_demo_ctools_export_ui.inc
Default Presetsexportable_demo.module
Tell Ctools that we support our default presets
Default Presets
Define the actual preset
exportable_demo.module
3rd Party Module Presetsthird_party.module
Tell Ctools that we support our default presets
3rd Party Module Presetsthird_party.module
Define the actual preset
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.”
Advantages Ajax ResponderAjax without javascript
Part of “core” in Drupal 7
Much simpler than AHAH
Fails gracefully automatically
SEO Compatible
Define the AJAX callback
Using Ajax Responderajax_demo.module
Requires two hook_menu items
Using Ajax Responderajax_demo.module
Using Ajax Responder
Add a link
ajax_demo.module
Ajax Responder Commands
Ajax in php
Command functions all take the form:
ctools_ajax_command_[COMMAND_NAME]
1
append
2
replace
3
prepend
4 after
5 before
7
6
9
8
Ajax Responder Commandsremove
changed
alert
css
10 attr
11
redirect
12
settings
13
data
14 reload
15 submit
6
Ajax Responder Commands
What is Ctools?
Form Wizard03
“An API to make multi-step forms much easier.”
Advantages of Form WizardMultistep forms are hard in Drupal
More like FAPI
Allows for better organization of UI
Allows for better organization of code
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
hook_menu callbackform_demo.module
Add wizard and cache includes
hook_menu callbackform_demo.module - form_demo_page()
Multistep array: form settings
hook_menu callbackform_demo.module - form_demo_page()
Multistep array: form IDs and labels
hook_menu callbackform_demo.module - form_demo_page()
Setup form cache
hook_menu callbackform_demo.module - form_demo_page()
Render the form
Define form step 1form_demo.module
Just a normal hook_form
Define form step 1form_demo.module
Normal hook_form_validate too!
Define form step 1form_demo.module
Not quite a normal hook_form_submit
Define form step 2form_demo.module
Use choices from step 1 in step 2
Define form step 2form_demo.module
Not quite a normal hook_form_submit
Define form step 2form_demo.module
Even in last submit, dont' save
Define form callbacksform_demo.module
Finish Callback – finally we can save
Define form callbacksform_demo.module
Next callback – set the cache
Define form callbacksform_demo.module
Cancel callback
Define form callbacksform_demo.module
Used for passing data between steps
What is Ctools?
Modal Dialog04
“Tool to make it simple to put a form in a modal dialog.”
Advantages Modal DialogModal popup without javascript
Standardized way of creating modal
Build to handle forms
Easy to theme
Implement hook_menumodal_demo.module
Two menu items, page and modal
hook_menu callbackmodal_demo.module
Add js libraries and create link
hook_menu callbackmodal_demo.module
Create Modal with any form
Modal dialog themingmodal_demo.module
Add an array of settings
Modal dialog themingmodal_demo.module
More modal options
Modal dialog themingCtools-ajax-sample.js
Must be in Drupal.theme.prototype namespace
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