Keeping guest additions up to date in Vagrant

At work we use Vagrant and Virtual Box to keep our development environments consistent across the team.  I recently updated my Virtual Box environment and ended up getting the following message.

[web] The guest additions on this VM do not match the installed version of VirtualBox! In most cases this is fine, but in rare cases it can
cause things such as shared folders to not work properly. If you see shared folder errors, please update the guest additions within the virtual machine and reload your VM.

Guest Additions Version: 4.2.10
VirtualBox Version: 4.3

To fix this issue easily, enter the vbguest plugin for vagrant.  This plugin will detect that your guest additions is a different version to the version that you are running and will upgrade it on boot for you.

To install (assuming you’re running vagrant > 1.1) simply run the following:

vagrant plugin install vagrant-vbguest

Then the next time you boot it should update for you.

Adding classes to the Drupal image_formatter link

So you are using Drupal, and you are outputting an image field from a node to the screen.  You have it set up so that the display is using an image_style to generate a thumbnail, and you are linking to the full size image.  All great, except you want an additional class on the link….

You could override the field template so that it has the field hard coded.  Seems like a bit of hard work, and massively redundant since all you want is a single (or couple of) class(es) on the link (as you’re using a Bootstrap based theme and want to add the thumbnail class)

Preprocess this

Enter theme_preprocess_field(), which is called before any field is rendered, and is your friend.

First thing to do is target the field that you are looking to modify, which is done like this

function THEME-NAME_preprocess_field(&$variables, $hook) {
  if ($variables['element']['#field_name'] == 'field_FIELD-NAME') {
    ...
  }
}

Next thing is to add the class to the link.  The image formatter uses items from the #path array to construct and link, and makes use of the l() function, so we need to bare that in mind when we are adding classes.  The option array with the #path array gets passed into the l function as the options parameter.

The final code looks like this.

function THEME-NAME_preprocess_field(&$variables, $hook) {
  if ($variables['element']['#field_name'] == 'field_FIELD-NAME') {
    foreach ($variables['item'] as &$item) {
      $item['#path']['options']['attributes']['class'] = array(
        'my-class',
      );
    }
  }
}

So there we have it, our class is added to the link, in just a few lines of code, without overriding a template that could easily get stale or hard to maintain.

Easily select Airplay speakers in Mavericks

One of my favourite new features of Mavericks is the ability to direct all audio output from your computer to Airplay enabled speakers.  Meaning at last that I can “throw” Spotify onto my airplay speakers without having to use my iDevice.

So you want to do this – well one way is to go into preferences, open sound, choose output and select in there.  That’s a bit long winded, why not just use this shortcut…

Hold down the option (alt) key while clicking on the speaker icon in the menu bar and it will bring up a list of all devices that you can send your audio output to.

Easily choose Airplay in Mavericks

Select the ones you want and hey presto.

Ordering WordPress taxonomies

I came across an issue the other day when I was working on The Band Company website that required me to order a taxonomy numerically.  The issue was, that even though the items that I was ordering were numbers, they were being ordered alphabetically.  This is what I did to solve the issue.

Continue reading Ordering WordPress taxonomies