What is Ctools?

 “This suite is primarily a set of APIs and tools to improve the
                     developer experience”




         Controlling the Chaos
What is Ctools?
 1   Exportables       6 Contexts


 2   Ajax Responder    7   Plugins


 3   Form Wizard       8   Dependant



 4   Modal dialog      9 Content


 5   Object Caching   10 Form tools
What is Ctools?

 “Tools to make it easier for modules to have objects that
 live in database or live in code, such as 'default views'.”




01     Exportables
What is Ctools?

 “Tools to make it easier for the server to handle AJAX
 requests and tell the client what to do with them.”




02     AJAX Responder
What is Ctools?

 “An API to make multi-step forms much easier.”




03     Form Wizard
What is Ctools?

 “Tool to make it simple to put a form in a modal dialog.”




04     Modal Dialog
What is Ctools?

 “Tool to make it easier to edit an object across multiple
 page requests and cache the editing work.”




05      Object Caching
What is Ctools?

 “The notion of wrapping objects in a unified wrapper and
 providing an API to create and accept these contexts as
 input.”




06     Contexts
What is Ctools?

 “Tools to make it easy for modules to let other modules
 implement plugins from .inc files.”




07     Plugins
What is Ctools?

 “A simple form widget to make form items appear and
 disappear based upon the selections in another item.”




08     Dependant
What is Ctools?

 “Pluggable content types used as panes in Panels and
 other modules like Dashboard.”




09     Content
What is Ctools?

 “Tools to make it easier for forms to deal with AJAX.”




10     Form Tools
What is Ctools?

 “Tools to make it easier for modules to have objects that
 live in database or live in code, such as 'default views'.”




11      Exportables
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 Exportables
Portability 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_schema
                exportable_demo.install
Implement hook_schema      exportable_demo.install




    Export section is unique to exportables
Implement hook_install           module.install




    Don't forget to call hook_install
Define the UI              exportable_demo.module




    Use Ctools plugins to define the UI
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 Presets             exportable_demo.module




     Tell Ctools that we support our default presets
Default Presets            exportable_demo.module




     Define the actual preset
3 Party Module Presets
 rd
                             third_party.module




      Tell Ctools that we support our default presets
3 Party Module Presets
 rd
                            third_party.module




      Define the actual preset
What is Ctools?

 “Tools to make it easier for the server to handle AJAX
 requests and tell the client what to do with them.”




02     AJAX Responder
Advantages Ajax Responder
Ajax without javascript

Part of “core” in Drupal 7

Much simpler than AHAH

Fails gracefully automatically

SEO Compatible
Using Ajax Responder          ajax_demo.module




    Define the AJAX callback
Using Ajax Responder          ajax_demo.module




    Requires two hook_menu items
Using Ajax Responder   ajax_demo.module




    Add a link
Ajax Responder Commands
Command functions all take the form:


ctools_ajax_command_[COMMAND_NAME]




        Ajax in php
Ajax Responder Commands
 1   replace     6 remove


 2   prepend     7 changed


 3   append      8 alert


 4 after         9 css


 5 before       10 attr
Ajax Responder Commands
11   settings    6


12   data



13   redirect



14 reload


15 submit
What is Ctools?

 “An API to make multi-step forms much easier.”




03     Form Wizard
Advantages of Form Wizard
Multistep forms are hard in Drupal

More like FAPI

Allows for better organization of UI

Allows for better organization of code
hook_menu callback                            form_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 callback                form_demo.module




       Add wizard and cache includes
hook_menu callback
                 form_demo.module - form_demo_page()




    Multistep array: form settings
hook_menu callback
                 form_demo.module - form_demo_page()




    Multistep array: form IDs and labels
hook_menu callback
               form_demo.module - form_demo_page()




    Setup form cache
hook_menu callback
               form_demo.module - form_demo_page()




    Render the form
Define form step 1             form_demo.module




    Just a normal hook_form
Define form step 1              form_demo.module




    Normal hook_form_validate too!
Define form step 1              form_demo.module




    Not quite a normal hook_form_submit
Define form step 2                form_demo.module




    Use choices from step 1 in step 2
Define form step 2              form_demo.module




    Not quite a normal hook_form_submit
Define form step 2                 form_demo.module




    Even in last submit, dont' save
Define form callbacks             form_demo.module




    Finish Callback – finally we can save
Define form callbacks                form_demo.module




    Next callback – set the cache
Define form callbacks   form_demo.module




    Cancel callback
Define form callbacks            form_demo.module




    Used for passing data between steps
What is Ctools?

 “Tool to make it simple to put a form in a modal dialog.”




04     Modal Dialog
Advantages Modal Dialog
Modal popup without javascript

Standardized way of creating modal

Build to handle forms

Easy to theme
Implement hook_menu           modal_demo.module




    Two menu items, page and modal
hook_menu callback                 modal_demo.module




    Add js libraries and create link
hook_menu callback                   modal_demo.module




       Create Modal with any form
Modal dialog theming           modal_demo.module




    Add an array of settings
Modal dialog theming     modal_demo.module




    More modal options
Modal dialog theming             Ctools-ajax-sample.js




    Must be in Drupal.theme.prototype namespace
References
Exportables:
    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

Ctools presentation