Skip to main content

Beginning Drupal, the book

In 2007 I made a small comment on Dries' blog that what Drupal needed was a book on Drupal for the end user. Fast forward three years and I still haven't written that book although J. Ayen Green wrote something close to what I had in mind. Instead I wrote a book designed for new developers coming over to Drupal, it is entitled Beginning Drupal (7).

I wrote the book while living and working in China in late 2008 and 2009. A lot of my work in China was training others how to use Drupal from the perspective of a site builder and architect. These folks were primarily developers that had transitioned to Drupal as their full-time job. They didn't need to know how to build a specific website or how to get a specific module working. They needed to understand Drupal and have a reference to all of its working. These folks would not be building a single site in Drupal but many, many sites in Drupal. It is this audience that I wrote the book for.
Beginning Drupal (7) is a book designed to pick apart Drupal's different areas and thoroughly examine them. It mimics my own personal method of training. In fact the book is primarily a collection of several of my personal lesson plans and exercises that I used in class. The chapters and exercises are organized by an area of Drupal such as Content management, User management, and Internationalization. Each chapter uses exercises that build upon each other starting small and then working to a robust website but the chapters are not necessarily connected. For example, you could learn all about User management on one day and skip ahead several chapter and learn about Internationalization.

Drupal 6 or Drupal 7?

When I began writing the book I was training developers on how to use Drupal 6 and many of the exercises and chapters were initially written on Drupal 6. Drupal 7 was on the horizon and was more interesting to follow and write about. Drupal 6 is awesome but Drupal 7 is downright amazing. It was a great journey to watch the development of Drupal 7, the Drupal community is absolutely amazing.

Drupal 7? Its not even out yet!

Yes. The book was written on Drupal 7 even though Drupal 7 is not yet stable. The vast majority of the book will require no revisions after Drupal 7 is released although the sections on Views, Workflow and Rules may require some minor updates. These areas have been highlighted in the text and we have a plan to revise the book if and when necessary.

Who is the intended audience?

Students of Drupal. The book was primarily written from my course materials and notes that I taught from. If you want to build a single website and never see Drupal again this book is not for you. If you are new to Drupal and want to really understand Drupal then you are the intended audience. This book is for long-term Drupal users. I have already begun to use this book in my courses and I hope that other Drupal instructors find it as helpful as I do.







3 comments -- Add a new comment

Top Drupal Hooks and Functions

Alternative title: What every new Drupal developer should know

Over the past few years I've been teaching various Drupal classes ranging from introductory courses to module development courses for seasoned developers. In fact what lit a fire under me to write up this entry was an upcoming course I'm doing with Chapter Three December 14-18th in San Francisco. I'm my classes nearly every student has asked me a variation of the same question; What do I need to know?

If the student was a beginner I'd point them to one of the numerous Top X Drupal modules, such as Lullabot's Top 80, or direct them to review the awesome site showcases up on drupal.org. If the student was a developer (or aspiring developer) the answer was never as concrete. I would explain the concept of a hook, rattle off a few hooks I thought were important, point them to greggle's (or GVS's?) awesome Cheat sheet, tell them about t(), hook_menu, explain how db_query() worked, and then direct them to http://api.drupal.org. Being the geek I am this wasn't good enough for me so I set out to find out what the top hooks and functions were. I wanted something concrete.

I broke out my terminal and used CVS to checkout every module on drupal.org that was listed as stable for Drupal 6 (those in a DRUPAL-6 branch), 3,308 modules. I then wrote a quick and dirty BASH script that went through every function sorting, counting, and ultimately discovering what the most heavily used hooks were. I wrote this script over a year ago at a time when I was living behind the great firewall of China, which made blogging, twittering, and other fun Internet activities a frustrating experience, which is why I have not posted this sooner.
Without much further delay here are the top hooks used in Drupal 6:

Hook name# of usesComments
hook_menu2,120
hook_uninstall1,659Very brief research showed that modules were implementing hook_uninstall to remove variables set in the administrative pages or with variable_set, which would explain why this has more implementations than hook_install
hook_install1,520
hook_perm1,374
hook_help1,232Wow! This is pretty awesome
hook_theme1,183
hook_schema999
hook_form_alter852
hook_nodeapi660
admin_settings591 This is not a hook but a common way to name your administrative settings function.

The next 12 significant implementations are:

Hook name# of usesComments
hook_block568
hook_init538
settings446Related to admin_setting in the top ten
hook_form437
hook_user354
hook_cron317
hook_enable273
settings_form265Related to admin_setting in the top ten
hook_load264
hook_views_api261
hook_delete241
hook_access237

Most Utilized Functions

My curiosity then led me to answer the question: What are the most frequented used functions in a Drupal module?
A few commands later I discovered 143,783 unique functions used a total of 1,008,398 times across the 3,308 modules. Below is how these panned out.
Note: I removed uses of if, foreach, etc.

