I have a view with an exposed filter of organic group id's (ie: gid). I wanted to convert it to be a dropdown with the actual group name. I did so with a form alter. The filter works fine, however I'm having an issue with the filter when trying to view all groups. I tried adding 'ALL' to the dropdown, but that doesn't match a particular gid, so it doesn't work. How can I fix my code to allow content of all groups to show?
/** * Implements hook_form_alter(). */ function tma_views_form_alter(&$form, &$form_state, $form_id) { if ($form['#id'] === 'views-exposed-form-event-list-page') { $form['field_event_type_tid']['#type'] = 'hidden'; } elseif ($form['#id'] === 'views-exposed-form-page-event-calendar-page') { $form['og_group_ref_target_id'] = array( '#type' => 'select', '#options' => tma_views_get_chapters_list(), '#default_value' => 'ALL', ); } } /* * Retrieves an associated array list of all Chapter nodes * return - a list of nids */ function tma_views_get_chapters_list() { $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'node') ->entityCondition('bundle', 'chapter'); $results = $query->execute(); foreach ($results['node'] as $node) { $nids[] = $node->nid; } $nodes = node_load_multiple($nids); $options['ALL'] = 'Select Chapter'; foreach ($nodes as $node) { $options[$node->nid] = $node->title; } return $options; } EDIT: One more thing to note: when no filter is set at all (for the organic group filter), I get a drupal error message on the screen:
An illegal choice has been detected. Please contact the site administrator. I obviously would like to be able to fix that as well.