Hi there,

It's my objective to allow the user to select just one group while creating a node within a group. I've written my own module and implemented hook_form_alter(). So I've changed $form['og_nodeapi']['visible']['og_groups']['#multiple'] to FALSE. As soon as I preview or submit a group form I get the error

warning: array_filter() [function.array-filter]: The first argument should be an array in /sites/all/modules/og/og.module on line 1748.

I totally understand what's going on: the POST value of $form['og_nodeapi']['visible']['og_groups'] has to be an array. How can I achieve my goal? Any suggestions?

Comments

bjacob’s picture

This function is very important for me. Is there anyone who could help me, please?

ZoeN’s picture

Seconded - I need this too (instead of the checkboxes in the Groups section, we need a single-select dropdown box).

geek-merlin’s picture

I want to understand this too ;-)
Is there a hook where we can jump in and choose which groups are allowed and which preselected?
I think i remember that og_forum needed some patching of og.module to limit the froups available.

bjacob’s picture

I've found a solution. First of all I've created a new module. There I'm using hook form_alter.

/*
 * Implementation of hook form_alter
 */
function custom_kit_form_alter($form_id, &$form) {
  if ($form_id == 'yourContentType_node_form') {
    $form['og_nodeapi']['visible']['og_groups'] = array(
      '#validate' => array('one_group' => array('og_groups'))
    );
  }
}

function one_group($form_element, $field_name) {
  $og_group = $form_element['#value'];
  if (count($og_group) > 1) {
    form_set_error($field_name, t('Your not allowed to select more than one group.'));
  }
}

Maybe the name of the validation function is not the best and the error message needs some more attention. But it works for me.

If you want to get rid of the checkboxes you can also achieve it with the help of hook form_alter().

$form['og_nodeapi']['visible']['og_groups'] = array(
  '#type' => 'select',
  //preselection
  '#default_value' => ...,
  //size of select (lines)
  '#attributes' => array('size' => ...),
);
moshe weitzman’s picture

Status: Active » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.