drupal

Render/embed a Panels Page in a jQuery Dialog Box

I need a page on my Drupal 7 project site to display within a jQuery modal dialog box. Adding content to a jQuery dialog is straightforward with the Dialog module. The issue was the dialog box needed to contain the contents of a Panel. Previously I've embeded Views using views_embed_view(), but I've never tried to embed a Panel. A web search wouldn't give me a quick answer, so I worked it out.

Change Image Style and Row Class depending on result count

This is a simple example of the use of Views hooks in the template.php file of a theme. It is written for use with Drupal 7 and Views 7.x-3.0-beta3. 

In this project, a page contains a View which must display one, two or three results/rows. Each row contains an image and and body text. The final output display must to stay roughly the same size regardless of the amount of content. To make it all fit and allow for custom theming/CSS, I decided to change the Image Style and Row Class depending on the number of results.

Clear a form field on click with JS & Behaviors in Drupal 7

A common web design feature is to move the label for a form field into the field value, then clear the field once it gains focus. There are many ways to implement this functionality, but this is the Drupal 7 theming method.

These steps assume your theme contains no custom Javascript. They describe how to add the word Search to the regular Drupal search block text field.

  1. Open your template.php file.
  2. We will use hook_form_alter() to change the value of the search field:

Using the Drupal 6 files table for uploads

Drupal 6 provides a files table for managing files in your custom modules, but the correct usage isn't well/obviously documented. The following code works best in my experience:

$file = new stdClass();
$file->filename = file_munge_filename(trim(basename($_FILES['files']['name'][$source]), '.'), $extensions);
$file->filepath = $_FILES['files']['tmp_name'][$source];
$file->filemime = file_get_mimetype($file->filename);
$file->filesize = $_FILES['files']['size'][$source];
$file->uid = $user->uid;
$file->status = FILE_STATUS_TEMPORARY; //'FILE_STATUS_PERMANENT'

Displaying CCK field data in Solr results

The Apache Solr Search module adds a lot of functionality to the base Drupal system. You can easily search by title, body, and CCK fields. One you'll often run into is many times the designer and/or client wants CCK field data in the search results. You can easily search, and filter by the CCK fields, but how do you get them back out of the Solr index to display? You could do something extremely inefficient like running node_load() for every returned node ID, but there are better answers.

Rename/Reorder Apache Solr options in Drupal 6

There are two ways to rename the sorting methods available in the Drupal 6 Apache Solr module. First is the simpler method of changing the translation of the sort title as it is passed through t(). Second is changing the available sorts in the query object in a custom module. If you need to re-order, changing the query object is your only option. The default available sorts are listed in Solr_Base_Query.php:

/**
* Returns a default list of sorts.
*/
protected function default_sorts() {
// The array keys must always be real Solr index fields.

Pages

Subscribe to drupal