SlideShare a Scribd company logo
Advanced Module
Development (D6)

Case study: UC_Etranzact Ubercart
         contrib module

                       Kayode Odeyemi
             Technical Architect, Opevel
               DrupalCamp Lagos 2011
Where to start from?

There are various ways of starting a Drupal
module;

• Using Features module: Makes your Drupal
  module exportable and deployment easier.

• Using Module Builder module: auto-generates a
  skeleton or "scaffolding" for a module
Drupal Common Hooks

•   Hook_menu
•   Hook_init
•   Hook_help
•   Hook_nodeapi
•   Hook_theme
•   Hook_install
•   Hook_uninstall
•   Hook_form
•   Hook_form_alter
•   Hook_form_submit
•   Hook_form_validate
Very useful Drupal APIs for everyday development
 •   Module_invoke
 •   Module_load_include
 •   Drupal_write_record
 •   Function_exists
 •   Call_user_func_array
 •   Db_table_exists
 •   Db_query
 •   Db_result
 •   Db_object_fetch_array and db_object_fetch_object
 •   Drupal_set_message or dsm if using devel module
 •   Db_create_table
 •   Update_sql
 •   Views_get_views_result
 •   Db_add_field
 •   Db_drop_field
 •   Drupal_get_schema
 •   Element_children
 •   Views_get_default_view
Writing Drupal Hooks
There are different ways of writing Drupal hooks.

// Using module_implements inline within a non-hook function and using module_invoke

