Building API's

483 views

Published on

This session will cover how to write effective API modules utilizing the hook system found in Drupal in a way that makes your module extensible and pluggable.
We’ll look at some of the Drupal modules that do this effectively(Views, Fields/CCK, etc.) and also look at a recent example, The Piecemaker API module, where I implemented this strategy.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
483
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Building API's

  1. 1. Building API’s<br />A.K.A. making your module extensible<br />
  2. 2. Who Am I?<br />Adam A. Gregory<br />Drupal Developer, Themer, Consultant, and Trainer<br />Using Drupal For 5+ years<br />Built and maintain numerous modules/themes on Drupal.org<br />Been involved in Drupal projects large and small<br />Recently released my first API module, Piecemaker API, & currently converting the Theme Editor module to more of an API in D7<br />
  3. 3. What We’ll Cover<br />What is an API<br />How it applies to building modules<br />How do I code an API module?<br />Planning<br />Proper structures (hooks, classes)<br />Drupal Coding Standards<br />Code, Test, Code, Test<br />Give Examples (example.api.php)<br />Release into the wild<br />Real World Examples<br />
  4. 4. What is an API?<br />Application Programming Interface<br />Allows other code/programs/modules/etc. to reutilize it’s utilities, resources, and/or services<br />Provides a more efficient code base in Drupal (ussually)<br />Drupal is essentially a big API, or rather a group of API’s<br />
  5. 5. How do I code an API module?<br />Code, Pray, Test, Yell, Throw computer in pool, Give up, Become a monk.<br />
  6. 6. Planning<br />A good plan violently executed now is better than a perfect plan executed next week.<br /> - General George S. Patton<br />Use a whiteboard, mindmap, pad of paper<br />Think through possible uses, by both devs and end users<br />Steal ideas! (It’s OK, that’s what Open Source is for)<br />
  7. 7. Proper Structures<br />Classes<br />Drupal is moving slowly but surely to a more OOP approach so try to plan for that.<br />In D7 there is auto loading of Classes so it makes for more efficient code.<br />In order to utilize classes you must initialize classes dynamically, not statically. (May also apply to methods depending on your module use)<br />Classes can easily be extended so they are preferable.<br />
  8. 8. Proper Structures<br />Hooks<br />You can write an entire API that only utilizes hooks.<br />Hooks will be needed even in API that are mostly OOP.<br />The entire Drupal system was built as a hooker so it is easily understood by most developers<br />
  9. 9. Drupal Coding Standards<br />In order for your module to be extensible it MUST, MUST, MUST conform to Drupal coding standards and practices.<br />Common mistakes<br />Not using a theme() function for ANY html output<br />Not using drupal_alter() to allow other modules access<br />Not Documenting properly: PHPDoc, example.api.php<br />
  10. 10. Code, Test, Code, Test<br />
  11. 11. Give Examples<br />Document you code thoroughly<br />Use your own hooks if possible<br />Provide an example.api.php that shows some implementations of your hooks and classes<br />Code the first module that implements the API and include it.<br />
  12. 12. Release it into the wild!<br />You’ve done it right?<br />Not so fast my friend…<br />No you have to support it.<br />Provide documentation on Drupal.org<br />Answer Issues<br />Fix bugs<br />Provide Support<br />Make improvements<br />Make new releases<br />Lather, Rinse, Repeat<br />
  13. 13. Lets Look At Some Code<br />Views, Fields, Piecemaker<br />
  14. 14. Q&A<br />You ask. I answer. Lets keep it simple… Not the questions, just the subtitle.<br />
  15. 15. Adam A. Gregory<br />Web:<br />Causecast.org<br />NewhallWeb.com<br />Twitter:<br />@adamgregory<br />Email:<br />arcaneadam@gmail.com<br />Adam@NewhallWeb.com<br />Drupal:<br />arcaneadam<br />

×