school of information university of michigan si.umich.edu drupal: configuration and customization...
TRANSCRIPT
![Page 1: SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e155503460f94aff0e1/html5/thumbnails/1.jpg)
SCHOOL OF INFORMATION
UNIVERSITY OF MICHIGANsi.umich.edu
Drupal: Configuration and Customization
Week 4: Installation, Module Development
January 25, 2007
Professor Paul Resnick
(with help from Michael Hess, as usual)
![Page 2: SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e155503460f94aff0e1/html5/thumbnails/2.jpg)
SCHOOL OF INFORMATION
UNIVERSITY OF MICHIGANsi.umich.edu
Today’s Learning Objectives At the end of this week, students should
be able to:– Debug minor installation and upgrade
problems– Explain the major differences between
Drupal 4.7 and 5.0– Explore the code behind a contributed
module– Create small custom modules
![Page 3: SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e155503460f94aff0e1/html5/thumbnails/3.jpg)
SCHOOL OF INFORMATION
UNIVERSITY OF MICHIGANsi.umich.edu
Drupal 4.7 Installation
If you don’t have an auto-installer (e.g., fantastico)… Download and extract the tar.gz file
– Place in a web-accessible folder on your server• E.g., htdocs
Edit sites/default/settings.php file– Directions in the comments in this file– location of your database – $base_url path
Import the database– Get directions from your ISP– E.g., mysql dbname –u dbuser –ppassword < drupaldb_file
![Page 4: SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e155503460f94aff0e1/html5/thumbnails/4.jpg)
SCHOOL OF INFORMATION
UNIVERSITY OF MICHIGANsi.umich.edu
Drupal 5.0 Installation
If you don’t have an auto-installer (e.g., fantastico)…
Download and extract the tar.gz file– Place in a web-accessible folder on your server
• E.g., htdocs
Change perms on /sites/default/settings.php to 666– Owner, group, and other all read/write privileges
Access your Drupal install via web and follow the directions
![Page 5: SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e155503460f94aff0e1/html5/thumbnails/5.jpg)
SCHOOL OF INFORMATION
UNIVERSITY OF MICHIGANsi.umich.edu
Upgrading 4.7 to 5
See Lullabot screencast Note: you can’t do this on cms.si.umich
– We have a multi-site installation
![Page 6: SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e155503460f94aff0e1/html5/thumbnails/6.jpg)
SCHOOL OF INFORMATION
UNIVERSITY OF MICHIGANsi.umich.edu
Drupal Security
If you’re the site maintainer…– Join the security mailing list
• Login to drupal.org• My account >> my newsletters
– When you get a security alert for a module you’re using
• Upgrade as soon as you can
– When you get a security alert for Drupal core• Follow the suggested action ASAP
Do NOT install modules not found on Drupal.org– No security alerting system
![Page 7: SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e155503460f94aff0e1/html5/thumbnails/7.jpg)
SCHOOL OF INFORMATION
UNIVERSITY OF MICHIGANsi.umich.edu
Drupal 5.0 Preview
Key changes– Installation is easier– Administration interface changes– Themes
• New: Garland• Some color changes without changing code
– CCK is part of core– Installation Profiles
See Lullabot screencast
![Page 8: SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e155503460f94aff0e1/html5/thumbnails/8.jpg)
SCHOOL OF INFORMATION
UNIVERSITY OF MICHIGANsi.umich.edu
Some PHP Basics
Semi-colon at end of statements { } enclose collection of statements Variables If-statements Functions Arrays For loops
![Page 9: SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e155503460f94aff0e1/html5/thumbnails/9.jpg)
SCHOOL OF INFORMATION
UNIVERSITY OF MICHIGANsi.umich.edu
PHP Variables
Variables begin with $ Set using =
$x = 23; Local unless you specify global
global $user;
![Page 10: SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e155503460f94aff0e1/html5/thumbnails/10.jpg)
SCHOOL OF INFORMATION
UNIVERSITY OF MICHIGANsi.umich.edu
PHP If/Else and Switch/Caseif ($op == "list") {
stm1; stm2; …}else {}
switch ($section) { case “a”: stmt; break; case “b”: stmt; }
![Page 11: SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e155503460f94aff0e1/html5/thumbnails/11.jpg)
SCHOOL OF INFORMATION
UNIVERSITY OF MICHIGANsi.umich.edu
PHP Function Definition
function onthisdate_help($section='') { $output = ''; switch ($section) { case "admin/modules#description": $output = t("Displays links to nodes created on this date");
break; } return $output;} // function onthisdate_help
![Page 12: SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e155503460f94aff0e1/html5/thumbnails/12.jpg)
SCHOOL OF INFORMATION
UNIVERSITY OF MICHIGANsi.umich.edu
PHP Arrays
Example: an array whose first/only item is an array
$items = array(); $items[] = array('path' => 'onthisdate', 'title' => t('on this date'), 'callback' => 'onthisdate_all', 'access' => user_access('access
content'), 'type' => MENU_CALLBACK);
![Page 13: SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e155503460f94aff0e1/html5/thumbnails/13.jpg)
SCHOOL OF INFORMATION
UNIVERSITY OF MICHIGANsi.umich.edu
PHP Foreach Loops
<?php$arr = array(1, 2, 3, 4);foreach ($arr as &$value) { $value = $value * 2;}// $arr is now array(2, 4, 6, 8)?>
![Page 14: SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e155503460f94aff0e1/html5/thumbnails/14.jpg)
SCHOOL OF INFORMATION
UNIVERSITY OF MICHIGANsi.umich.edu
Extensibility Concepts: Defining Add-ons
Adding new names– Only problem is name collisions
• Variables in programs– local and global• XML markup tags– XML Namespaces
Defining meaning of named items– Set variable values– Define functions
![Page 15: SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e155503460f94aff0e1/html5/thumbnails/15.jpg)
SCHOOL OF INFORMATION
UNIVERSITY OF MICHIGANsi.umich.edu
Extensibility Concepts: Integrating Add-ons
Hooks/callbacks– Base calls the add-on
Function libraries– Add-on calls the base
![Page 16: SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e155503460f94aff0e1/html5/thumbnails/16.jpg)
SCHOOL OF INFORMATION
UNIVERSITY OF MICHIGANsi.umich.edu
What Programmers Need to Know About Callbacks
How to register the callback so it will be invoked
When the callback will be invoked Parameters passed and returned
![Page 17: SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e155503460f94aff0e1/html5/thumbnails/17.jpg)
SCHOOL OF INFORMATION
UNIVERSITY OF MICHIGANsi.umich.edu
Drupal Callbacks (Hooks)
Registering a hook– Define a function with the right name
• <modulename>_hookname
– No separate registration process; will automatically be invoked
When hook will be invoked– Check documentation; look at source code
Parameters passed and returned– api.drupal.org
![Page 18: SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e155503460f94aff0e1/html5/thumbnails/18.jpg)
SCHOOL OF INFORMATION
UNIVERSITY OF MICHIGANsi.umich.edu
Drupal Naming Conventions One big namespace Don’t define a module that has same
name as any other module All functions in module begin with prefix
– <module-name>_• For functions that may be invoked from other
files
– _<module-name>_• For private functions
![Page 19: SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e155503460f94aff0e1/html5/thumbnails/19.jpg)
SCHOOL OF INFORMATION
UNIVERSITY OF MICHIGANsi.umich.edu
What Programmers Need to Know About Library Functions Parameters passed and returned
– See api.drupal.org Any side effects of the function
– E.g., saving a node in the database
![Page 20: SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e155503460f94aff0e1/html5/thumbnails/20.jpg)
SCHOOL OF INFORMATION
UNIVERSITY OF MICHIGANsi.umich.edu
Some Useful Hooks
Documentation hook_access hook_block hook_cron hook_menu hook_settings (4.7; use hook_menu in 5.0) hook_nodeapi
![Page 21: SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e155503460f94aff0e1/html5/thumbnails/21.jpg)
SCHOOL OF INFORMATION
UNIVERSITY OF MICHIGANsi.umich.edu
Cron.php
When cron.php is executed– Executes the cron hooks for all contributed
modules Set up a UNIX cron job to cause cron.php to
be executed periodically– Done for you on cms.si
• Once per hour
Poormanscron module if you can’t run a cron job on your installation– Checks on each user access whether it’s time to
run cron.php
![Page 22: SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e155503460f94aff0e1/html5/thumbnails/22.jpg)
SCHOOL OF INFORMATION
UNIVERSITY OF MICHIGANsi.umich.edu
Some Useful Drupal library functions Documentation at http://api.drupal.org/ Theme related
– l(), t() Node functions
– node_load(), node_save() Database functions
– Db_query() et al Forms API Access control
– User_access()
![Page 23: SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e155503460f94aff0e1/html5/thumbnails/23.jpg)
SCHOOL OF INFORMATION
UNIVERSITY OF MICHIGANsi.umich.edu
Drupal Licensing
Drupal Core is Distributed under GPL– You can modify and redistribute it– You can’t prevent others from doing so– You don’t have to distribute your modifications
If you distribute modifications, must be under GPL– Wiggle room about whether a consultant who
gives the module only to a client who paid for its production is distributing it
• Consult an attorney
![Page 24: SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e155503460f94aff0e1/html5/thumbnails/24.jpg)
SCHOOL OF INFORMATION
UNIVERSITY OF MICHIGANsi.umich.edu
Module Development
Tutorial OnThisDate– http://drupal.org/node/22801
A Sign-me-up custom feature for AARecon
![Page 25: SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e155503460f94aff0e1/html5/thumbnails/25.jpg)
SCHOOL OF INFORMATION
UNIVERSITY OF MICHIGANsi.umich.edu
Devel Module
Menu block– Clear the cache– View variable values
PHP block to execute some code Display SQL queries used in building a
page Object structure display for current node
![Page 26: SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e155503460f94aff0e1/html5/thumbnails/26.jpg)
SCHOOL OF INFORMATION
UNIVERSITY OF MICHIGANsi.umich.edu
OnThisDate Tutorial
http://drupal.org/node/22801 Final version of 4.7 code (rename it to
OnThisDate.module)
![Page 27: SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e155503460f94aff0e1/html5/thumbnails/27.jpg)
SCHOOL OF INFORMATION
UNIVERSITY OF MICHIGANsi.umich.edu
Making module information visible hook_help
![Page 28: SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e155503460f94aff0e1/html5/thumbnails/28.jpg)
SCHOOL OF INFORMATION
UNIVERSITY OF MICHIGANsi.umich.edu
Permission Actions
hook_perm
![Page 29: SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e155503460f94aff0e1/html5/thumbnails/29.jpg)
SCHOOL OF INFORMATION
UNIVERSITY OF MICHIGANsi.umich.edu
Create Block(s) in a Module hook_block
– List op– View op
![Page 30: SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e155503460f94aff0e1/html5/thumbnails/30.jpg)
SCHOOL OF INFORMATION
UNIVERSITY OF MICHIGANsi.umich.edu
Create Module Settings
hook_settings– Add a new variable that can be set through
administer >> settings >> this_module
![Page 31: SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e155503460f94aff0e1/html5/thumbnails/31.jpg)
SCHOOL OF INFORMATION
UNIVERSITY OF MICHIGANsi.umich.edu
Create a Page
Define a function that outputs a page Give it a URL path and/or add it to a
menu
![Page 32: SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e155503460f94aff0e1/html5/thumbnails/32.jpg)
SCHOOL OF INFORMATION
UNIVERSITY OF MICHIGANsi.umich.edu
SignMeUp Custom Module Adds a link to sign up as the closer For production we’ll do better
– A custom field type using CCK’s API• Copy and edit userreference
– Button in each of the fields where user can sign up
• Access controls; don’t allow double sign-up, etc.
– Display sign-ups with photos
![Page 33: SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e155503460f94aff0e1/html5/thumbnails/33.jpg)
SCHOOL OF INFORMATION
UNIVERSITY OF MICHIGANsi.umich.edu
Exercises
Which hook would you use? Write or modify a module