Merge branch 'impove_default_profile_behaviour'
This commit is contained in:
commit
b480d87ed7
4 changed files with 31 additions and 24 deletions
|
@ -237,32 +237,33 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Is this the default profile?
|
||||||
|
$is_default = $this->profile->is_default();
|
||||||
|
|
||||||
// Assign template variables.
|
// Assign template variables.
|
||||||
$this->assign('op', $this->_op);
|
$this->assign('op', $this->_op);
|
||||||
$this->assign('profile_name', $this->profile->getName());
|
$this->assign('profile_name', $profile_name);
|
||||||
$this->assign('is_default', $this->profile->is_default());
|
$this->assign('is_default', $is_default);
|
||||||
|
|
||||||
// Add form elements.
|
// Add form elements.
|
||||||
$is_default = $profile_name == 'default';
|
|
||||||
$this->add(
|
$this->add(
|
||||||
($is_default ? 'static' : 'text'),
|
'text', // field type
|
||||||
'name',
|
'name', // field name
|
||||||
E::ts('Profile name'),
|
E::ts('Profile name'),
|
||||||
[],
|
['class' => 'huge'] + ($is_default && $this->_op == 'edit' ? ['readonly'] : []),
|
||||||
!$is_default
|
!$is_default
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->add(
|
// Do only display selector if this is not the default profile
|
||||||
// field type
|
if (!$is_default) {
|
||||||
'text',
|
$this->add(
|
||||||
// field name
|
'text', // field type
|
||||||
'selector',
|
'selector', // field name
|
||||||
// field label
|
E::ts('Project IDs'), // field label
|
||||||
E::ts('Project IDs'),
|
['class' => 'huge'],
|
||||||
['class' => 'huge'],
|
TRUE // is required
|
||||||
// is required
|
);
|
||||||
TRUE
|
}
|
||||||
);
|
|
||||||
|
|
||||||
$this->add(
|
$this->add(
|
||||||
'select',
|
'select',
|
||||||
|
|
|
@ -25,6 +25,7 @@ class CRM_Twingle_Page_Profiles extends CRM_Core_Page {
|
||||||
foreach (CRM_Twingle_Profile::getProfiles() as $profile_id => $profile) {
|
foreach (CRM_Twingle_Profile::getProfiles() as $profile_id => $profile) {
|
||||||
$profiles[$profile_id]['id'] = $profile_id;
|
$profiles[$profile_id]['id'] = $profile_id;
|
||||||
$profiles[$profile_id]['name'] = $profile->getName();
|
$profiles[$profile_id]['name'] = $profile->getName();
|
||||||
|
$profiles[$profile_id]['is_default'] = $profile->is_default();
|
||||||
foreach (CRM_Twingle_Profile::allowedAttributes() as $attribute) {
|
foreach (CRM_Twingle_Profile::allowedAttributes() as $attribute) {
|
||||||
$profiles[$profile_id][$attribute] = $profile->getAttribute($attribute);
|
$profiles[$profile_id][$attribute] = $profile->getAttribute($attribute);
|
||||||
}
|
}
|
||||||
|
|
|
@ -600,25 +600,28 @@ class CRM_Twingle_Profile {
|
||||||
* @param string $project_id
|
* @param string $project_id
|
||||||
*
|
*
|
||||||
* @return CRM_Twingle_Profile
|
* @return CRM_Twingle_Profile
|
||||||
|
* @throws \CRM_Twingle_Exceptions_ProfileException
|
||||||
|
* @throws \Civi\Core\Exception\DBQueryException
|
||||||
*/
|
*/
|
||||||
public static function getProfileForProject($project_id) {
|
public static function getProfileForProject($project_id) {
|
||||||
$profiles = self::getProfiles();
|
$profiles = self::getProfiles();
|
||||||
|
$default_profile = NULL;
|
||||||
|
|
||||||
foreach ($profiles as $profile) {
|
foreach ($profiles as $profile) {
|
||||||
if ($profile->matches($project_id)) {
|
if ($profile->matches($project_id)) {
|
||||||
return $profile;
|
return $profile;
|
||||||
}
|
}
|
||||||
|
if ($profile->is_default()) {
|
||||||
|
$default_profile = $profile;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If none matches, use the default profile.
|
// If none matches, use the default profile.
|
||||||
if (isset($profiles['default'])) {
|
if (!empty($default_profile)) {
|
||||||
return $profiles['default'];
|
return $default_profile;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new ProfileException(
|
throw new ProfileException('Could not find default profile', ProfileException::ERROR_CODE_DEFAULT_PROFILE_NOT_FOUND);
|
||||||
'Could not find default profile',
|
|
||||||
ProfileException::ERROR_CODE_DEFAULT_PROFILE_NOT_FOUND
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr class="crm-section">
|
<tr class="crm-section">
|
||||||
|
{if not $form.is_default}
|
||||||
<td class="label">{$form.selector.label}
|
<td class="label">{$form.selector.label}
|
||||||
<a
|
<a
|
||||||
onclick='
|
onclick='
|
||||||
|
@ -46,6 +47,7 @@
|
||||||
></a>
|
></a>
|
||||||
</td>
|
</td>
|
||||||
<td class="content">{$form.selector.html}</td>
|
<td class="content">{$form.selector.html}</td>
|
||||||
|
{/if}
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr class="crm-section">
|
<tr class="crm-section">
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue