Resize a VirtualBox Guest Image to Increase Harddrive Space

I use VirtualBox to run Windows XP in a virtual machine for the purpose of testing websites in Internet Explorer. My virtual harddisk recently ran out of space and I needed to increase the disk size. Following are the steps I took to do that.

Note that my virtual disk was a vmdk disk and not a vdi, so I first had to convert it to the proper format.

cd my_virtual_disk_directory
VBoxManage clonehd WinXP.vmdk WinXP2.vdi --format vdi

Once I had my disk cloned I then ran the following.

VBoxManage modifyhd WinXP2.vdi --resize 20000

Remove WYSIWYG From Individual Node Edit Forms

Sometimes you have a particular node edit form that you DO NOT way the WYSIWYG editor to appear on. Just drop the following into your site specific custom module.

/*
* remove tinymce wysiwyg from individual textareas.
*/
function utility_form_alter(&$form, &$form_state, $form_id) {
  // get the current url
  $req = request_uri();
  switch ($req) {
    case '/node/25/edit':
      $form['body_field']['format'] = array();
    break;
  }
}

Add a Class Selector to Menu Items

Sometimes you need a class selector in order to more easily target some particular item, such as a menu link.

Drop the following into the template.php file for your theme, clear your caches and all your menu items will have classes like "menu-123".


/**
* Add unique class (mlid) to all menu items.
*/
function YOUR-THEME-NAME_menu_link(array $variables) {
$element = $variables['element'];
$sub_menu = '';

$element['#attributes']['class'][] = 'menu-' . $element['#original_link']['mlid'];

if ($element['#below']) {
$sub_menu = drupal_render($element['#below']);
}

Setting up and Configuring LAMP Development Stack

Following are a few notes for what I needed to do to properly setup my development system.

After restoring all my website DocumentRoots I ran the following commands to fix permissions.

cd /path_to_drupal_installation
sudo chown -R twooten:www-data .
find . -type d -exec chmod u=rwx,g=rx,o= {} \;
find . -type f -exec chmod u=rw,g=r,o= {} \;

To Fix Files:

cd /path_to_drupal_installation/sites
find . -type d -name files -exec chmod ug=rwx,o= '{}' \;
for d in sites/*/files
do
find $d -type d -exec chmod ug=rwx,o= {} \;

Automated installation of the Microsoft IE App Compat virtual machines

The ievms scripts aim to facilitate the automated process of creating virtual machines for testing in multiple versions of IE, using VirtualBox on Linux or OS X. With a single command, you can have IE7, IE8 and IE9 running in separate virtual machines.

https://github.com/xdissent/ievms

Reset Password Via Drush

drush user-password username --password="new_password"

PHP Snippet to Lowercase URL and Redirect

Recently I had to ensure that any URL with an uppercase letter was rewritten. Normally I would do something like this using the .htaccess file and mod_rewrite rules. In order for that to work you have to ensure that the RewriteMap directive is defined in the httpd.conf file, then called from .htaccess. Unfortunately this is a shared server so no access to httpd.conf.

I solved it by adding the following to the beginning of index.php.

if (preg_match('/[A-Z]/', $_SERVER['REQUEST_URI'])) {
$lowercase_file_url = strtolower($_SERVER['REQUEST_URI']);

Filling in the 'To'-date fields with the 'From'-date values using jQuery

Many thanks to Bruno De Bondt for posting this snippet at krimson.be!

When creating nodes in Drupal that have one or more date fields, it can be handy if the values for the 'To' date fields (date & time) are automatically changed to the values that were filled in the 'From' date fields. For example, when events take place on the same day, this can ease data input and make life easier for authors.

Add View Result Count

Put the following into the header or footer to display something like;

Showing 1-4 of 7 results.

<?php
global $pager_page_array, $pager_total_items, $pager_total;
$my_view = views_get_current_view();
$items_per_page = $my_view->pager['items_per_page'];
if ($pager_total[0] == 1) {
echo t('Showing !pager_total_items results', array('!pager_total_items' => $pager_total_items[0]));
} else {
$start = 1 + ($pager_page_array[0] * $items_per_page);
$end = (1 + $pager_page_array[0]) * $items_per_page;
if ($end > $pager_total_items[0]) {