Drupal

New Lines to Paragraph Tags (nl2p)

Problem: Emails from your site go out in a good looking HTML format, but some of the content you want to inject in those emails are plain text while others are already formatted with HTML. The email content of the plain text emails which are only plain text now appear as one big block of text with no line breaks.

Let's look at this problem specifically in the context of a Drupal website.

All the emails such as welcome, password recover, etc... are plain text by default. Now you want to add a nice email template utilizing a module like mimemail.

Tags: 

Installing Drush without PEAR

Here's an easy way to install drush without PEAR.

Note, replace the wget argument with a current version of drush. http://drupal.org/project/drush

# cd /usr/local/share/
# wget http://ftp.drupal.org/files/projects/drush-x.x-x.x.tar.gz
# tar -zxvf drush-7.x-5.7.tar.gz 
# rm tar -zxvf drush-7.x-5.7.tar.gz
# chmod a+x drush/drush
# ln -s /usr/local/share/drush/drush /usr/local/bin/drush

When you want to update drush, simply replace the drush directory in /usr/local/share.

Drupal 7 Ubercart - Programmatically Capture Pre-Authorized Payments from Authorize.net

I'm working with Drupal 7, Ubercart, and the Authorize.net payment gateway.

The goal here is to pre-authorize the payment at check-out, and capture the payment once the items have been shipped. I'm using order status to trigger when that happens, but I wanted to just show an example of how to capture that pre-authorized transaction.

    Important notes:

Printing or Rendering a Node Field or Profile2 Field in Drupal 7

When overriding a node template or user profile, you should not be drilling down the field array and printing the output unless you have a very good reason to do so. i.e. (do not do this) print $node->field_zipcode['und']['0']['value'];

The Drupal 7 field api offers us the field_view_field() function to get a renderable array of the output for a field entity.

When a Custom Page is a Better Option than a Page Node

I'm not even talking a page node with PHP in it, I'm talking a page that's going to remain static.

Many times when we need to create a static page it's just a matter of creating a page node. But when would it make sense to create the page inside of a module, even when there's not much dynamic going on?

1. Deploying a node that a themer would need to override the node template for.

Let's say you create a page node on a development server for an about-us page and the graphic designer created it in a way that node.tpl.php will just not work with.

Tags: 

Drupal 6 to 7, a first glimpse

Today I finally started porting a module over to Drupal 7. I didn't read up in depth on the changes and just dove in and started learning based on the PHP errors and features that were not working.

I'm not going to go into anything too in depth here as there is good information out there already, but I took some notes and will point out some changes I had to make with the module I was working on.

Admin settings path

Tags: 

Adding IDs to all Fieldsets

A themer on a project I was recently working on needed a lot of CSS IDs added to fieldsets throughout the site.

Fortunately, there's a theme_fieldset() function in includes/forms.inc

I was able to copy that function into the phptemplate.php file, obviously change theme_ to phptempalte_ in the function name, and then add logic that adds an ID based on the fieldset name if an id does not already exist.

Here's the code:

/**
* Format a group of form items.
*
* @param $element
* An associative array containing the properties of the element.

Q-Views

Q-Views is a module I came across while browsing through new modules on drupalmodules.com.

It's been a while since I've been so impressed with a module. This allows you to create views based of SQL. You allow it to analyze your SQL and it will populate a list of options for each field your query returns.

You can write module hooks to handle the query output on a per-field basis, or you can write the handler directly in the configuration.

Subscribe All Users to a Simplenews Newsletter

There's been a couple times where I've had to subscribe all users to a new newsletter.

I started out with a snippet I found which cleans up the subscriptions, but I lost the link or I would have referenced it here.

Here's the code that will subscribe all users to newsletter node id 16. Note I'm using mysql_insert_id() as a quick fix so you will need to use another method if you're not using mysql.

$result = db_query("SELECT uid, mail FROM {users} WHERE uid>0");

while ($row = db_fetch_object($result)) {