Text

How to Learn Drupal

People seem to ask this question a lot. When you’re learning something, it’s comforting to know that you’re doing it correctly and efficiently and that you’re not learning the wrong way or the long way.

Therefore, once and for all, here’s my official 1 minute guide to learning Drupal.

General Advice

As with most things programming related, the best way to get up and running is just to do it already. Download Drupal, install it somewhere, and build a blog just to learn the ropes. You’re going to see terms like “node”, “taxonomy”, “module”, all kinds of words you’re not familiar with. They key is to research stuff like this as you come across it, and make sense of it all as you go.

I’m completely against reading all about something and trying to learn it before actually doing anything with it yourself; it makes a lot more sense to start doing it yourself and use the resources to help you along the way.

If you’re still going to read something before you get started no matter what I say, then read What Is Drupal by Tim Millwood.

Recommended Steps

There are, in my opinion, four basic steps to becoming a Drupal expert. Those are:

  1. Learning to use Drupal core for content administration. To learn: build a multi-user blog using only Drupal core.
  2. Learning to use the big boy contributed modules (such as Views and CCK). To learn: build an image hosting site complete with image resizing, a lightbox, categories, etc.
  3. Learning theme development (including the cool stuff that goes on in template.php). To learn: Build a theme suitable for releasing on Drupal.org.
  4. Learning module development. To learn: Find something that no contrib modules handle (something really weird like a mortgage calculator for California residents), and make a module to handle it.

Once you have a good hang of those four, then you can start cranking out some truly awesome stuff with Drupal.

As for some resources to help you along the way…

Books

If you like books, there are two great ones to pick up.

  • Using Drupal - a really good intro to both Drupal site building and content administration with Drupal.
  • Pro Drupal Development - the big boy in coding Drupal sites, complete with loads of info on creating modules and themes.

Screencasts

If you’re like me, you’d much rather see something done than read about it. If that’s the case, then the following sites have some really good Drupal screencasts for you to get up and running with.

Getting Questions Answered

You’re no doubt going to have questions along the way. Whenever I have questions, here’s my typical process:

  1. Google it for at least 5 minutes, and if you can’t find anything…
  2. Ask in IRC. The #drupal channel at irc.freenode.net usually has about 500 people at any given time (although most of those people aren’t active at any given time), and that’s the hangout for core and contrib devs, so you’ll often get some really good help.
  3. If it’s related to a specific module, then ask your question as a “Support Request” in that module’s issue queue on Drupal.org.
  4. If all else fails, ask on Stack Overflow. There’s about 3 or 4 active contributors to SO that are more or less Drupal experts, so you’ve got a good shot at some help here.
  5. Post in the Forum on Drupal.org. I’ve never had good luck with this so I save this as a last resort.

If, at the end of this process, you still don’t have the answer, then my advice is to go back into IRC and ask your question every 3 or 4 hours until someone answers it or points you in the right direction.

Conclusion

Drupal is what some have called a “wall” project. That means, some projects have learning curves, and Drupal has a learning “wall” that seems impossible until you all of a sudden jump it (i.e., the lightbulb moment) and it all makes sense. Just stick with it until it starts to make sense and you’ll be just fine.

Tags: Drupal
Quote
Also, it might be that you want to clean up your commit history but I might actually want to see the struggle, the mental process you went through to get to the shiny results. Ask a scientist whether they burn their notes once they published their results.

chx, regarding rebasing in git.

Tags: Drupal Git Quote
Text

Some test HTML for Drupal themes

It’s all too common that you hand a Drupal site off to a client, only to realize that the WYSIWYG threw in a common element (such as a blockquote perhaps) that should work look beautiful, but it looks like crap because you never tested it.

As an attempt to solve that, I gathered a crap-ton of markup to be used to test your Drupal theme. It includes both regular HTML elements (pretty much every one you can think of), as well as Drupal-specific stuff (such as tabs and status messages). The purpose of this markup is that you can copy and paste into a node and you have your very own markup tester.

Even though it’s just a single file, I went ahead and put it on GitHub with my other pet projects.

Text

Project Verity

Mark Boulton and Leisa Reichelt just launched Project Verity, which looks to ultimately be a Drupal admin theme aimed at content creators and site editors. It will be “designed in the open and available soon,” although the site says it will be a paid/premium theme.

I asked Mark Boulton about that last part via Twitter:

@markboulton it will be a paid/premium theme?

And his reply:

@mcrittenden Yes it will. This is aimed very clearly at agencies developing sites for people like verity.

That doesn’t make very much sense to me. I’m sort of confused about the notion of designing a theme in the open and then charging for it.

Also, I’m a little confused as to the difference between Verity and Seven, the D7 admin theme they designed. Seems like they would fit the same use case.

That said, I’m pleased to see them taking the initiative I’ll be very interested to see what comes of this and how the community reacts.

Tags: Drupal Theme
Text

Ubuntu Funnel

I just launched Ubuntu Funnel, an aggregator of Ubuntu and Linux blogs.

It’s basically a vanilla install of Development Seed’s Managing News, so I can’t take credit for anything except the fact that I bought the domain and set it up. Development Seed has been doing a really awesome job on not only Managing News, but also Open Atrium and MapBox.

