introduction to module development (drupal 7)
TRANSCRIPT
![Page 1: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/1.jpg)
1
by April Sides
![Page 2: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/2.jpg)
2
April Sides
Assessment Web Developer
North Carolina Institute of Climate Studies (NCICS)North Carolina State University
National Centers for Environmental Information (NCEI)
Drupal ID: weekbeforenext
Asheville Drupal User Group Member
![Page 3: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/3.jpg)
3
• Tools - what you need to develop a module• API/Hooks - how to get Drupal to run your code• Anatomy - what files you need and what code
should be included in those files• Resources - where to find the right hooks• Example - how to modify an existing form, etc.
![Page 4: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/4.jpg)
4
• Some PHP coding experience• Plain text editor
Mac: Sublime Text - http://www.sublimetext.com
PC: Notepad++ - https://notepad-plus-plus.org
• A working Drupal site Acquia Dev Desktop - https://www.acquia.com/downloads
• Troubleshooting /research resources Devel module - https://www.drupal.org/project/devel
Internet access
![Page 5: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/5.jpg)
5
• What is an API? An application programming interface (API) expresses a
software component in terms of its operations, inputs, outputs and underlying types.
Drupal core modules contain MODULE_NAME.api.php files defining functions that other modules can “hook” into.
Well documented at http://api.drupal.org
![Page 6: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/6.jpg)
6
• What is a hook? Hooks are how modules can interact with the core code
of Drupal. A hook can be thought of as an event listener in the sense
that an event triggers an action. Ex. hook_delete Some hooks let you alter things that have been generated
just before they're processed. Ex. hook_form_alter Other hooks allow you to add or register new content
items. Ex. hook_block_info
![Page 7: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/7.jpg)
7
Drupal
sites
all
modules
block_example
![Page 8: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/8.jpg)
8
block_example.module
block_exampleblock_example.info block_example.test
block_example.install
![Page 9: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/9.jpg)
9
block_example.info
![Page 10: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/10.jpg)
10
block_example.module
![Page 11: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/11.jpg)
11
block_example.install
![Page 12: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/12.jpg)
12
• I want to modify the contact form
![Page 13: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/13.jpg)
13
• I want to modify the contact form: Enable “Send yourself a copy.” checkbox by default Change the title of the form to “AWESOME Contact
Form” Change the field label “Your name” to “Your AWESOME
name” Add help text to the Subject field with suggestions Change the text of the submit button to “Send your
AWESOME message”
![Page 14: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/14.jpg)
14
my_module.info
![Page 15: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/15.jpg)
15
my_module.module
![Page 16: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/16.jpg)
16
![Page 17: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/17.jpg)
17
api.drupal.org – hook_form_alter
![Page 18: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/18.jpg)
18
![Page 19: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/19.jpg)
19
![Page 20: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/20.jpg)
20
![Page 21: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/21.jpg)
21
![Page 22: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/22.jpg)
22
![Page 23: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/23.jpg)
23
![Page 24: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/24.jpg)
24
api.drupal.org – Form API Reference
![Page 25: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/25.jpg)
25
![Page 26: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/26.jpg)
26
![Page 27: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/27.jpg)
27
![Page 28: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/28.jpg)
28
![Page 29: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/29.jpg)
29
api.drupal.org – drupal_set_title
![Page 30: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/30.jpg)
30
![Page 31: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/31.jpg)
31
![Page 32: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/32.jpg)
32
![Page 33: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/33.jpg)
33
api.drupal.org – Form API Reference
![Page 34: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/34.jpg)
34
api.drupal.org – Form API Reference
![Page 35: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/35.jpg)
35
![Page 36: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/36.jpg)
36
![Page 37: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/37.jpg)
37
![Page 38: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/38.jpg)
38
api.drupal.org – Form API Reference
![Page 39: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/39.jpg)
39
api.drupal.org – Form API Reference
![Page 40: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/40.jpg)
40
![Page 41: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/41.jpg)
41
![Page 42: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/42.jpg)
42
![Page 43: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/43.jpg)
43
api.drupal.org – Form API Reference
![Page 44: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/44.jpg)
44
![Page 45: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/45.jpg)
45
![Page 46: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/46.jpg)
46
• I want to add a non-node page: The page should be accessible by anyone who can see
published content at: mysite.com/awesome-page The title of the page should be “I can make a page!” Include the following paragraph on the page: “I am so
awesome that I can create my own page in a custom module.”
![Page 47: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/47.jpg)
47
…
api.drupal.org – hook_menu
![Page 48: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/48.jpg)
48
![Page 49: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/49.jpg)
49
![Page 50: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/50.jpg)
50
api.drupal.org – hook_menu
![Page 51: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/51.jpg)
51
![Page 52: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/52.jpg)
52
![Page 53: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/53.jpg)
53
![Page 54: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/54.jpg)
54
![Page 55: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/55.jpg)
55
![Page 56: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/56.jpg)
56
api.drupal.org – hook_menu
![Page 57: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/57.jpg)
57
![Page 58: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/58.jpg)
58
api.drupal.org – hook_menu
![Page 59: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/59.jpg)
59
![Page 60: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/60.jpg)
60
![Page 61: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/61.jpg)
61
![Page 62: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/62.jpg)
62
![Page 63: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/63.jpg)
63
FLUSH THE CACHE
![Page 64: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/64.jpg)
64
![Page 65: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/65.jpg)
65
• I want the following to happen when an author creates a new article: Change the author to me, so it looks like I’m doing more
work than I am. Make sure that all new articles are set to publish by
default, so my boss will see “my” work.
![Page 66: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/66.jpg)
66
api.drupal.org – Node API Hooks
![Page 67: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/67.jpg)
67
api.drupal.org – hook_node_insert
![Page 68: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/68.jpg)
68
![Page 69: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/69.jpg)
69
![Page 70: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/70.jpg)
70
![Page 71: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/71.jpg)
71
![Page 72: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/72.jpg)
72
![Page 73: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/73.jpg)
73
![Page 74: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/74.jpg)
74
![Page 75: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/75.jpg)
75
![Page 76: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/76.jpg)
76
![Page 77: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/77.jpg)
77
![Page 78: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/78.jpg)
78
node/add/article
![Page 79: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/79.jpg)
79
![Page 80: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/80.jpg)
80
node/15/edit
![Page 81: Introduction to Module Development (Drupal 7)](https://reader034.vdocuments.us/reader034/viewer/2022051521/58f2b2141a28ab7b6b8b4587/html5/thumbnails/81.jpg)
81
• Examples for Developers - https://www.drupal.org/project/examples
• Drupal API reference - https://api.drupal.org
• DrupalContrib API reference - http://www.drupalcontrib.org
• Drupal Answers - http://drupal.stackexchange.com