Drupal - Alter Views Exposed Filter Form

With hook_form_alter, we can adjust a Views Exposed Filter Form. For example, I had an exposed filter so users could select a particular node reference to filter on. However, the exposed filter was including unpublished nodes, and I needed to get rid of them. So with a little code like this, we can get the job done:

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 - Date Repeat Rule Change Theme of "Repeats every day until"

In my use case, the most common date repeat rule used by authors is the "Repeats every day until". For example, an event spanning from October 2012 through April 2013, read something like this:

Repeats every day until Tue Apr 30 2013 .

Date is an awesome module, but this isn't an awesome way to show a date range. Let's change it to something like this instead:

October 5th, 2012 - April 30th, 2013

Looks better, eh? Charming, indeed.

Drupal - Views hook_views_query_alter Group By

So my story goes like this.... I was building a view which showed a slideshow of content. Due to some views' relationships and complex content types, we were getting duplicate results. No big deal? This happens from time to time, the views module doesn't rule the world, yet. So sometimes we can just adjust the views settings to use DISTINCT, and that will solve our problem, other times not. This was a time where DISTINCT didn't seem to be helping. Usually when this happens, I fall back to my good old friend, hook_views_query_alter().

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 - Use Browser Inspector to Check All Check Boxes on a Form

In Drupal 7, on a content type edit screen, I needed to set the available menus for that content type. Some sites only have a few menus, other sites (particulary ones with lots of Organic Group menus) will have tons of menus to choose from. Clicking each checbox, when there are hundreds of them, over and over again through multiple content types is annoying. "Let's use computers to make our lives easier", said man.

You must disable Drupal 7 administrative pages in the overlay for this to work. You can toggle this on/off on your user edit form.

Drupal - Organic Groups Title Token

I have an Organic Group, and a separate content type that references this Group Audience when creating nodes. I needed to set up Pathauto to automatically create a path like this:


This is the Pathauto token set up that worked for my content type:

Drupal 7 - Theme Image Style Example

If you have an image style specified in Drupal 7 and you'd like to programmatically render an image thumb nail with that image style, try something like this:

$image = theme(
    'path' => 'public://my_example_image.jpg',
    'style_name' => 'my_custom_image_style',
    'alt' => 'Alternate Text',
    'title' => 'Title Text',
print $image;

This would work if you had an image style specified at admin/config/media/image-styles that was called 'my_custom_image_style'.

Drupal - Hide the "Administrative overlay" Checkbox on the User Edit Form

Do you need to hide the 'Use the overlay for administrative pages' checkbox in the 'Administrative overlay' fieldset on the user edit form? Then look no further my child, this can be accomplished with hook_form_alter and an #after_build in your custom module.


Subscribe to RSS - Code