Error message

Deprecated function: implode(): Passing glue string after array is deprecated. Swap the parameters in drupal_get_feeds() (line 394 of /home1/tylerfra/public_html/includes/common.inc).

planet drupal

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:

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)

Drupal - File Usage MySQL Queries

Here are a few helpful MySQL queries to retrieve file usage in Drupal (perhaps via IMCE or other file management module).

Total File Space Used by a Particular User

select SUM(filesize) as total_space from {files} where uid = 123;

Total File Space Used by a Particular Directory

select sum(filesize) as total_size from {files} where filepath like '%files\/my_sub_dir\/my_other_sub_dir%';

Drupal - How to Make a Backup Copy of MySQL Database

Here is how you can make a backup copy of your Drupal's MySQL database from a terminal:

mysqldump -u my_drupal_mysql_uer_name -p my_drupal_mysql_database_name > ~/my_drupal_sql_dump.sql

I like to clear all of Drupal's caches before running the dump so there isn't a bunch of cache data in the export.

If you'd prefer to use Drush, check out this article instead: Use Drush to Export/Import a Drupal MySQL Database Dump File

Pages

Subscribe to RSS - planet drupal