61
“This suite is primarily a set of APIs and tools to improve the developer experience” Controlling the Chaos What is Ctools?

Ctools presentation

Embed Size (px)

Citation preview

Page 1: Ctools presentation

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

Controlling the Chaos

What is Ctools?

Page 2: Ctools presentation

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: Ctools presentation

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: Ctools presentation

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: Ctools presentation

What is Ctools?

Form Wizard03

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

Page 6: Ctools presentation

What is Ctools?

Modal Dialog04

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

Page 7: Ctools presentation

What is Ctools?

Object Caching05

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

Page 8: Ctools presentation

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: Ctools presentation

What is Ctools?

Plugins07

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

Page 10: Ctools presentation

What is Ctools?

Dependant08

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

Page 11: Ctools presentation

What is Ctools?

Content09

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

Page 12: Ctools presentation

What is Ctools?

Form Tools10

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

Page 13: Ctools presentation

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: Ctools presentation

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: Ctools presentation

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: Ctools presentation

Using Exportables

Setup your project

Page 17: Ctools presentation

Implement hook_schemaexportable_demo.install

Page 18: Ctools presentation

Implement hook_schema

Export section is unique to exportables

exportable_demo.install

Page 19: Ctools presentation

Implement hook_install

Don't forget to call hook_install

module.install

Page 20: Ctools presentation

Define the UI

Use Ctools plugins to define the UI

exportable_demo.module

Page 21: Ctools presentation

Define the UI/plugin/export_ui/exportable_demo_ctools_export_ui.inc

Page 22: Ctools presentation

Define the UI/plugin/export_ui/exportable_demo_ctools_export_ui.inc

Page 23: Ctools presentation

Default Presetsexportable_demo.module

Tell Ctools that we support our default presets

Page 24: Ctools presentation

Default Presets

Define the actual preset

exportable_demo.module

Page 25: Ctools presentation

3rd Party Module Presetsthird_party.module

Tell Ctools that we support our default presets

Page 26: Ctools presentation

3rd Party Module Presetsthird_party.module

Define the actual preset

Page 27: Ctools presentation

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: Ctools presentation

Advantages Ajax ResponderAjax without javascript

Part of “core” in Drupal 7

Much simpler than AHAH

Fails gracefully automatically

SEO Compatible

Page 29: Ctools presentation

Define the AJAX callback

Using Ajax Responderajax_demo.module

Page 30: Ctools presentation

Requires two hook_menu items

Using Ajax Responderajax_demo.module

Page 31: Ctools presentation

Using Ajax Responder

Add a link

ajax_demo.module

Page 32: Ctools presentation

Ajax Responder Commands

Ajax in php

Command functions all take the form:

ctools_ajax_command_[COMMAND_NAME]

Page 33: Ctools presentation

1

append

2

replace

3

prepend

4 after

5 before

7

6

9

8

Ajax Responder Commandsremove

changed

alert

css

10 attr

Page 34: Ctools presentation

11

redirect

12

settings

13

data

14 reload

15 submit

6

Ajax Responder Commands

Page 35: Ctools presentation

What is Ctools?

Form Wizard03

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

Page 36: Ctools presentation

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: Ctools presentation

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: Ctools presentation

hook_menu callbackform_demo.module

Add wizard and cache includes

Page 39: Ctools presentation

hook_menu callbackform_demo.module - form_demo_page()

Multistep array: form settings

Page 40: Ctools presentation

hook_menu callbackform_demo.module - form_demo_page()

Multistep array: form IDs and labels

Page 41: Ctools presentation

hook_menu callbackform_demo.module - form_demo_page()

Setup form cache

Page 42: Ctools presentation

hook_menu callbackform_demo.module - form_demo_page()

Render the form

Page 43: Ctools presentation

Define form step 1form_demo.module

Just a normal hook_form

Page 44: Ctools presentation

Define form step 1form_demo.module

Normal hook_form_validate too!

Page 45: Ctools presentation

Define form step 1form_demo.module

Not quite a normal hook_form_submit

Page 46: Ctools presentation

Define form step 2form_demo.module

Use choices from step 1 in step 2

Page 47: Ctools presentation

Define form step 2form_demo.module

Not quite a normal hook_form_submit

Page 48: Ctools presentation

Define form step 2form_demo.module

Even in last submit, dont' save

Page 49: Ctools presentation

Define form callbacksform_demo.module

Finish Callback – finally we can save

Page 50: Ctools presentation

Define form callbacksform_demo.module

Next callback – set the cache

Page 51: Ctools presentation

Define form callbacksform_demo.module

Cancel callback

Page 52: Ctools presentation

Define form callbacksform_demo.module

Used for passing data between steps

Page 53: Ctools presentation

What is Ctools?

Modal Dialog04

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

Page 54: Ctools presentation

Advantages Modal DialogModal popup without javascript

Standardized way of creating modal

Build to handle forms

Easy to theme

Page 55: Ctools presentation

Implement hook_menumodal_demo.module

Two menu items, page and modal

Page 56: Ctools presentation

hook_menu callbackmodal_demo.module

Add js libraries and create link

Page 57: Ctools presentation

hook_menu callbackmodal_demo.module

Create Modal with any form

Page 58: Ctools presentation

Modal dialog themingmodal_demo.module

Add an array of settings

Page 59: Ctools presentation

Modal dialog themingmodal_demo.module

More modal options

Page 60: Ctools presentation

Modal dialog themingCtools-ajax-sample.js

Must be in Drupal.theme.prototype namespace

Page 61: Ctools presentation

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