Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Building API's


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
  • Be the first to comment

  • Be the first to like this

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<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<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 /><br /><br />Twitter:<br />@adamgregory<br />Email:<br /><br /><br />Drupal:<br />arcaneadam<br />