Vertical Tabs in render arrays without the Form API in Drupal 7

This is a quick reminder to myself so I don't forget in future. Using Vertical Tabs within forms is fairly easy as it's part of the form API. It was a little harder for me to work out how to do it without using the Form API and using only a render array. The example below shows how to split up content using Vertical Tabs from within a render array:

Getting Facebook FB.Event.subscribe edge.create & edge.remove to work with AJAX

This is a quick reminder to myself so I don't forget in future. I've got a Facebook Like button which I'm reloading using AJAX. Using FB.XFBML.parse(); is required to render XFBML markup on the fly but for some reason both the FB.Event.subscribe('edge.create') and FB.Event.subscribe('edge.remove') were not working after any AJAX event.

Caching Render Arrays in Drupal 7

Render arrays in Drupal are great. If you do not know what a render array is then take a look here, but basically they are arrays that convert into HTML. Render arrays are used to allow other modules to override output before going through the theme layer. What happens though if you have a render array that does a lot of processing? You do not want that array, or part of that array, running each time the page is called.

Here I describe how to cache a render array. Firstly, we need a render array:

Themeing a form into a table with draggable rows in Drupal 7

What I want is a form themed into a table, but I also want to to make the rows draggable so I can change the weight of each form entry. Below is an example of one way this can be done in Drupal 7. As an example, lets say we have an array of the main characters in the BBC series Red Dwarf (not including Holly). We want to display those characters into a form so our user can change those details, if they so wish.

Applying Javascript behaviours once in Drupal

Drupal uses Drupal.behaviours as a replacement for jQuery.ready, but unlike jQuery.ready it can run multiple times during page execution or whenever new DOM elements are inserted into the document. This can be a problem when we want code inside the Behavior to run only once. This is important if you want to create a new instance of an object, for example. What I used to do in the past (for Drupal 6) was add a class to an element to know if the code had been processed or not:

Override the theme list item function to add odd/even zebra striping

I think list items should, or have the option to, include zebra striping. For now, it easy enough to just override theme_item_list() and add that ourselves. Place the following code in your themes template.php file, remembering to change the hook to the name of your theme.

Describe field properties to make custom fields work with Entity Metadata Wrappers

I've created a custom field using the Field API and it works great. However, I want to use the Entity module and its Entity Metadata Wrapper to quickly access Entity data, including data from the new field I've created. If you try to access data from the new field you will see an error message similar to the below.

EntityMetadataWrapperException: Unknown data property field_example_rgb. in EntityStructureWrapper->getPropertyInfo() (line 339 of mysite\sites\all\modules\entity\includes\

Merging two forms together in Drupal

Sometimes in Drupal I want to join together two forms, or in other words, prepend a form to another. For example, let say I have three user forms, all different but all contain the same fields to obtain the user address. One day I want to add an address lookup button in the address part of the form, but I'm forced to do the work on all three forms. What if I could create a separate form for just the address, then merge/add/prepend it to other forms. This way, I just need to change the address form and the changes would be reflected in all three of my forms. Here is an example:

Drupal is Sexy

If Drupal was a woman, you definitely would!

A very good reason NOT to use CloudFlare

Is CloudFlare great? Probably! Should I put up with messages like this when trying to view my site? Definitely not!!