create new field for TwingleProject url

This commit is contained in:
Marc Michalsky forumZFD 2021-02-10 18:03:08 +01:00
parent 4f87c65663
commit 7168b1a07b
Signed by untrusted user who does not match committer: marc.koch
GPG key ID: 12406554CFB028B9
4 changed files with 19 additions and 13 deletions

View file

@ -134,23 +134,29 @@ class CRM_TwingleCampaign_BAO_TwingleCampaign {
if ($parent_campaign_type_id == $twingle_project_campaign_type_id) { if ($parent_campaign_type_id == $twingle_project_campaign_type_id) {
$this->values['parent_project_id'] = $parent_id; $this->values['parent_project_id'] = $parent_id;
// Get custom field name for twingle_project_page field // Get custom field names for twingle_project_page and
// twingle_project_url fields
$cf_page = ExtensionCache::getInstance() $cf_page = ExtensionCache::getInstance()
->getCustomFieldMapping('twingle_project_page'); ->getCustomFieldMapping('twingle_project_page');
$cf_url = ExtensionCache::getInstance()
->getCustomFieldMapping('twingle_project_url');
// Extract twingle_project_page url from parent_campaign // Try to extract twingle_project_url from parent_campaign
if ($parent_campaign[$cf_page]) { if (!empty($parent_campaign[$cf_url])) {
$this->values['parent_project_url'] = $parent_campaign[$cf_url];
}
// If there is no twingle_project_url use the parent_project_page instead
elseif (!empty($parent_campaign[$cf_page])) {
$this->values['parent_project_url'] = $parent_campaign[$cf_page]; $this->values['parent_project_url'] = $parent_campaign[$cf_page];
} }
// If both values are missing, try a synchronization
// If twingle_project_widget value is missing, try a synchronization
else { else {
$parent_campaign = civicrm_api3('TwingleProject', 'sync', $parent_campaign = civicrm_api3('TwingleProject', 'sync',
['id' => $parent_id]); ['id' => $parent_id]);
// Now try again to extract the twingle_project_widget url // Now try again to extract the twingle_project_page url
if ($parent_campaign[$cf_url]) { if ($parent_campaign[$cf_url]) {
$this->values['parent_project_url'] = $parent_campaign[$cf_url]; $this->values['parent_project_url'] = $parent_campaign[$cf_page];
} }
// If twingle_project_widget value is still missing, show an alert on // If twingle_project_widget value is still missing, show an alert on

View file

@ -140,7 +140,7 @@
"html_type": "TextArea", "html_type": "TextArea",
"text_length": 600, "text_length": 600,
"is_active": 1, "is_active": 1,
"is_view": 0, "is_view": 1,
"weight": 1 "weight": 1
}, },
"twingle_project_widget": { "twingle_project_widget": {

View file

@ -18,8 +18,8 @@ function _civicrm_api3_twingle_form_Create_spec(array &$spec) {
'api.required' => 1, 'api.required' => 1,
'description' => E::ts('ID of the TwingleProject campaign'), 'description' => E::ts('ID of the TwingleProject campaign'),
]; ];
$spec['page'] = [ $spec['url'] = [
'name' => 'page', 'name' => 'url',
'title' => E::ts('TwingleProject Page URL'), 'title' => E::ts('TwingleProject Page URL'),
'type' => CRM_Utils_Type::T_STRING, 'type' => CRM_Utils_Type::T_STRING,
'api.required' => 1, 'api.required' => 1,

View file

@ -49,9 +49,9 @@ function _civicrm_api3_twingle_project_Create_spec(array &$spec) {
'api.required' => 0, 'api.required' => 0,
'description' => E::ts('Financial Target of a Project'), 'description' => E::ts('Financial Target of a Project'),
]; ];
$spec['page'] = [ $spec['url'] = [
'name' => 'page', 'name' => 'url',
'title' => E::ts('Project Page'), 'title' => E::ts('TwingleProject Page URL'),
'type' => CRM_Utils_Type::T_STRING, 'type' => CRM_Utils_Type::T_STRING,
'api.required' => 0, 'api.required' => 0,
'description' => E::ts('The URL of the TwingleProject page'), 'description' => E::ts('The URL of the TwingleProject page'),