This question has been answered by sumoborac. See the first response.
if ($this->modx->getOption('form_customization_use_all_groups',null,false)) {
$userGroups = $this->modx->user->getUserGroups();
} else {
$primaryGroup = $this->modx->user->getPrimaryGroup();
if ($primaryGroup) {
$userGroups = array($primaryGroup->get('id'));
}
}