all multigroups are exposed in registration forms, impossible to configure multigroup skipping via UI

Comments

mansspams’s picture

Title: cck 3 support » CCK3 Multigroups support
Status: Active » Needs review

sorry I dont know how to make patches and this is still at least one step away from patch...

original code

<?php
  // Hide fields as configured
  foreach (content_profile_get_settings($type, 'registration_hide') as $field_name) {
    if (module_exists('fieldgroup') && ($group_name = _fieldgroup_field_get_group($type, $field_name))) {
      unset($form_add[$group_name][$field_name]);

      if (count(element_children($form_add[$group_name])) == 0) {
        unset($form_add[$group_name]);
      }

    }
    else {
      unset($form_add[$field_name]);
    }
  }
?>

updated code

<?php
  // Hide fields as configured
  foreach (content_profile_get_settings($type, 'registration_hide') as $field_name) {
    if (module_exists('fieldgroup') && ($group_name = _fieldgroup_field_get_group($type, $field_name))) {
      unset($form_add[$group_name][$field_name]);

			if (module_exists('content_multigroup')) { // NEW IF
				// multigroups store field info in '0'
				// @TODO find out if 0 is dynamic value and if it is (most probably) add more code to deal with that
				unset($form_add[$group_name]['0'][$field_name]);

			}

      if (count(element_children($form_add[$group_name])) == 0) {
        unset($form_add[$group_name]);
      }

			// NEW IF
			// == 2 because two children are left: __weight and _remove, they hold some multigroup widget markup
      if (module_exists('content_multigroup') && count(element_children($form_add[$group_name]['0'])) == 2) {
        unset($form_add[$group_name]);
      }

    }
    else {
      unset($form_add[$field_name]);
    }
  }
?>

one issue with this code - someone needs to come up with idea on how to unset fields inside that '0' array since for multiple fields it might be not 0 but 1, 2 or 3, but then again, since this is to display NEW profile form in registration, fields are not filled before and 0 just might work... but then again someone can alter form for some kind of reasons...

so far it works for my application but this feature deserved professional treatment and patch