Embracing chaos
Leveraging the Chaos tool suite for
      module development
@zroger
drupal.org/user/67977
What is CTools?
“This suite is primarily a set of APIs and tools
to improve the developer experience. It also
contains a module called the Page Manager
whose is to manage pages. In particular it
manages panel pages, but as it grows it will be
able to manage far more than just Panels.”

                      - http://drupal.org/project/ctools
Credit: http://www.flickr.com/photos/ontario_wanderer
The Tools
•   Plugins            •   Modal Dialog

•   Exportables        •   Dependent

•   AJAX Responder     •   Content

•   Form Tools         •   Form wizard

•   Object caching     •   CSS Tools

•   Contexts           •   Others*
Credit: http://www.flickr.com/photos/jakematesdesign
Plugins
• Variation of the hook system
• Extensions of modules
• Several implementation methods
• Implementation by other modules
• And themes too!
Credit: http://www.flickr.com/photos/thomashawk
Exportables
• Allows for exportable objects
• Exported objects run from code
• CTools handles the overrides
• Implemented in hook_schema()
Form Tools
• replacements for Drupal's form functions
• ctools_build_form instead of
  drupal_get_form
              =




• uses form_state exclusively, no function
  args
• basis of modal dialog and form wizard
AJAX Responder




            Credit: http://www.flickr.com/photos/jimmyroq
AJAX Responder

• Command passing framework
• Common language (JSON)
• Command execution happens in javascript
• Command invocation happens in PHP
Click Handler


                 AJAX Callback


AJAX Command
Modal Dialog
• Built on top of AJAX Responder
• Works especially well with forms
• Handles form validation and submission
  workflows
Object Cache
• non-volatile cache
• mainly used for editing/creating complex
  objects
• allows for "unsaved" states
• the code responsible for the object is
  responsible for clearing the cache
Contexts
• Packages objects into re-usable contexts
• Most often used with url args, similar to
  menu loader wildcards
• Contexts can be fetched from any
  condition (url, 
• Contexts can be added manually (page
  manager)
Content
• re-usable content displays
• configurable options
• make use of contexts
• panels panes are “content” plugins
Form Wizard
• Form wizard
• multi-step forms, different from core
  multistep
• separate forms, vs a single form (the core
  forms api)
• very easy to add new forms (steps), re-
  order steps
CSS Tools
• disassemble CSS
• filter by properties/values
• reassemble CSS
• compress CSS
Dependent Fields
• Provides a simple mechanism for
  "dependent" form fields
• Form fields can be dependent on other
  fields
• Usually dependent on the value of a
  checkbox, radio button or select
Dependent Fields
• On any form item, add
• '#process' =>
    array('ctools_dependent_process')
• '#dependency' => array('id-of-form-
    without-the-#' => array(list, of, values, that,
    make, this, gadget, visible))
•
Drop-down links
• Dropdown menu links
• javascript based dropdowns
• panels "cogs"
• theme('ctools_dropdown', ...)

Leveraging the Chaos tool suite for module development