Drupal Blog

Drupal 7: Add a custom link in admin menu

Here is some code to be used in a custom module in Drupal 7 in order to create a custom link in the admin menu. This item will show up in the Configuration section and it is particularly useful with the administration menu module.


Drupal: Send file programmatically

Here is a handy, general function for Drupal 6 that takes as an argument a file id and returns the file for downloading.

Drupal Commerce - "Select a product" element: How to change the select list to radio buttons

Here is the code that changes the default select list of "Select a product" element of Drupal Commerce to radio buttons, for a standalone product list.

The following goes in a custom module (tested in Drupal 7).

function MYMODULE_form_alter(&$form, $form_state, $form_id) {
  if (
strpos($form_id, 'commerce_cart_add_to_cart_form_') === 0 && isset($form['product_id'])) {
$form['product_id']['#type'] = "radios";   

MySQL Order by before Group by

In a custom module, I needed to get the latest node that each user published. It is fairly easy to goup by users, but it needs a little something to actually accomplish the sorting.

The following query worked for me, we need to do the sorting in a nested select:

("SELECT * FROM (SELECT * FROM node order by created DESC) as node WHERE nid IN ($placeholders)  GROUP BY uid",10,0,$count_query);

In case the following error comes up:


Create an ubercart order programmatically and update address and products.

One of my latests tasks was to allow a link that would take a user id and a node id as an argument, and automatically create a new order that would have some fields pre populated and ready for further editing. Scope is to use the user id as the client that does the order and to automatically select the product depending on the taxonomy term of the provided node.

In my case I offer a series of links through a custom view template, that uses data from each row results to built the link.

Here is the code for my module, hopefully it will be useful for someone:


Recent Comments

Forward by Dries Buytaert, Founder and Project Lead, Drupal; CTO Acquia.

Order now from:

Managing Expectations Podcast with DrupalEasy

Author Interview http://tinyurl.com/8a8nxno

We provide the most Shiny Drupal Bits & Pixels

Since Drupal 4.x