menu_get_object() vs node_load() when getting the node object in Drupal 7

Sometimes, we need to get node information about the current node we are viewing. In Drupal 6, it was always recommended to use menu_get_object() rather than node_load() to get the node object - the node object has all the information about the node. The reason being that during the inital page request to the node, the node object is cached statically in the function menu_get_item(), a function used by menu_get_object(). So the next time we call menu_get_object(), we are in fact getting a cached version of the node object, making it much faster than node_load().

How to debug AJAX in Drupal using FirePHP

I've been using the AJAX Framework in Drupal quite a lot lately, and it's always been fairly steady going, but recently my code has become more and more complicated. I thought it was time to find a good way viewing all those PHP arrays and objects during AJAX calls, so I can see how they are changing and if my code was doing what it was supposed to be doing. FirePHP is what I ended up using and below describes how I got it working with Drupal.

Convert XML Object to Array

Below is a very quick way of converting XML to an Array:

Creating a custom content type & adding fields programmatically in Drupal 7

Although it's very easy to create new content types in the admin section of Drupal, sometimes it's good to do this programmatically to make your brain feel a lot more clever.

Lets pretend we are creating a module called jobs, and in that module we have an install file called jobs.install. The first thing we do is add our hook_install() function that does the following steps:

Eclipse Indigo with PHP PDT & Aptana Studio 3 for Drupal development

I've been using Eclipse for a while now and during that time have slowly compiled a large amount of Drupal related snippets and templates. Unfortunately, one day my computer crashed and all my lovely snippets just disappeared. After locking myself in a dark room and crying for a little while, I thought this would be a good opportunity to upgrade from Eclipse Helios to Indigo. Below are the steps I followed to achieve this using Windows 7.

Validate a date in DD/MM/YYYY format in PHP

I'm British! I like being British, the problem is that a lot of dates are formated MM/DD/YYYY. I spend a lot of time using DD/MM/YYYY format because that's what is expected for British sites. However, what if I want to validate a date in this format? Well it turns out it's pretty easy, below is a function I created to return TRUE if the date is in the valid DD/MM/YYYY format:

Get a thumbnail for a Vimeo video using the video ID

Getting the thumbnail image for a Vimeo video is very easy. Just use the following link, replacing the <video-id> with the id of the video.

Small image;

Get a thumbnail for a Youtube video using the video ID

Getting the thumbnail image for a YouTube video is very easy. Just use the following link, replacing the <video-id> with the id of the video.

Large image:<video-id>/0.jpg

Thumb image:<video-id>/1.jpg

Thumb image (different position):

Find and remove empty or blank lines in Eclipse

If you need to remove empty or blank lines in Eclipse, follow the instructions below:

  • Open the find/replace window (Ctrl + F).
  • Check the Regular Expressions checkbox.
  • In the Find field, enter:

Asthenopia - Eye Strain - from working all the time [solved]

I've been suffering from eye strain for over a year now, I just can't seem to shake it. There are many articles on the internet that include various solutions about what one should do in the event of developing eye strain, this isn't one of them, rather I'm going to just list all the ones I've tried. In my case, the best advise is to simply take time off and let my eyes recover, but everything I like doing involves sitting in front of a monitor.