Code

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):

Drupal - Send an E-mail with Custom Module Code

Here is how to send an e-mail with some custom code in your module and by utilizing hook_mail.

Add this example code snippet to your custom module where you would like to have an e-mail sent. For example, maybe you want to send an e-mail about a node when one of your module's forms are submitted.

Drupal - Run Custom Code When a Node's Workflow State Changes

Do you  need to execute some custom code when a node's workflow state changes in Drupal? Yes? Ok.

In your custom module, implement hook_workflow provided by the Workflow module and try something like this:

Drupal - Custom Node Access Example

To setup custom access control in Drupal 6, try something like this...

This example restricts access to everyone on a particular node type, unless the user belongs to a certain role or is the node author. Here is how I did it using hook_node_access_records and hook_node_grants in Drupal 6:

Install gource in Ubuntu 10.10 to visualize a git repo

Download gource 0.37 (0.38 had too many dependencies that appear to be for Ubuntu 11+), extract its contents to your Desktop (or wherever you want), navigate to the directory where the files were extracted, then execute the following terminal commands (checkout the contents of the INSTALL file for more details):

Drupal Services File Create Example with JSON and JQuery

Note, please read about this issue with the Services module before getting started!

UPDATE: There is security issue with the Services module prior to version 3.4. Now all autheticated service calls that use POST, PUT or DELETE need a CSRF token sent along in the request header. This article has NOT been udpated to show those changes! More Information and Workaround(s)

How to 'git rm' all deleted files shown by 'git status'

UPDATE: Thanks to user comments, it turns out the easiest way to do this is with this command:

git add -u

Otherwise, feel free to read the example below for an alternative approach...

===============================

So today I was updating the filefield module in Drupal 6 with Drush (drush up webform), this worked great, as usual. However, my Drupal site is under source control with GIT. So after updating the module and running 'git status' I was presented with a whole bunch of changes. Something like this:

git status

Pages

Subscribe to RSS - Code