Drupal tips

Command line Drupal install and update script for multi-site hosting

Maintaining a Drupal site, or a collection of sites is much easier if everything is kept completely separate--Drupal core, contributed modules, and the site itself.
This is even more important if multiple sites are hosted on the same server. Drupal's own multi-site support can be a nightmare to maintain, believe me! (e.g. when you want to upgrade modules or core).
A must simpler and easily supported configuration is to keep everything separate and to use symbolic links to tie it all together. For example, I keep:

Technical Notes

These notes are my personal online notebook of useful commands and "how-to's". You are welcome to make use of them if you find them helpful. They obviously don't come with any warranty! Click on one of the category tags above for the notes in any category.

Add Zurb Foundation theme to Drupal 7 site

1. Install necessary modules and themes:

site=/home/mysite
dsite add $site zurb-foundation -m theme
dsite add $site views_foundation
dsite add $site jquery_update

Notes

Optional modules

Installing Compass on Drupal server

Installing the theme is the easy bit. What is much harder is setting up automatic SCSS recompilation.

  • The README.txt file suggests using a full-blown installation of node.js just to manage this.
  • A much more lightweight solution is to use compass

updating webform from 2.x to 3.x

There are two changes that need to be made.

Drupal Video Players

Modules

Theming CCK fields in Drupal 7

Drupal node display can be overridden using a template file of the form:

  • node--content_name.tpl.php

The simplest way of displaying fields is to use the render() function

The render array is documented here: drupal.org/node/930760

  • Individual field values can be found in one of:
    • render($content['field_name'] fully rendered value
    • $content['field_name']['#items']['0']['safe_value'] will include paragraph markup
    • $content['field_name']['#items']['0']['value'] raw
    • $content['field_na

Drupal 6 to 7 upgrades

The Select builder adds a LOT of overhead. You should not use it unless you need one of the things it offers: Dynamic query structure, hook_query_alter, certain db-unportable features that don’t have a simpler version (random ordering, for instance), etc.
For the run of the mill SQL query, db_query() is several times faster than db_select(). If you need a limit query, db_query_range() is still there.

The "Support" module on Drupal

Some notes on configuring the module

  • Follow the online instructions, but also
    • set the support content type not to be on the front page
    • set the from email address to be do-not-reply@mydomain
    • Default sort: State/ascending
    • Secondary sort: Last update/descending
    • Modify the new and updated ticket email to be something like this:

Deleting large numbers of comments from Drupal

  • You can easily delete all comments with:
DELETE FROM comments;
  • The problem comes when there are good and bad comments, and you only want to get the bad comments. -The cleanest way is to delete all the rogue users first. That will set the UID on their comments to 0, so you can delete all their comments by running:
DELETE FROM comments WHERE uid=0;
Syndicate content