Function name# of usesComments
array()200,886Proof positive Drupal developers love arrays. Note that this is technically a language construct and not a function.
t()107,388Hurray for translation!
db_query()24,266Drupal developers also love the database
variable_get()23,694
theme()8,283
drupal_set_message()8,260We love our messages
l()7,149
isset()6,331
db_fetch_object()6,072db_fetch_array came in at 1,931 uses
url()5,087
unset()4,654
define()4,350
variable_del()3,969
variable_set()3,854
check_plain()3,384
drupal_render()3,321
db_result()3,147
form_set_error()3,111
drupal_get_path()2,825
str_replace()2,633



For the curious here are the BASH commands I ran to discover this information

The completely inefficient but written in roughly ten minutes BASH script I used to discover the top hooks was: --count_functions.sh--

#!/bin/sh
module_dir="/Users/jredding/Downloads/contributions/modules"
for module_name in `find $module_dir -name *.info|xargs basename |awk -F.info '{print $1}'`
do
grep -hr "function * ${module_name}_" *|awk -F${module_name}_ '{print $2}'|awk -F"(" '{print $1}'
done

I then piped the output through

sort |uniq -c |sort -n 
Be aware that this method takes a very long time to process, roughly three to four hours. I later modified the script to the following, which only took about seven minutes to run:
functions_tmp=/tmp/all_functions.txt
module_dir="/Users/jredding/Downloads/contributions/modules"
grep -hR "^function *" modules/* > $functions_tmp

for module in `find $module_dir -name *.info|xargs basename |awk -F".info" '{print $1}'`
do
  grep -h "function * ${module}_" $functions_tmp |awk -F${module}_ '{print $2}'|awk -F"(" '{print $1}'
done
rm $functions_tmp
~                 
Of course I could probably save more time if I saved the data to two arrays and did all of this searching/sorting in memory instead of performing literally thousands of disk hits. I'll save that for another day.

To discover every function used I ran the following command:

find ./modules/ -exec awk '/[a-9]\(/ { for (i = 1; i <= NF; i++) printf "%s\n", $i }' {} \; |awk '/[a-9]\(/ {print}'|awk -F\( '{print $1}' |sort |uniq -c |sort


A few interesting stats

I found the following stats interesting.

#What
3,308Total modules analyzed
67,582Total number of defined functions
20-21Average number of functions per module
143,783Unique functions called including Drupal and PHP functions
1,008,398Total functions called including Drupal and PHP functions


Raw Data

Function use

15 comments -- Add a new comment

2009 Association Budget

As the first major budgeting process the Association undertook it was a bit of a long and mildly painful process. However we work out the kinks, set our goals, priorities and creating awesome working teams. Check out the newly published 2009 budget!. As always if you see something interesting and want to get involved contact us.

Add a new comment

Drupalcon Survey

Another Drupalcon has come and gone but our work is not over. A dedicated team is actively at work on Drupalcon Paris and another team is being formed to put on Drupalcon 2010. Drupalcon is built by and is for the community. They are what you want them to be. Help us shape the future of Drupalcon by taking a few minutes to answer the questions in the Drupalcon Survey.

Thanks to every one of the over 1,400 people that showed up in D.C, I hope that we can top that number in Paris and then again in 2010!

3 comments -- Add a new comment

Rock your session at Drupalcon

Are you presenting at Drupalcon D.C? Rock it!

Drupalcon D.C is nearly upon us and the registration is slammed shut full. The D.C team found extra room released a few more tickets and hired white gloved people to shove everyone into rooms Japanese Subway style. This is going to be the largest and most packed Drupalcon ever. This is your chance to address hundreds and thousands of Drupalers about your module/API/technique/process or <Insert name of your session >. Put your best foot forward and rock your session.

You were chosen to speak because you are an expert in your subject and people want to hear your thoughts, opinions and to learn from you. You were also chosen because you have an ability to convey yourself well and understand the time and other constraints imposed when speaking at a conference. With just two weeks left now is a good time to start practicing and getting ready for your session. The Drupalcon D.C team and Emma Jane have graciously stepped up to help you out. The day before the conference Emma will be hosting a session entitled "Presenting You!", all presenters ( seasoned or not) should try to attend.

Presenting You! will go over techniques to overcome nervousness and maintain your collective self while on stage and being stared at by hundreds of eyeballs (not to mention cameras, phones, voice recorders, etc.). She'll will also give you tips on managing your time and controlling the presentation so that you use all of your time effectively. The session description also has great resources to help you prepare your slides as well as your talk.

You don't have to wait until Drupalcon to get ready. If you haven't already present your session to your local Drupal meetup. Give it a good once through to work out any kinks. Your local community will appreciate it and you'll learn the nuances that can take your session from good to great. You may also consider attending your local Toastmasters to brush up on your public speaking skills if its been a while.

Drupalcon is a success because of YOU. These resources are here to help you become the best presenter you can be and leave the audience wanting to know more.

See you at Drupalcon!

2 comments -- Add a new comment