From 53cfc93c8077f00a60140a398727df1ef352af01 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 1 Aug 2013 20:17:30 +1200 Subject: [PATCH] CRM-13142 if only one membership organization exists then prefill it (unless membership field is optional), add -select- to types as the default --- CRM/Core/BAO/UFGroup.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/CRM/Core/BAO/UFGroup.php b/CRM/Core/BAO/UFGroup.php index 20d4465d4f..e4094f36b2 100644 --- a/CRM/Core/BAO/UFGroup.php +++ b/CRM/Core/BAO/UFGroup.php @@ -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, -- 2.25.1