Module Development - Get the
Drupal started
Pieter-Jan Drouillon
WHY
this talk?

2
d
Goo

Ability

How soon can they
start kicking ass?

Suck
threshold

ad
B

Time
http://buytaert.net/creating-passionate-u...
WHO
is talking?

@pjdrouillon | pieterjd.ulyssis.be

4
DISCLAIMER
5
DEFINE
your module

6
Define your module
<name>.info file
name
description
core
files
Achmed's advice :)
sites/all/modules/<name>
7
HOOKS
8
When something happens...
your module can hook in on it

9
DEM
O

hook_menu
10
FORMS
11
DEM
O

To form or not to form ...
Forms = arrays
Form API
Reverse example
Add a menu entry
set callback to drupal_get_form...
Let’s add a
submit function

DEM
O

<form_function>_submit($form, &$form_state)

13
What about ...
Validation?

DEM
O

<form_function>_validate($form, &$form_state)

14
BLOCKS
15
QR Block
On every page
With a QR code
Use Google Chart API
http://chart.googleapis.com/chart?
chs=150x150&cht=qr&chl=<url>...
Define the block

DEM
O

hook_block_info
array with all the info
key > block name
info > Some information
hook_block_view(...
PERMISSIONS
18
DEM
O

To show or not to show ...
hook_permission
array with all the info
key > permission’s (short) name
title > permissi...
PREPROCESS
20
»
21
Read more »

DEM
O

hook_preprocess
process of preparing HTML code
$author > name of author linking to user profile
hook_p...
DEM
O

hook_form_alter
23
“I need a signature!”

DEM
O

hook_form_alter
hook_form_FORM_ID_alter

24
“I sometimes need
a legal disclaimer”

DEM
O

Add a checkbox
There’s a catch :)

25
theming
26
“I want my
definition list”

DEM
O

Cannot just return html
use theming functions
theme(<hook>,...)
search in API for them...
hook_theme

DEM
O

array with all the info
key > name of theme (item_list, dd, ...)
add a list of variables
write function...
TAKE AWAY
29
Don’t give up
Join a (local) community
Recommended books
Pro Drupal 7 development
Pakt Drupal 7 Module Development
Recomme...
Q&A
31
Feedback & follow-up:
http://drupalcampgent.be/feedback
Upcoming SlideShare
Loading in...5
×

Drupalcamp Gent 2012

317

Published on

This session aims to help new drupal developers based on personal experiences and with simple, working examples. Last year, the presenter lost quite some time to get something working. The steap learning curve, new concepts and extensive documentation makes it difficult to improve.

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
317
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Drupalcamp Gent 2012

  1. 1. Module Development - Get the Drupal started Pieter-Jan Drouillon
  2. 2. WHY this talk? 2
  3. 3. d Goo Ability How soon can they start kicking ass? Suck threshold ad B Time http://buytaert.net/creating-passionate-users 3
  4. 4. WHO is talking? @pjdrouillon | pieterjd.ulyssis.be 4
  5. 5. DISCLAIMER 5
  6. 6. DEFINE your module 6
  7. 7. Define your module <name>.info file name description core files Achmed's advice :) sites/all/modules/<name> 7
  8. 8. HOOKS 8
  9. 9. When something happens... your module can hook in on it 9
  10. 10. DEM O hook_menu 10
  11. 11. FORMS 11
  12. 12. DEM O To form or not to form ... Forms = arrays Form API Reverse example Add a menu entry set callback to drupal_get_form set argument to function returning render array 12
  13. 13. Let’s add a submit function DEM O <form_function>_submit($form, &$form_state) 13
  14. 14. What about ... Validation? DEM O <form_function>_validate($form, &$form_state) 14
  15. 15. BLOCKS 15
  16. 16. QR Block On every page With a QR code Use Google Chart API http://chart.googleapis.com/chart? chs=150x150&cht=qr&chl=<url> 16
  17. 17. Define the block DEM O hook_block_info array with all the info key > block name info > Some information hook_block_view($delta = ‘’) delta > name of block to render returns render array 17
  18. 18. PERMISSIONS 18
  19. 19. DEM O To show or not to show ... hook_permission array with all the info key > permission’s (short) name title > permission’s fullname user_access checks if logged in user has the right permission user 1 bypass 19
  20. 20. PREPROCESS 20
  21. 21. » 21
  22. 22. Read more » DEM O hook_preprocess process of preparing HTML code $author > name of author linking to user profile hook_preprocess_hook hook_preprocess_blog 22
  23. 23. DEM O hook_form_alter 23
  24. 24. “I need a signature!” DEM O hook_form_alter hook_form_FORM_ID_alter 24
  25. 25. “I sometimes need a legal disclaimer” DEM O Add a checkbox There’s a catch :) 25
  26. 26. theming 26
  27. 27. “I want my definition list” DEM O Cannot just return html use theming functions theme(<hook>,...) search in API for theme_<hook> 27
  28. 28. hook_theme DEM O array with all the info key > name of theme (item_list, dd, ...) add a list of variables write function to create HTML code theme_dd($variables) 28
  29. 29. TAKE AWAY 29
  30. 30. Don’t give up Join a (local) community Recommended books Pro Drupal 7 development Pakt Drupal 7 Module Development Recommended sites api.drupal.org, www.lullabots.com & www.drupalize.me, NodeOne TODO: Check out Drush & github ! 30
  31. 31. Q&A 31
  32. 32. Feedback & follow-up: http://drupalcampgent.be/feedback
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×