Solving the "Add a block" redirection bug in Homebox 6.x-3.0-beta5 with OG

Background: The module Homebox OG lets you use Homebox as a replacement for the front page of organic groups. However, when you use this feature and try to add a block, you are redirected afterwards to a generic path such as "homebox-og-frontpage" which was set back when you created the homebox instance. Drupal.org issue page: http://drupal.org/node/1370906

Solution: Although I expect and hope that adding a block will eventually return the new set of blocks through AJAX so that a reload/redirect isn't necessary, this solution will do in the meantime. What you need to do is simply to add a destination to the "Add a block" link when the variable homebox_og_home is set, which means that the feature described above is being used. The link is created in the function homebox_add_link() in homebox.module. I used a modified version of drupal_get_destination for this purpose.

Replace these lines: 

  $options['query']['token'] = homebox_get_token($page);
  return l($text, 'homebox/js/' . $page->name . '/add/' . $module . '/' . $delta, $options);

with these:

  $options['query']['token'] = homebox_get_token($page);
  if(variable_get('homebox_og_home', '') && arg(0)=='node') {
    if (isset($_REQUEST['destination'])) {
      $options['query']['destination'] = urlencode(drupal_get_path_alias($_REQUEST['destination']));
    }
    else {
      // Use $_GET here to retrieve the original path in source form.
      $path = isset($_GET['q']) ? $_GET['q'] : '';
      $query = drupal_query_string_encode($_GET, array('q'));
      if ($query != '') {
        $path .= '?'. $query;
      }
      $options['query']['destination'] = urlencode(drupal_get_path_alias($path));
    }
  }
  return l($text, 'homebox/js/' . $page->name . '/add/' . $module . '/' . $delta, $options);

Patch may be downloaded below.