Download presentation
Presentation is loading. Please wait.
Published byBranden Dennis Modified over 9 years ago
1
1/30/11 Hacking your way through the Drupal API, a themers intro Baris Wanschers (BarisW)
2
How to chop an onion?
14
Baris Wanschers Drupal Specialist at Sogeti Board member of the Dutch Drupal foundation Maintainer of some small modules (Google Fonts, Termcase, Menu Force, Translate This button, etc) Wrote some patches for Drupal 7 Core Build www.drupal7releaseparty.orgwww.drupal7releaseparty.org
15
Agenda The joy of a contrib modules They come with limits More modules to fix this? Or can we do this ourselves? Some usecases and example code (don’t panic, it’s just PHP)
16
My first little module
17
What do you need? A folder to store the files in (mymodule) An info file (mymodule.info) to describe the module A module file (mymodule.module) with the actual code
18
mymodule.info name = My module description = "The description of my module" core = 7.x ; Module dependencies dependencies[] = taxonomy
19
The hook system
20
hook_what? Drupal modules are build around hooks. Hooks are functions that Drupal tries to access Replace hook_ with yourmodule_ Example: mymodule_menu is a call to hook_menu in mymodule Check the API on hook_. You can use these!
21
Example: hook_init Perform setup tasks This hook is run at the beginning of the page request
22
Example: hook_init Perform setup tasks This hook is run at the beginning of the page request
23
The power is yours If you know just these hooks hook_menu_alter to change navigation items hook_form_alter to edit forms Also interesting hook_node_* (hook_node_view, hook_node_load, etc) hook_user_* (hook_user_view, etc)
24
Menu system function devdays_menu() { $items['hello-world'] = array( 'title' => 'Hello world', 'page callback' => 'devdays_hello_world', 'access arguments' => array('access content'), 'type' => MENU_NORMAL_ITEM, ); return $items; } DEMO
25
Form system $form['title'] = array( '#type' => 'textfield', '#title' => 'My title', '#required' => TRUE, ); $form['description'] = array( '#type' => 'textarea', '#title' => 'Description', ); DEMO
26
Improve the user form User register / log in
28
Let’s begin! Useful links Devel module: http://drupal.org/project/develhttp://drupal.org/project/devel Drupal API: http://api.drupal.org/api/drupalhttp://api.drupal.org/api/drupal Drush: http://drupal.org/project/drushhttp://drupal.org/project/drush DEMO
29
New revision Make the log message required
31
Summary What did you learn? Basic insight in the hook_system Few lines of code instead of huge modules and hours of searching hook_menu_alter to change menu items (also to override a function) hook_form_alter to change forms (and change classes/id’s)
32
Summary What did you learn?
33
Questions? Twitter: @BarisW Drupal.org / IRC: BarisW Web: http://www.bariswanschers.com/http://www.bariswanschers.com Mail: baris.wanschers@sogeti.nlbaris.wanschers@sogeti.nl
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.