Subscribe to group via a webform - pass in group Id
Here's the code I wrote to achieve my goal ...

function mymodule_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  if (strpos($form['#id'], 'webform-client-form-') === 0) {
    if (in_array(
      'default-via-parameter',
      $form['submitted']['mailing_list']['civicrm_1_contact_1_other_group']['#attributes']['class'])
    ) {
      $params = drupal_get_query_parameters();
      if (filter_var($params['gid'], FILTER_VALIDATE_INT, array('options' =&gt; array('min_range' =&gt; 1)))) {
        $form['submitted']['mailing_list']['civicrm_1_contact_1_other_group']['#default_value'] = array($params['gid']);
      }
    }
  }
}


Details ...


Check if it's the right form
Check that I want to allow the default to be overwritten (via a CSS class attached to the field)
Check if the Group Id is supplied as an argument, and is valid
Set the default group to the one supplied


The form can be used without supplying a default to choose any group.
If a default is supplied the user can use this, or even override it