CRM-13142 if only one membership organization exists then prefill it (unless membersh...
authoreileen <eileen@fuzion.co.nz>
Thu, 1 Aug 2013 08:17:30 +0000 (20:17 +1200)
committereileen <eileen@fuzion.co.nz>
Thu, 1 Aug 2013 08:17:30 +0000 (20:17 +1200)
CRM/Core/BAO/UFGroup.php

index 20d4465d4fd53a76a762d3e67158b8d3020a35e3..e4094f36b2cbf1ded66de4abfb7348288e4d603f 100644 (file)
@@ -1826,8 +1826,19 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
     elseif (CRM_Utils_Array::value('name',$field) == 'membership_type') {
       list($orgInfo, $types) = CRM_Member_BAO_MembershipType::getMembershipTypeInfo();
       $sel = &$form->addElement('hierselect', $name, $title);
-      $select = array( '' => ts('- select -') );
-      $sel->setOptions(array( $select + $orgInfo, $types));
+      $select = array('' => ts('- select -') );
+      if(count($orgInfo) == 1 && $field['is_required']) {
+        // we only have one org - so we should default to it. Not sure about defaulting to first type
+        // as it could be missed - so adding a select
+        // however, possibly that is more similar to the membership form
+        if(count($types[1]) > 1) {
+          $types[1] = $select + $types[1];
+        }
+      }
+      else {
+        $orgInfo = $select + $orgInfo;
+      }
+      $sel->setOptions(array($orgInfo, $types));
     }
     elseif (CRM_Utils_Array::value('name',$field) == 'membership_status') {
       $form->add('select', $name, $title,