add select field for XCM profile to extension config page
This commit is contained in:
parent
e460d923f8
commit
e4af927a5b
4 changed files with 72 additions and 56 deletions
|
@ -318,7 +318,7 @@ class TwingleEvent extends Campaign {
|
|||
}
|
||||
try {
|
||||
$contact = civicrm_api3('Contact', 'getorcreate', [
|
||||
'xcm_profile' => 'default',
|
||||
'xcm_profile' => Civi::settings()->get('twinglecampaign_xcm_profile'),
|
||||
'first_name' => $names,
|
||||
'last_name' => $lastname,
|
||||
'email' => $email,
|
||||
|
|
|
@ -7,16 +7,67 @@ use CRM_TwingleCampaign_ExtensionUtil as E;
|
|||
*
|
||||
* @see https://docs.civicrm.org/dev/en/latest/framework/quickform/
|
||||
*/
|
||||
class CRM_TwingleCampaign_Form_Settings extends CRM_Admin_Form_Setting {
|
||||
class CRM_TwingleCampaign_Form_Settings extends CRM_Core_Form {
|
||||
|
||||
protected $_settings = [
|
||||
'twingle_api_key' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
|
||||
'twingle_request_size' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
|
||||
];
|
||||
protected $_settings = NULL;
|
||||
|
||||
public function buildQuickForm() {
|
||||
|
||||
$this->addElement('text',
|
||||
'twingle_api_key',
|
||||
E::ts('Twingle API key')
|
||||
);
|
||||
|
||||
$this->addElement('select',
|
||||
'twinglecampaign_xcm_profile',
|
||||
E::ts('XCM Profile'),
|
||||
$this->getXCMProfiles()
|
||||
);
|
||||
|
||||
$this->addButtons([
|
||||
[
|
||||
'type' => 'submit',
|
||||
'name' => E::ts('Save'),
|
||||
'isDefault' => TRUE,
|
||||
]
|
||||
]);
|
||||
|
||||
parent::buildQuickForm();
|
||||
$this->assign('elementNames', array_keys($this->_settings));
|
||||
}
|
||||
|
||||
public function setDefaultValues() {
|
||||
$defaultValues['twingle_api_key'] =
|
||||
Civi::settings()->get('twingle_api_key');
|
||||
$defaultValues['twinglecampaign_xcm_profile'] =
|
||||
Civi::settings()->get('twinglecampaign_xcm_profile');
|
||||
return $defaultValues;
|
||||
}
|
||||
|
||||
//TODO: validate Twingle API key
|
||||
|
||||
public function postProcess() {
|
||||
$values = $this->exportValues();
|
||||
Civi::settings()->set('twingle_api_key', $values['twingle_api_key']);
|
||||
Civi::settings()->set('twinglecampaign_xcm_profile', $values['twinglecampaign_xcm_profile']);
|
||||
parent::postProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves XCM profiles (if supported). 'default' profile is always
|
||||
* available
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getXCMProfiles() {
|
||||
$xcmProfiles = [];
|
||||
if (!isset($this->_settings['twinglecampaign_xcm_profile'])) {
|
||||
if (method_exists('CRM_Xcm_Configuration', 'getProfileList')) {
|
||||
$profiles = CRM_Xcm_Configuration::getProfileList();
|
||||
foreach ($profiles as $profile_key => $profile_name) {
|
||||
$xcmProfiles[$profile_key] = $profile_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $xcmProfiles;
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'twingle_api_key' => [
|
||||
'name' => 'twingle_api_key',
|
||||
'type' => 'String',
|
||||
'default' => '',
|
||||
'html_type' => 'text',
|
||||
'title' => ts('Twingle API Key'),
|
||||
'is_domain' => 1,
|
||||
'is_contact' => 0,
|
||||
'description' => ts('The key that allows you to call the Twingle API'),
|
||||
`settings_pages` => ['remote' => ['weight' => 10]],
|
||||
],
|
||||
'twingle_request_size' => [
|
||||
'name' => 'twingle_request_size',
|
||||
'type' => 'Integer',
|
||||
'default' => '10',
|
||||
'html_type' => 'text',
|
||||
'title' => ts('Twingle Request Size'),
|
||||
'is_domain' => 1,
|
||||
'is_contact' => 0,
|
||||
'description' => ts('How many items should be requested from the Twingle API at once?'),
|
||||
`settings_pages` => ['remote' => ['weight' => 11]],
|
||||
]
|
||||
];
|
|
@ -1,27 +1,18 @@
|
|||
{* HEADER *}
|
||||
|
||||
<div class="crm-submit-buttons">
|
||||
{include file="CRM/common/formButtons.tpl" location="top"}
|
||||
</div>
|
||||
|
||||
{* FIELD EXAMPLE: OPTION 1 (AUTOMATIC LAYOUT) *}
|
||||
|
||||
{foreach from=$elementNames item=elementName}
|
||||
<div class="crm-section">
|
||||
<div class="label">{$form.$elementName.label}</div>
|
||||
<div class="content">{$form.$elementName.html}</div>
|
||||
<div class="crm-section">
|
||||
<div class="label">{$form.twingle_api_key.label}</div>
|
||||
<div class="content">{$form.twingle_api_key.html}</div>
|
||||
<div class="clear"></div>
|
||||
</div>
|
||||
{/foreach}
|
||||
|
||||
{* FIELD EXAMPLE: OPTION 2 (MANUAL LAYOUT)
|
||||
|
||||
<div>
|
||||
<span>{$form.favorite_color.label}</span>
|
||||
<span>{$form.favorite_color.html}</span>
|
||||
</div>
|
||||
|
||||
{* FOOTER *}
|
||||
<div class="crm-submit-buttons">
|
||||
{include file="CRM/common/formButtons.tpl" location="bottom"}
|
||||
</div>
|
||||
|
||||
<div class="crm-section">
|
||||
<div class="label">{$form.twinglecampaign_xcm_profile.label}</div>
|
||||
<div class="content">{$form.twinglecampaign_xcm_profile.html}</div>
|
||||
<div class="clear"></div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="crm-submit-buttons">
|
||||
{include file="CRM/common/formButtons.tpl" location="bottom"}
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue