Your SlideShare is downloading. ×
Creating Custom Drupal Modules
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Creating Custom Drupal Modules

16,224
views

Published on

Presentation delivered to the East Anglia Drupal Usergroup meeting on 16th June 2010 demonstrating how to create a simple custom module in Drupal 7.x

Presentation delivered to the East Anglia Drupal Usergroup meeting on 16th June 2010 demonstrating how to create a simple custom module in Drupal 7.x

Published in: Technology

1 Comment
4 Likes
Statistics
Notes
  • really infomative..ease of understanding...
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
16,224
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
267
Comments
1
Likes
4
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Creating Custom Drupal Modules Drupal East Anglia UG – 16/6/2010 Alastair Aitchison
  • 2.
    • Independent developer based in Norwich
    • 3 years Drupal experience
    • Current maintainer of Question module
    • Contributed to Automatic Nodetitles , Node Import , Examples , Synonyms , Tagadelic , WebSnapr ...
    • tanoshimi AlastairA [email_address]
    About Me
  • 3. Types of Module
  • 4. Anatomy of a Module
    • Required
    • .info – metadata describing the module
    • .module – the module PHP code
    • Optional
    • .install – install / uninstall scripts
    • .css – stylesheets
    • .inc – additional include files
    • .test – unit test files
  • 5. Where Do Module Files Reside?
    • CORE
    • /modules/ subdirectory
    • Don’t edit or place other modules here!
    • CONTRIB & CUSTOM
    • /sites/all/modules/ subdirectory
    • Directory name matches module name
  • 6. .info file
    • Metadata about the module
    • Name, description, version, dependencies etc.
    • EXAMPLE!
  • 7. meeting.info
    • name = Meeting Demo Module
    • description = This is a demo module
    • for the Drupal UG meeting
    • core = 7.x
    • version = 7.0 - alpha
    • files[] = meeting.module
  • 8. Drupal’s Hook System Build menus Render node Build blocks hook_menu hook_node_view
  • 9. .module file
    • Implements one or more Drupal hooks – PHP functions that get called by Drupal
    • Proper naming ensures that functions are automatically recognised and fired at the right time
    • Syntax is modulename_hookname
    • EXAMPLE!
  • 10. meeting.module
    • <?php
    • function meeting_menu() {
    • $items['meeting_page'] = array(
    • 'title' => 'My newmenu item',
    • 'description' => 'This is a test menu item',
    • 'page callback' => 'meeting_page',
    • 'access callback' => TRUE,
    • );
    • return $items;
    • }
    • function meeting_page() {
    • return 'Yay! This worked.... probably.';
    • }
  • 11. Altering Other Modules
    • Edit user_login_form? (l. 1,154 of user.module)
    • Use hook_form_ user_login_form _alter
    How to change this? NO! YES!
  • 12. Alter Hooks Build menus Render node Build blocks Perform Alterations hook_menu hook_node_view hook_xxx_alter
  • 13. Not only forms can be altered...
    • hook_link_alter
    • hook_mail_alter
    • hook_menu_alter
    • hook_profile_alter
    • hook_schema_alter
    • ...
  • 14. More Resources
    • http://api.drupal.org – lists all available hooks, together with example usage
    • http://drupal.org/project/modules - contrib module repository
    • http://www.apress.org – publishers of Pro Drupal Development
  • 15. Things to Remember
    • Custom modules add new functionality / alter other modules by implementing hooks
    • Require .info (metadata) and .module (code)
    • Create in a subdirectory of sites/all/modules
    • DON’T EDIT CORE! Use hook_xxx_alter