diff --git a/CRM/Twingle/Form/Profile.php b/CRM/Twingle/Form/Profile.php index 109013f..43307c4 100644 --- a/CRM/Twingle/Form/Profile.php +++ b/CRM/Twingle/Form/Profile.php @@ -237,32 +237,33 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { break; } + // Is this the default profile? + $is_default = $this->profile->is_default(); + // Assign template variables. $this->assign('op', $this->_op); - $this->assign('profile_name', $this->profile->getName()); - $this->assign('is_default', $this->profile->is_default()); + $this->assign('profile_name', $profile_name); + $this->assign('is_default', $is_default); // Add form elements. - $is_default = $profile_name == 'default'; $this->add( - ($is_default ? 'static' : 'text'), - 'name', + 'text', // field type + 'name', // field name E::ts('Profile name'), - [], + ['class' => 'huge'] + ($is_default && $this->_op == 'edit' ? ['readonly'] : []), !$is_default ); - $this->add( - // field type - 'text', - // field name - 'selector', - // field label - E::ts('Project IDs'), - ['class' => 'huge'], - // is required - TRUE - ); + // Do only display selector if this is not the default profile + if (!$is_default) { + $this->add( + 'text', // field type + 'selector', // field name + E::ts('Project IDs'), // field label + ['class' => 'huge'], + TRUE // is required + ); + } $this->add( 'select', diff --git a/CRM/Twingle/Page/Profiles.php b/CRM/Twingle/Page/Profiles.php index 23fcd77..e59de5f 100644 --- a/CRM/Twingle/Page/Profiles.php +++ b/CRM/Twingle/Page/Profiles.php @@ -25,6 +25,7 @@ class CRM_Twingle_Page_Profiles extends CRM_Core_Page { foreach (CRM_Twingle_Profile::getProfiles() as $profile_id => $profile) { $profiles[$profile_id]['id'] = $profile_id; $profiles[$profile_id]['name'] = $profile->getName(); + $profiles[$profile_id]['is_default'] = $profile->is_default(); foreach (CRM_Twingle_Profile::allowedAttributes() as $attribute) { $profiles[$profile_id][$attribute] = $profile->getAttribute($attribute); } diff --git a/CRM/Twingle/Profile.php b/CRM/Twingle/Profile.php index 4e186ad..356e3a0 100644 --- a/CRM/Twingle/Profile.php +++ b/CRM/Twingle/Profile.php @@ -600,25 +600,28 @@ class CRM_Twingle_Profile { * @param string $project_id * * @return CRM_Twingle_Profile + * @throws \CRM_Twingle_Exceptions_ProfileException + * @throws \Civi\Core\Exception\DBQueryException */ public static function getProfileForProject($project_id) { $profiles = self::getProfiles(); + $default_profile = NULL; foreach ($profiles as $profile) { if ($profile->matches($project_id)) { return $profile; } + if ($profile->is_default()) { + $default_profile = $profile; + } } // If none matches, use the default profile. - if (isset($profiles['default'])) { - return $profiles['default']; + if (!empty($default_profile)) { + return $default_profile; } else { - throw new ProfileException( - 'Could not find default profile', - ProfileException::ERROR_CODE_DEFAULT_PROFILE_NOT_FOUND - ); + throw new ProfileException('Could not find default profile', ProfileException::ERROR_CODE_DEFAULT_PROFILE_NOT_FOUND); } } diff --git a/templates/CRM/Twingle/Form/Profile.tpl b/templates/CRM/Twingle/Form/Profile.tpl index 00794ef..df54418 100644 --- a/templates/CRM/Twingle/Form/Profile.tpl +++ b/templates/CRM/Twingle/Form/Profile.tpl @@ -28,6 +28,7 @@ + {if not $form.is_default} {$form.selector.label}