Drupal Flexibility and Core Hacks

Posted by matt on Sun, Apr 26, 2009 at 12:55pm

As Gina kindly pointed out to me recently, my blog promises overlong tangents about Drupal, but hasn't delivered lately. Since my first-year anniversary of working with Drupal is coming up, I thought I'd change that and share my experiences so far.

I came to Drupal as a PHP/MySQL programmer and a bit of a snob about building sites from scratch. My primary concern was that a mature CMS would be too constricting, that it would keep me from doing things I wanted to do, or else those things would require complex, time-wasting workarounds.

I'm really happy to say, I was wrong.

Drupal is a fantastically flexible system, and don't believe anyone who says otherwise. Anything is possible in Drupal. You can modify it to work however you like, and on the whole, it's so flexible that you should be able to easily implement whatever you need on top of what's there. Rather than feeling constrained by the core CMS, I've found it liberating, saving me the time and effort of hand-coding a lot of backend stuff like edit pages, logs, and other admin screens that are, frankly, really boring to do. It's very easy to take what you've got in core Drupal and add your own stuff on top of it...much easier than rolling your own CMS from scratch.

The only big no-no is hacking core Drupal. Core Drupal refers to the main drupal distribution itself, which includes the main framework and six required modules (block, filter, node, system, user, watchdog), plus several optional modules. Hacking core Drupal can cause your site to fall out-of-sync with important security updates, as well as adding a significant risk of future malfunction.

On IndieBound.org, I've made one significant hack to core Drupal. One. Here it is:

user.module line 311:

if ($file = file_save_upload('picture_upload', variable_get('user_picture_path', 'pictures') .'/picture-'. $user->uid .'.'. $info['extension'], 1)) {

changed to:

if ($file = file_save_upload('picture_upload', variable_get('user_picture_path', 'pictures') .'/picture-'. $user->uid .'-'. time() .'.'. $info['extension'], 1)) {

This code simply appends a timestamp to a new user picture when it's uploaded. Otherwise, the new user picture has the same filename as the old user picture, which means many browsers won't automatically refresh the picture, causing the user to think the upload didn't "take." Confusing!

This is a RARE example of the kind of thing that can't be circumvented. Almost anything else can be modified without hacking core Drupal.

I'm going to start blogging at more length about how I've set up certain features of this site, because I think it might be helpful to other Drupal users out there. Googling for such blogs was certainly of enormous help to me when I was getting started...and still is today.

Want to know more about a certain topic? Ask me--I'll write what I know.

Interest Tags: drupal

Comments

thecolorblue's picture

Ramblings of a beginner

From what I understand you can do pretty much anything in a module using hooks. This would also save you from having problems updating later.
I have been messing around with drupal on and off since last september. i am still just getting used to views and CCK.
I am always amazed at how huge the network of developers is for a project like drupal.

matt's picture

Views and CCK...

Drupal's hook system is great. I think the thing about Drupal is that it always emphasizes flexibility over simplicity; hence the steep learning curve.

Views and CCK are both pretty confusing. CCK in particular can be tricky to follow on the database side of things.

My main concern about both was that they would be slow. CCK is definitely not slow, due partly to its cache and partly to some smart loading methods. Views generates some hideous, paragraph-long SQL queries but most of the time its performance is decent. Ultimately, I think the ease of maintenance is a good argument for using both.

Depends which version of Drupal you're using, too. If you're using Drupal 7, CCK is now part of core with Fields API and, from what I can gather, is a bit more straightforward. We're using Drupal 5 here.

linktolonkar's picture

ok thank you

ok thank you

Indie Bookstore Finder

FIND US ON:
IndieBound on Twitter IndieBound on Facebook

Indie Bestsellers

We Were Liars
E. Lockhart
Delacorte Press
Americanah
Chimamanda Ngozi Adichie
Anchor
The Bees
Laline Paull
Ecco Press
All the Light We Cannot See
Anthony Doerr
Scribner Book Company

Make Your Own Wishlist






Update Profile