PHP

Get the Value of the Cheapest Option for an Ubercart Product

This is just a quick code example. Imaging you have an Ubercart attribute that has several options and you'd like to show an "As low as $X.XX" price on the frontend. Here's a simple solution. Note that if you wanted the lowest price across ALL attributes you could loop through each attribute too (instead of just looking at attributes[1]).

Showing a nodeasblock block as full content instead of teaser

UPDATE: I've had much better luck with the ​nodeblock​ module. I create an "Editable Block" content type (machine name editblock​) and allow clients to edit these blocks. I've stopped using Node As Block.

By default, the Node As Block module displays a node in teaser mode. After the break, I'll show you how to show the full content of the node using a simple preprocess function in your theme's template.php file.

Sending webform submissions to email based on value of field

We recently did a site for a client that allowed patients to submit a webform to request an appointment. The user could choose their physician and based on their choice, the submission would be emailed to the chosen doctor's secretary. I originally thought about using the key part of the key|value pair for the select list to store the secretary's email address, with the doctor's name. This wouldn't work, however, because the key could not contain standard email address characters. Read on for the solution...

Using hook_form_alter() and #after_build to set maxlength on emvideo title field

A fellow Drupal user posted an issue to the Embedded Media Field project. The user was trying to set the maxlength from 35 characters to some other number for the 'title' field within each embedded video widget. I faced the same issue with a site. The client wanted to be able to add more lengthy captions to each video they uploaded. I added the embedded video field (YouTube) as an "unlimited" video field.

Automatically create a Drupal node when a user registers

Sometimes projects come up that have requirements that cannot be solved with an out-of-the-box Drupal install. A project I worked on some time ago required that I store a node every time a user registered for an account. The details of the project are a little fuzzy for me now, so I'll just skip right to the example.

Programmatically displaying an image using an imagecache preset

The following illustrates one way to render an image using an Imagecache preset.
Naturally, if your imagefield has multiple uploads you could wrap this in a foreach.

$path = $node->field_pgallery_images[0]['filepath'];
$alt = $node->field_pgallery_images[0]['data']['alt'];
$title = $node->field_pgallery_images[0]['data']['title'];
print theme('imagecache', ‘presetname’, $node->field_pgallery_images[0]['filepath'], $alt, $title, $attributes);

Pages