So if you’re into Ubuntu or Linux, check it out and maybe subscribe to its RSS feed.

Also, if you happen to run an Ubuntu blog, just let me know and I’d be glad to add it to the Funnel.

Tags: Ubuntu Drupal
Text

Installing and updating Drupal with CVS

It’s relatively easy to use CVS to keep Drupal core up to date. Here’s a quick guide.

To install core:

$ cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal co -r DRUPAL-6-14 -d directory_name drupal

When doing the above, change 6-14 to the Drupal version you want to check out (obviously using X-X syntax instead of X.X), and change directory_name to the path to the directory where you want it to download.

When it comes time to update, navigate to the site root and run:

$ cvs update -dP -r DRUPAL-6-15

Just change 6-15 to the version you’re updating to.

And of course, don’t forget to run your site’s update.php after these updates are done to keep your database in the game.

Bonus tip: since we all tend to do updates more than we do installs, I added this to my .bashrc file:

alias drupdate="cvs update -dP -r"

(Make sure that after you edit the file, you run bash so that it gets loaded.)

With this alias, you can navigate to your site root (assuming it’s already running off of CVS), and update it using a simple;

$ drupdate DRUPAL-6-15
Text

Why host your Drupal module/theme at Drupal.org?

Many reasons!

  • Larger User Base - Most users check Drupal.org first and assume the project doesn’t exist if it’s not there.
  • Consistency Is Understandable - It is much easier for someone new to Drupal to understand how to download and install themes/modules from a central location rather than 3 or 4 central locations
  • Unified Issue Tracker - “My Issues” will show any issues you are subscribed to for any Drupal project, instead of having to go to different sites to check
  • Usage Statistics - Any project or theme on Drupal.org has tracked usage statistics via the Update Status module
  • Update Notifications - A Drupal website will notify (even email if you prefer) you when a Drupal.org project is updated via the Update Status module
  • Programmatic Updates & Downloads - Hosting everything at Drupal.org means that Drush, Aegir, Plugin Manager, etc. can all have a uniform method of downloading and updating projects.
  • Encouraging Activity - Users are more encouraged to contribute bug reports, patches, etc., if they only have to do so in one place, with one account, and one set of skills.
  • Co-contributors - It is trivial to add more CVS contributors to your Drupal.org project, and more difficult if these contributors would have to be set up in an external site
  • Install Profile Integration - Drupal’s Install Profiles give you pre-packaged versions of Drupal, complete with all required modules and themes. They cannot do this if any of the modules or themes are not hosted on Drupal.org.

I also made this into a handbook page.

Text

Drupal: Add a class to the first non-image paragraph

Say you need to grab the first paragraph of a node’s body that starts out with text. For example, you want to add a drop cap to the first letter of a node’s body, but if the first paragraph only has an image, then you can’t do anything cool like first-child. So here’s what you do.

Throw this into your theme’s template.php:

Replace THEMENAME with your theme’s name (i.e., the name of your theme folder) and you should be good to go. This just adds class=”first” to the first paragraph of your node’s body that does NOT start with an img tag.

Text

Drupal: change a menu item’s class in module

So I just spent 3 hours writing 4 lines of code.

The problem: we need a way to make a certain “Approvals” link red if there are approvals waiting. This could also apply to making an “Inbox” link stand out if you have unread messages or whatever. Anyway, according to Google, this is something that has never been done before in the history of computing, so here it goes.

The hook we’re using is hook_translated_menu_link_alter() a.k.a. the_longest_hook_name_that_drupal_has_ever_dreamed_of(). Basically, that hook grabs menu items before they’re displayed so you can change them however you want. Changing them is tough though, particularly because it’s not documented at all.

So here’s the code.

So as you can see here, I’m counting all the reservation nodes which are unapproved, and if there are any, I grab that specific menu item and give it a class of ‘attention’. The tough part here is the ‘localized_options’ part. The API would have you believe that that part should just be ‘options’ but it’s all a big lie.

Maybe it has something to do with the locale module? Anyway, there you go.

Text

Why make things pluggable?

Just thought I’d share. Larry Garfield (aka Crell aka Drupal’s DB maintainer) left an insightful comment on this blog post:

[…] That’s one of the reasons we maintain a pluggable theme layer, even if it’s not really used [i.e., everybody uses phptemplate even though it’s not the only option - Mike]. It forces us to think about how the theme system will be used and what parts of it really belong where. That’s the example, actually, that Jeff Eaton gave me over dinner one night while I was bemoaning how difficult it was to support PostgreSQL in early versions of DBTNG. :-) Just because no one uses Postgres doesn’t mean we shouldn’t still support it, because forcing ourselves to support it forces architectural decisions that improve the overall system in the first place.

And you know what? He was absolutely right. Now we have full support for 3 databases, a 4th in contrib, and the overall DBTNG [i.e., DB The Next Generation which is the D7 implementation of Drupal’s multi-database abstraction layer - Mike] architecture is much cleaner and better than it would have been otherwise.

Making something pluggable can be an excuse to force yourself to make it right. That you also enable other people to swap it out themselves (with a little or a lot of effort) for their own implementations that do things you never dreamed of is a nice side effect. :-)

This in response to the growing smallcore movement. My ramblings on that are coming soon.