Compare commits
4 commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
6786af0c92 | ||
![]() |
521784d743 | ||
![]() |
76a7a28483 | ||
![]() |
484920f47d |
3 changed files with 25 additions and 21 deletions
|
@ -139,7 +139,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
|
|||
$this->_op = 'create';
|
||||
}
|
||||
|
||||
// Verify that profile with the given name exists.
|
||||
// Verify that a profile with the given name exists.
|
||||
$profile_name = CRM_Utils_Request::retrieve('name', 'String', $this);
|
||||
if (!$this->profile = CRM_Twingle_Profile::getProfile($profile_name)) {
|
||||
$profile_name = NULL;
|
||||
|
@ -174,20 +174,22 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
|
|||
// This will be a 'create' actually.
|
||||
$this->_op = 'create';
|
||||
|
||||
// Retrieve the source profile name.
|
||||
$profile_name = CRM_Utils_Request::retrieve('source_name', 'String', $this);
|
||||
// When copying without a valid profile name, copy the default profile.
|
||||
if (!$profile_name) {
|
||||
$profile_name = 'default';
|
||||
$this->profile = CRM_Twingle_Profile::getProfile($profile_name);
|
||||
}
|
||||
$this->profile = CRM_Twingle_Profile::getProfile($profile_name);
|
||||
|
||||
// Set a new name for this profile.
|
||||
// Propose a new name for this profile.
|
||||
$profile_name = $profile_name . '_copy';
|
||||
$this->profile->setName($profile_name);
|
||||
CRM_Utils_System::setTitle(E::ts('New Twingle API profile'));
|
||||
break;
|
||||
case 'create':
|
||||
// Load factory default profile values.
|
||||
$this->profile = CRM_twingle_Profile::createDefaultProfile($profile_name);
|
||||
$this->profile = CRM_Twingle_Profile::createDefaultProfile($profile_name);
|
||||
CRM_Utils_System::setTitle(E::ts('New Twingle API profile'));
|
||||
break;
|
||||
}
|
||||
|
@ -428,13 +430,6 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
|
|||
parent::buildQuickForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function addRules() {
|
||||
$this->addFormRule(array('CRM_Twingle_Form_Profile', 'validateProfileForm'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the profile form.
|
||||
*
|
||||
|
@ -445,12 +440,21 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
|
|||
* TRUE when the form was successfully validated, or an array of error
|
||||
* messages, keyed by form element name.
|
||||
*/
|
||||
public static function validateProfileForm($values) {
|
||||
$errors = array();
|
||||
public function validate() {
|
||||
$values = $this->exportValues();
|
||||
|
||||
// Validate new profile names.
|
||||
if (
|
||||
isset($values['name'])
|
||||
&& ($values['name'] != $this->profile->getName() || $this->_op != 'edit')
|
||||
&& !empty(CRM_Twingle_Profile::getProfile($values['name']))
|
||||
) {
|
||||
$this->_errors['name'] = E::ts('A profile with this name already exists.');
|
||||
}
|
||||
|
||||
// Restrict profile names to alphanumeric characters and the underscore.
|
||||
if (isset($values['name']) && preg_match("/[^A-Za-z0-9\_]/", $values['name'])) {
|
||||
$errors['name'] = E::ts('Only alphanumeric characters and the underscore (_) are allowed for profile names.');
|
||||
$this->_errors['name'] = E::ts('Only alphanumeric characters and the underscore (_) are allowed for profile names.');
|
||||
}
|
||||
|
||||
// Validate custom field mapping.
|
||||
|
@ -513,10 +517,10 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
|
|||
}
|
||||
}
|
||||
catch (Exception $exception) {
|
||||
$errors['custom_field_mapping'] = $exception->getMessage();
|
||||
$this->_errors['custom_field_mapping'] = $exception->getMessage();
|
||||
}
|
||||
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
return parent::validate();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -543,7 +547,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
|
|||
*/
|
||||
public function postProcess() {
|
||||
$values = $this->exportValues();
|
||||
if (in_array($this->_op, array('create', 'edit'))) {
|
||||
if (in_array($this->_op, array('create', 'edit', 'copy'))) {
|
||||
if (empty($values['name'])) {
|
||||
$values['name'] = 'default';
|
||||
}
|
||||
|
|
6
info.xml
6
info.xml
|
@ -14,9 +14,9 @@
|
|||
<url desc="Support">https://github.com/systopia/de.systopia.twingle/issues</url>
|
||||
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
|
||||
</urls>
|
||||
<releaseDate></releaseDate>
|
||||
<version>1.2-dev</version>
|
||||
<develStage>dev</develStage>
|
||||
<releaseDate>2020-11-10</releaseDate>
|
||||
<version>1.2</version>
|
||||
<develStage>stable</develStage>
|
||||
<compatibility>
|
||||
<ver>5.0</ver>
|
||||
<ver>5.19</ver>
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
</td>
|
||||
<td>
|
||||
<a href="{crmURL p="civicrm/admin/settings/twingle/profile" q="op=edit&name=$profile_name"}" title="{ts domain="de.systopia.twingle" 1=$profile.name}Edit profile %1{/ts}" class="action-item crm-hover-button">{ts domain="de.systopia.twingle"}Edit{/ts}</a>
|
||||
<a href="{crmURL p="civicrm/admin/settings/twingle/profile" q="op=copy&name=$profile_name"}" title="{ts domain="de.systopia.twingle" 1=$profile.name}Copy profile %1{/ts}" class="action-item crm-hover-button">{ts domain="de.systopia.twingle"}Copy{/ts}</a>
|
||||
<a href="{crmURL p="civicrm/admin/settings/twingle/profile" q="op=copy&source_name=$profile_name"}" title="{ts domain="de.systopia.twingle" 1=$profile.name}Copy profile %1{/ts}" class="action-item crm-hover-button">{ts domain="de.systopia.twingle"}Copy{/ts}</a>
|
||||
{if $profile_name == 'default'}
|
||||
<a href="{crmURL p="civicrm/admin/settings/twingle/profile" q="op=delete&name=$profile_name"}" title="{ts domain="de.systopia.twingle" 1=$profile.name}Reset profile %1{/ts}" class="action-item crm-hover-button">{ts domain="de.systopia.twingle"}Reset{/ts}</a>
|
||||
{else}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue