drupal 6.x

Drupal Batch Example

Drupal 7

Here's an example that utilizes the Batch API for Drupal 7:

Drupal - Automatically Set "To date" when "From date" Changes on Popup Calendar

With a date field in Drupal, you can specify the 'To date' be the same as the 'From date' on the field settings. However, selecting a 'From date' on a node form does not automatically update the 'To date' to be the same value, and this is usually annoying for our patrons. Let's use some javascript to detect changes on our 'From date' field(s), then automatically set the 'To date' to the same date as the 'From date'.

Place this code in your custom javascript file:

Drupal - How to Patch a Module

This tutorial describes how to patch a module on your live Drupal site with the code changes you have made on your Drupal development site. If you already have a patch file that needs to be applied to a module, read this article instead: Apply a Patch to a Drupal Module

Otherwise, let us venture forth in quest of more libations!

Drupal Add JavaScript Setting Example

This describes how to add a custom setting to the JavaScript Drupal.settings variable using PHP

Drupal - Render an RSS Feed with PHP

Sometimes you want to show the output of an RSS feed somewhere in your Drupal site. Well with this handy dandy function, we can do just that:

Drupal - Save MySQL Data to Cache then Load it from Cache

Say for example you wanted to grab a list of all of your Drupal Content Types with a Node Count for each Content Type and display it as an html item list. That is easy enough with your own custom module and a bit of MySQL. However, on a site with thousands upon thousands (even millions) of nodes, this operation can be a little expensive on the server.

Drupal - Change the Label for the Body Field on a Node Form

If you want to change the label for the body field on a node form in Drupal 6, you can do it through the Drupal UI or with a little custom code in your module.

Go to admin/content/types then click the 'edit' link next to your content type. Fill out the 'Body field label' text box and then hit 'Save'.

If you'd rather have the body field's label controlled by your module, then try something like this:

Drupal - Get User Counts For Each User Role

Here is how to get a count of users for each user role in a Drupal 6 or 7 site:

SELECT
  COUNT(u.uid) AS user_count,
  r.name AS role 
FROM {users} u 
  INNER JOIN {users_roles} ur ON u.uid = ur.uid
  INNER JOIN {role} r ON ur.rid = r.rid
GROUP BY r.name
ORDER BY user_count DESC;

(Note, this isn't the 'correct' way to do it in Drupal 7, we should really use the new Database API layer, but I'm lazy right now.)

This will give you a table something like this:

Drupal - Get Node Counts For Each Content Type

Here is how to retrieve a count of nodes for each content type in a Drupal 6 or 7 site:

SELECT
  COUNT({node}.nid) AS node_count,
  {node_type}.type
FROM {node}
  INNER JOIN {node_type} ON {node}.type = {node_type}.type
GROUP BY {node_type}.type;

(Note, this isn't the 'correct' way to do this in Drupal 7, we should really use the new Database API Layer, but I'm lazy right now.)

This will give you a table something like this:

Drupal - Provide a Custom HTML String Variable to a Node Type Template File

To provide a custom php variable that contains an html string to your custom node type's template file, use some code sauce similar to this...

(Scroll down to the bottom for a Drupal 7 example)

Drupal 6

First in your theme's template.php file, add this (replace my_theme with the machine name of your theme):

Pages

Subscribe to RSS - drupal 6.x