foreach(module_implements(‘hook_name') as $module) {
   module_invoke($module, ‘hook_name', $args);
}

// Explicitly writing the hook as a function with module_implements alone
function mymodule_hook($fees) {
   foreach (module_implements(‘hook_name') as $module) {
      $function = $module . '_hook_name';
      $result = $function($fees);
      if (isset($result) && is_array($result)) {
          $return = array_merge($return, $result);
      }
      else if (isset($result)) {
          $return[] = $result;
      }
   }
   return $return;
}
drupal_http_request: Drupal's simple curl equivalent
  // curl
  $curl = curl_init(); $apiurl =
    variable_get('uc_etranzact_demo_mode', 1) ?
    UC_ETRANZACT_SERVICE_DEMO :
    UC_ETRANZACT_SERVICE; $apiurl = sprintf('%s?%s',
    $apiurl, $query); curl_setopt($curl, CURLOPT_URL,
    $apiurl); curl_setopt($curl,
    CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl,
    CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl,
    CURLOPT_FOLLOWLOCATION, 1); $return =
    curl_exec($curl);

  // drupal_http_request
  $result = drupal_http_request($uri, $header, $method,
    http_build_query($data, '', '&'));
Test with SimpleTest
  • When your project is starting to get robust and clumsy, test with
    SimpleTest
  • Common SimpleTest APIs are:

     – drupalGetNodeByTitle($title)
     – drupalCreateNode($settings)
     – drupalCreateContentType($settings) -
       drupalCreateUser($permissions)
     – checkPermissions(array $permissions, $reset = FALSE): Check
       to make sure that the array of permissions are valid.
     – drupalLogin(stdClass $user): Log in a user with the internal
       browser.
Test with SimpleTest

     – drupalLogout

     – assertNotEqual: Check to see if two values are not equal.

     – assertEqual: Check to see if two values are equal.

     – drupalPost: Execute a POST request on a Drupal page.

     – drupalGet: Retrieves a Drupal path or an absolute path.

     – assertTrue: Check to see if a value is not false (not an empty
       string, 0, NULL, or FALSE)

     – assertFalse: Check to see if a value is false (an empty string, 0,
       NULL, or FALSE).

     – assertNull: Check to see if a value is not NULL.
Administer Drupal faster with Drupal
  •   Drush is Drupal’s CLI language
  •   Administer modules quickly with Drush
  •   When working with multi-sites, Drush is your best friend
  •   Drupal cheat sheet

      –   Drush status
      –   Drush dl <modulename>
      –   Drush cc
      –   Drush eval “<php code>”
      –   Drush en <module name>
      –   Drush dis <module name>
      –   Drush up
      –   Drush upc <module name>
      –   … more on drupal.org
Debugging Drupal

• The devel module and theme developer modules are
  very handy tools for Debugging Drupal.

• There’s also a firebug Drupal extension for debugging
  Drupal

• Useful functions:
   – Dsm
   – Dpr
   – dvm
Ubercart Payment Hooks and useful APIs
• Hook_payment_method: define a custom payment method
• Hook_order: define and process the order items
• Hook_checkout_pane: define a custom pane for your order and
  style it
• uc_order_status_data: Check the status of an order
• uc_cart_empty(uc_cart_get_id()): Empty a cart
• uc_order_save($order): save an order to the database
• Hook_tapir_table_alter
• Hook_cart_item: alter the items in cart
• Hook_cart_pane: Override the cart pane
• Hook_product_description: modify the descriptions of items in cart
• Uc_cart_get_contents: get cart contents
Understanding ubercart cart process

 • Add items to cart using uc_cart_add_items.

 • Checkout your order and implement
   hook_checkout_pane to customize the order
   items.

 • Review the order in different states namely:
    – New: only called if the order is new
    – Submit: Process the order such as integrating with a
      payment gateway like etranzact.
    – Save: Save your order in a database
    – Load: called immediately an order is successfully
      saved in the db
How we build it: uc_etranzact module


 • Uc_etranzact module only requires a payment
   gateway implementation

 • Ubercart Hooks that got the job done:
    – Hook_payment_gateway
    – Hook_order
    – Callback functions to process the order to
      integrate with etranzact system
Questions
  • Website      - http://opevel.com

  • Twitter : @opevel @drupal @acquia

  • Opevel Services

     – Drupal custom development

     – Drupal site architecture

     – Custom Application Development on Google App Engine


  http://drupal.org/sandbox/charyorde/1310706

  • Datasphir is hiring Drupal developers. – http://datasphir.com

More Related Content

PDF
Google app-engine-cloudcamplagos2011
PDF
Gaelyk - SpringOne2GX - 2010 - Guillaume Laforge
PPTX
SenchaCon 2016: The Modern Toolchain - Ross Gerbasi
PPTX
Building and managing java projects with maven part-III
PPTX
Building and Managing Projects with Maven
PPTX
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
PPTX
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
PPTX
SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...
Google app-engine-cloudcamplagos2011
Gaelyk - SpringOne2GX - 2010 - Guillaume Laforge
SenchaCon 2016: The Modern Toolchain - Ross Gerbasi
Building and managing java projects with maven part-III
Building and Managing Projects with Maven
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...

What's hot (20)

PPT
DSpace UI Prototype Challenge: Spring Boot + Thymeleaf
PDF
Here Be Dragons - Debugging WordPress
PPT
Multi Tenancy With Python and Django
KEY
modern module development - Ken Barber 2012 Edinburgh Puppet Camp
PPTX
SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...
PPT
JSP Part 2
PDF
Choosing a Javascript Framework
PPT
Build Your Own CMS with Apache Sling
PDF
JavaScript Service Worker Design Patterns for Better User Experience
PDF
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
PDF
RESTful Web Applications with Apache Sling
PDF
AD102 - Break out of the Box
PPTX
Break out of The Box - Part 2
PPTX
IBM Connect 2016 - Break out of the Box
PPTX
SaaSy maps - using django-tenants and geodjango to provide web-gis software-a...
PDF
OSGi, Scripting and REST, Building Webapps With Apache Sling
PPTX
Pure Speed Drupal 4 Gov talk
PDF
Node.js and couchbase Full Stack JSON - Munich NoSQL
PDF
High Performance Drupal
ODP
How To Build a Multi-Field Search Page For Your XPages Application
DSpace UI Prototype Challenge: Spring Boot + Thymeleaf
Here Be Dragons - Debugging WordPress
Multi Tenancy With Python and Django
modern module development - Ken Barber 2012 Edinburgh Puppet Camp
SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...
JSP Part 2
Choosing a Javascript Framework
Build Your Own CMS with Apache Sling
JavaScript Service Worker Design Patterns for Better User Experience
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
RESTful Web Applications with Apache Sling
AD102 - Break out of the Box
Break out of The Box - Part 2
IBM Connect 2016 - Break out of the Box
SaaSy maps - using django-tenants and geodjango to provide web-gis software-a...
OSGi, Scripting and REST, Building Webapps With Apache Sling
Pure Speed Drupal 4 Gov talk
Node.js and couchbase Full Stack JSON - Munich NoSQL
High Performance Drupal
How To Build a Multi-Field Search Page For Your XPages Application
Ad

Viewers also liked (7)

PDF
Top 10 preso
PDF
Showcasing drupal
PDF
Opevel social-enterprise-platform osep-google_apps_slideshare
PDF
Interoperability betweendrupalandgoogleapps
PDF
Visual Design with Data
PDF
3 Things Every Sales Team Needs to Be Thinking About in 2017
PDF
How to Become a Thought Leader in Your Niche
Top 10 preso
Showcasing drupal
Opevel social-enterprise-platform osep-google_apps_slideshare
Interoperability betweendrupalandgoogleapps
Visual Design with Data
3 Things Every Sales Team Needs to Be Thinking About in 2017
How to Become a Thought Leader in Your Niche
Ad

Similar to Advanced moduledevelopment d6_slideshare (20)

PDF
Staging Drupal 8 31 09 1 3
PDF
13th Sep, Drupal 7 advanced training by TCS
ZIP
Learning the basics of the Drupal API
PPTX
Drupal Camp Porto - Developing with Drupal: First Steps
PDF
Drupal Module Development
PDF
Drupal Module Development - OSI Days 2010
ODP
Drupal Best Practices
PDF
Staying Sane with Drupal (A Develper's Survival Guide)
KEY
PPTX
Migrate yourself. code -> module -> mind
PPTX
Валентин Мацвейко та Владислав Мойсеєнко — D8: Migrate Yourself: code->module...
PPTX
Working with LoopBack Models
PPTX
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
PDF
Views Style Plugins
PPT
Drupal Javascript for developers
ZIP
Drupal Development
PDF
Staying Sane with Drupal NEPHP
PDF
Drupal Security from Drupalcamp Bratislava
PDF
Getting Started with DrupalGap
PPT
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Staging Drupal 8 31 09 1 3
13th Sep, Drupal 7 advanced training by TCS
Learning the basics of the Drupal API
Drupal Camp Porto - Developing with Drupal: First Steps
Drupal Module Development
Drupal Module Development - OSI Days 2010
Drupal Best Practices
Staying Sane with Drupal (A Develper's Survival Guide)
Migrate yourself. code -> module -> mind
Валентин Мацвейко та Владислав Мойсеєнко — D8: Migrate Yourself: code->module...
Working with LoopBack Models
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
Views Style Plugins
Drupal Javascript for developers
Drupal Development
Staying Sane with Drupal NEPHP
Drupal Security from Drupalcamp Bratislava
Getting Started with DrupalGap
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)

Recently uploaded (20)

PPTX
Big Data Technologies - Introduction.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
MYSQL Presentation for SQL database connectivity
PPT
Teaching material agriculture food technology
PDF
Electronic commerce courselecture one. Pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Cloud computing and distributed systems.
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
cuic standard and advanced reporting.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Big Data Technologies - Introduction.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Chapter 3 Spatial Domain Image Processing.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
MYSQL Presentation for SQL database connectivity
Teaching material agriculture food technology
Electronic commerce courselecture one. Pdf
Programs and apps: productivity, graphics, security and other tools
MIND Revenue Release Quarter 2 2025 Press Release
Cloud computing and distributed systems.
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
cuic standard and advanced reporting.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
The AUB Centre for AI in Media Proposal.docx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy

Advanced moduledevelopment d6_slideshare

  • 1. Advanced Module Development (D6) Case study: UC_Etranzact Ubercart contrib module Kayode Odeyemi Technical Architect, Opevel DrupalCamp Lagos 2011
  • 2. Where to start from? There are various ways of starting a Drupal module; • Using Features module: Makes your Drupal module exportable and deployment easier. • Using Module Builder module: auto-generates a skeleton or "scaffolding" for a module
  • 3. Drupal Common Hooks • Hook_menu • Hook_init • Hook_help • Hook_nodeapi • Hook_theme • Hook_install • Hook_uninstall • Hook_form • Hook_form_alter • Hook_form_submit • Hook_form_validate
  • 4. Very useful Drupal APIs for everyday development • Module_invoke • Module_load_include • Drupal_write_record • Function_exists • Call_user_func_array • Db_table_exists • Db_query • Db_result • Db_object_fetch_array and db_object_fetch_object • Drupal_set_message or dsm if using devel module • Db_create_table • Update_sql • Views_get_views_result • Db_add_field • Db_drop_field • Drupal_get_schema • Element_children • Views_get_default_view
  • 5. Writing Drupal Hooks There are different ways of writing Drupal hooks. // Using module_implements inline within a non-hook function and using module_invoke foreach(module_implements(‘hook_name') as $module) { module_invoke($module, ‘hook_name', $args); } // Explicitly writing the hook as a function with module_implements alone function mymodule_hook($fees) { foreach (module_implements(‘hook_name') as $module) { $function = $module . '_hook_name'; $result = $function($fees); if (isset($result) && is_array($result)) { $return = array_merge($return, $result); } else if (isset($result)) { $return[] = $result; } } return $return; }
  • 6. drupal_http_request: Drupal's simple curl equivalent // curl $curl = curl_init(); $apiurl = variable_get('uc_etranzact_demo_mode', 1) ? UC_ETRANZACT_SERVICE_DEMO : UC_ETRANZACT_SERVICE; $apiurl = sprintf('%s?%s', $apiurl, $query); curl_setopt($curl, CURLOPT_URL, $apiurl); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); $return = curl_exec($curl); // drupal_http_request $result = drupal_http_request($uri, $header, $method, http_build_query($data, '', '&'));
  • 7. Test with SimpleTest • When your project is starting to get robust and clumsy, test with SimpleTest • Common SimpleTest APIs are: – drupalGetNodeByTitle($title) – drupalCreateNode($settings) – drupalCreateContentType($settings) - drupalCreateUser($permissions) – checkPermissions(array $permissions, $reset = FALSE): Check to make sure that the array of permissions are valid. – drupalLogin(stdClass $user): Log in a user with the internal browser.
  • 8. Test with SimpleTest – drupalLogout – assertNotEqual: Check to see if two values are not equal. – assertEqual: Check to see if two values are equal. – drupalPost: Execute a POST request on a Drupal page. – drupalGet: Retrieves a Drupal path or an absolute path. – assertTrue: Check to see if a value is not false (not an empty string, 0, NULL, or FALSE) – assertFalse: Check to see if a value is false (an empty string, 0, NULL, or FALSE). – assertNull: Check to see if a value is not NULL.
  • 9. Administer Drupal faster with Drupal • Drush is Drupal’s CLI language • Administer modules quickly with Drush • When working with multi-sites, Drush is your best friend • Drupal cheat sheet – Drush status – Drush dl <modulename> – Drush cc – Drush eval “<php code>” – Drush en <module name> – Drush dis <module name> – Drush up – Drush upc <module name> – … more on drupal.org
  • 10. Debugging Drupal • The devel module and theme developer modules are very handy tools for Debugging Drupal. • There’s also a firebug Drupal extension for debugging Drupal • Useful functions: – Dsm – Dpr – dvm
  • 11. Ubercart Payment Hooks and useful APIs • Hook_payment_method: define a custom payment method • Hook_order: define and process the order items • Hook_checkout_pane: define a custom pane for your order and style it • uc_order_status_data: Check the status of an order • uc_cart_empty(uc_cart_get_id()): Empty a cart • uc_order_save($order): save an order to the database • Hook_tapir_table_alter • Hook_cart_item: alter the items in cart • Hook_cart_pane: Override the cart pane • Hook_product_description: modify the descriptions of items in cart • Uc_cart_get_contents: get cart contents
  • 12. Understanding ubercart cart process • Add items to cart using uc_cart_add_items. • Checkout your order and implement hook_checkout_pane to customize the order items. • Review the order in different states namely: – New: only called if the order is new – Submit: Process the order such as integrating with a payment gateway like etranzact. – Save: Save your order in a database – Load: called immediately an order is successfully saved in the db
  • 13. How we build it: uc_etranzact module • Uc_etranzact module only requires a payment gateway implementation • Ubercart Hooks that got the job done: – Hook_payment_gateway – Hook_order – Callback functions to process the order to integrate with etranzact system
  • 14. Questions • Website - http://opevel.com • Twitter : @opevel @drupal @acquia • Opevel Services – Drupal custom development – Drupal site architecture – Custom Application Development on Google App Engine http://drupal.org/sandbox/charyorde/1310706 • Datasphir is hiring Drupal developers. – http://datasphir.com