Drupal
Duplicate menu entries in Drupal 7's admin_menu module
The Drupal 7 version of admin_menu isn't done yet, and once in a while you'll get an admin menu full of stupid duplicate links, like so:

Here's a sql query that will find and delete the offending duplicates for you (use at your own risk):
- DELETE FROM menu_links WHERE mlid IN (SELECT duped_ids.mlid FROM (SELECT max(mlid) AS mlid, menu_name, link_title, link_path, router_path, module, count(*) FROM menu_links GROUP BY menu_name, link_title, link_path, router_path HAVING count(*) > 1) AS duped_ids)
Setting up email subscriptions and notifications in Drupal 7
Drupal Level: Beginner-Intermediate
Email notifications are the glitter of community sites: very few people passionately like them, but you'll never get rid of them. Probably the most typical use case on a Drupal site is to send an email notification to let a node's author know that someone's commented on their node. I just spent the good part of an afternoon setting this up on a Drupal 7 site, and thought I'd pass along some time saving tips.
Knowing Your Body and Practicing Safe CSS
This is a quick trick I picked up to guarantee that any css changes you make only affect what you want.
There are different ways to identify the page you need to change. I tend to use url as it's always unique.
Here's how:
Locate the template.php file for the theme your working on and add something like this to the page_preprocess function
- function your_theme_preprocess_page(&$vars) {
- // Add a custom body class for specifc page
- if ($_REQUEST['q'] == 'example/page/new-body-class') {
- $vars['body_classes'] .= ' custom-body-class-name ';
- }
IE Blew Up My Layout!!!
We've all experienced it, you've themed out a page and it looks fantastic in Firefox. Unfortunately the time has arrived for your IE testing... You've dreaded it the entire time and have put it off. You fire up your windows testing environment and your worst nightmare has come true. The entire layout is blown out. Divs are strewn about like your tpl.php ate a hand grenade.
db_affected_rows() is annoying
Given the following Drupal code:
and assuming that dummy_column doesn't exist in the users table, what is printed? Here's a hint from the php manual:
mysql_affected_rows()
Returns the number of affected rows on success, and -1 if the last query failed.
If you said "-1" like me, you're wrong (at least some of the time). The code above will return "1" if you have watchdog enabled.
How to use Apache's Proxy on Drupal's Files directory
Drupal's files directory can get enormous, and it's best not to keep it in version control. Here's a way to use Apache's proxy module to point your local environment directly to your dev/live site's files directory so you don't have to download it.
In your httpd.conf:
- ProxyRequests On
- ProxyVia On
- <Proxy *>
- Order deny,allow
- Deny from all
- Allow from localhost
- Allow from all
- </Proxy>
- <Location /sites/default/files/imagecache/>
- ProxyPass http://dev.yoursite.com/sites/default/files/imagecache/
- </Location>
I'll pay you when I'm rich
XXXXX YYYYY has sent you a message.
Date: 6/18/2010
Subject: Part-Time Drupal Project
Dear Domenic:








