From 14c67729bdad36e1dbb6f986ba30088390dca9c5 Mon Sep 17 00:00:00 2001 From: "Matthew Wire (MJW Consulting)" Date: Mon, 7 Jan 2019 17:50:09 +0000 Subject: [PATCH 1/9] Convert Survey/Petition to standard customData template --- CRM/Campaign/Form/Petition.php | 34 ++++++++++++--------- CRM/Campaign/Form/Survey.php | 26 +++++++++++----- CRM/Campaign/Form/Survey/Main.php | 22 +++---------- templates/CRM/Campaign/Form/Campaign.tpl | 18 +---------- templates/CRM/Campaign/Form/Petition.tpl | 13 +------- templates/CRM/Campaign/Form/Survey/Main.tpl | 23 +------------- templates/CRM/Custom/Form/Edit.tpl | 16 ---------- 7 files changed, 44 insertions(+), 108 deletions(-) delete mode 100644 templates/CRM/Custom/Form/Edit.tpl diff --git a/CRM/Campaign/Form/Petition.php b/CRM/Campaign/Form/Petition.php index 4d66cebf8b13..b94e55f14e2d 100644 --- a/CRM/Campaign/Form/Petition.php +++ b/CRM/Campaign/Form/Petition.php @@ -42,6 +42,22 @@ class CRM_Campaign_Form_Petition extends CRM_Core_Form { */ public $_surveyId; + /** + * Explicitly declare the entity api name. + */ + public function getDefaultEntity() { + return 'Survey'; + } + + /** + * Get the entity id being edited. + * + * @return int|null + */ + public function getEntityId() { + return $this->_surveyId; + } + public function preProcess() { if (!CRM_Campaign_BAO_Campaign::accessCampaign()) { CRM_Utils_System::permissionDenied(); @@ -64,14 +80,8 @@ public function preProcess() { } } - // when custom data is included in this page - if (!empty($_POST['hidden_custom'])) { - $this->set('type', 'Event'); - $this->set('entityId', $this->_surveyId); - CRM_Custom_Form_CustomData::preProcess($this, NULL, NULL, 1, 'Survey', $this->_surveyId); - CRM_Custom_Form_CustomData::buildQuickForm($this); - CRM_Custom_Form_CustomData::setDefaultValues($this); - } + // Add custom data to form + CRM_Custom_Form_CustomData::addToForm($this); $session = CRM_Core_Session::singleton(); $url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey'); @@ -90,8 +100,6 @@ public function preProcess() { $this->assign('action', $this->_action); $this->assign('surveyId', $this->_surveyId); - // for custom data - $this->assign('entityID', $this->_surveyId); if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::DELETE)) { $this->_surveyId = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE); @@ -321,11 +329,7 @@ public function postProcess() { $params['is_active'] = CRM_Utils_Array::value('is_active', $params, 0); $params['is_default'] = CRM_Utils_Array::value('is_default', $params, 0); - $customFields = CRM_Core_BAO_CustomField::getFields('Survey'); - $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, - $this->_surveyId, - 'Survey' - ); + $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $this->getEntityId(), $this->getDefaultEntity()); $surveyId = CRM_Campaign_BAO_Survey::create($params); diff --git a/CRM/Campaign/Form/Survey.php b/CRM/Campaign/Form/Survey.php index 1839334282cb..981514751aba 100644 --- a/CRM/Campaign/Form/Survey.php +++ b/CRM/Campaign/Form/Survey.php @@ -57,6 +57,22 @@ class CRM_Campaign_Form_Survey extends CRM_Core_Form { */ protected $_surveyTitle; + /** + * Explicitly declare the entity api name. + */ + public function getDefaultEntity() { + return 'Survey'; + } + + /** + * Get the entity id being edited. + * + * @return int|null + */ + public function getEntityId() { + return $this->_surveyId; + } + public function preProcess() { if (!CRM_Campaign_BAO_Campaign::accessCampaign()) { CRM_Utils_System::permissionDenied(); @@ -78,14 +94,8 @@ public function preProcess() { $this->assign('action', $this->_action); $this->assign('surveyId', $this->_surveyId); - // when custom data is included in this page - if (!empty($_POST['hidden_custom'])) { - $this->set('type', 'Survey'); - $this->set('entityId', $this->_surveyId); - CRM_Custom_Form_CustomData::preProcess($this, NULL, NULL, 1, 'Survey', $this->_surveyId); - CRM_Custom_Form_CustomData::buildQuickForm($this); - CRM_Custom_Form_CustomData::setDefaultValues($this); - } + // Add custom data to form + CRM_Custom_Form_CustomData::addToForm($this); // CRM-11480, CRM-11682 // Preload libraries required by the "Questions" tab diff --git a/CRM/Campaign/Form/Survey/Main.php b/CRM/Campaign/Form/Survey/Main.php index 80ecd28fc7e5..8bacc32bdd13 100644 --- a/CRM/Campaign/Form/Survey/Main.php +++ b/CRM/Campaign/Form/Survey/Main.php @@ -50,13 +50,6 @@ class CRM_Campaign_Form_Survey_Main extends CRM_Campaign_Form_Survey { */ protected $_context; - /** - * Explicitly declare the entity api name. - */ - public function getDefaultEntity() { - return 'Survey'; - } - public function preProcess() { parent::preProcess(); @@ -70,11 +63,8 @@ public function preProcess() { CRM_Utils_System::setTitle(ts('Configure Survey') . ' - ' . $this->_surveyTitle); } - // when custom data is included in this page - if (!empty($_POST['hidden_custom'])) { - CRM_Custom_Form_CustomData::preProcess($this); - CRM_Custom_Form_CustomData::buildQuickForm($this); - } + // Add custom data to form + CRM_Custom_Form_CustomData::addToForm($this); if ($this->_name != 'Petition') { $url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey'); @@ -93,8 +83,6 @@ public function preProcess() { $this->assign('action', $this->_action); $this->assign('surveyId', $this->_surveyId); - // for custom data - $this->assign('entityID', $this->_surveyId); } /** @@ -195,10 +183,8 @@ public function postProcess() { $params['is_active'] = CRM_Utils_Array::value('is_active', $params, 0); $params['is_default'] = CRM_Utils_Array::value('is_default', $params, 0); - $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, - $this->_surveyId, - 'Survey' - ); + $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $this->getEntityId(), $this->getDefaultEntity()); + $survey = CRM_Campaign_BAO_Survey::create($params); $this->_surveyId = $survey->id; diff --git a/templates/CRM/Campaign/Form/Campaign.tpl b/templates/CRM/Campaign/Form/Campaign.tpl index ce8ed37f6a13..d8969857ceec 100644 --- a/templates/CRM/Campaign/Form/Campaign.tpl +++ b/templates/CRM/Campaign/Form/Campaign.tpl @@ -95,26 +95,10 @@ -
+ {include file="CRM/common/customDataBlock.tpl"} {/if}
{include file="CRM/common/formButtons.tpl" location="bottom"}
- -{* include custom data js *} -{include file="CRM/common/customData.tpl"} - -{literal} - -{/literal} diff --git a/templates/CRM/Campaign/Form/Petition.tpl b/templates/CRM/Campaign/Form/Petition.tpl index 1c6ea28f0599..be46a7a50564 100644 --- a/templates/CRM/Campaign/Form/Petition.tpl +++ b/templates/CRM/Campaign/Form/Petition.tpl @@ -117,18 +117,7 @@ -
- {*include custom data js file*} - {include file="CRM/common/customData.tpl"} - {literal} - - {/literal} + {include file="CRM/common/customDataBlock.tpl"} {/if}
{include file="CRM/common/formButtons.tpl" location="bottom"}
diff --git a/templates/CRM/Campaign/Form/Survey/Main.tpl b/templates/CRM/Campaign/Form/Survey/Main.tpl index 7e2245216d86..fc73733dbe49 100644 --- a/templates/CRM/Campaign/Form/Survey/Main.tpl +++ b/templates/CRM/Campaign/Form/Survey/Main.tpl @@ -79,22 +79,10 @@ -
+ {include file="CRM/common/customDataBlock.tpl"} -
- {*include custom data js file*} - {include file="CRM/common/customData.tpl"} - {literal} - - {/literal}
{include file="CRM/common/formButtons.tpl" location="bottom"}
@@ -116,12 +104,3 @@ }); {/literal} -{literal} - -{/literal} diff --git a/templates/CRM/Custom/Form/Edit.tpl b/templates/CRM/Custom/Form/Edit.tpl deleted file mode 100644 index 84e41a4a3c40..000000000000 --- a/templates/CRM/Custom/Form/Edit.tpl +++ /dev/null @@ -1,16 +0,0 @@ -{* Edit custom data on Edit entity forms *} -{* Requires
on the form *} -{*include custom data js file*} -{include file="CRM/common/customData.tpl"} -{literal} - -{/literal} \ No newline at end of file From cc3dbc01b3bc87721d4efa9d41bdf3f95332e507 Mon Sep 17 00:00:00 2001 From: "Matthew Wire (MJW Consulting)" Date: Mon, 7 Jan 2019 17:51:24 +0000 Subject: [PATCH 2/9] Convert case/case activity forms to standard customData template --- CRM/Case/Form/Case.php | 46 ++++++++++++++++++++++------ templates/CRM/Case/Form/Activity.tpl | 32 +++++++------------ templates/CRM/Case/Form/Case.tpl | 19 +----------- 3 files changed, 48 insertions(+), 49 deletions(-) diff --git a/CRM/Case/Form/Case.php b/CRM/Case/Form/Case.php index 9e3e2897c35b..d8b2ae47ae5e 100644 --- a/CRM/Case/Form/Case.php +++ b/CRM/Case/Form/Case.php @@ -83,6 +83,36 @@ class CRM_Case_Form_Case extends CRM_Core_Form { */ public $_caseTypeId = NULL; + /** + * Explicitly declare the entity api name. + */ + public function getDefaultEntity() { + return 'Case'; + } + + /** + * Get the entity id being edited. + * + * @return int|null + */ + public function getEntityId() { + return $this->_caseId; + } + + /** + * Get the entity subtype ID being edited + * + * @param $subTypeId + * + * @return int|null + */ + public function getEntitySubTypeId($subTypeId) { + if ($subTypeId) { + return $subTypeId; + } + return $this->_caseTypeId; + } + /** * Build the form object. */ @@ -170,18 +200,15 @@ public function preProcess() { $session = CRM_Core_Session::singleton(); $this->_currentUserId = $session->get('userID'); - //when custom data is included in this page + //Add activity custom data is included in this page CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_activityTypeId, 1, 'Activity'); $className = "CRM_Case_Form_Activity_{$this->_activityTypeFile}"; $className::preProcess($this); $activityGroupTree = $this->_groupTree; - // for case custom fields to populate with defaults - if (!empty($_POST['hidden_custom'])) { - $params = CRM_Utils_Request::exportValues(); - CRM_Custom_Form_CustomData::preProcess($this, NULL, CRM_Utils_Array::value('case_type_id', $params, $this->_caseTypeId), 1, 'Case', $this->_caseId); - CRM_Custom_Form_CustomData::buildQuickForm($this); - } + // Add case custom data to form + $caseTypeId = CRM_Utils_Array::value('case_type_id', CRM_Utils_Request::exportValues(), $this->_caseTypeId); + CRM_Custom_Form_CustomData::addToForm($this, $caseTypeId); // so that grouptree is not populated with case fields, since the grouptree is used // for populating activity custom fields. @@ -227,10 +254,9 @@ public function buildQuickForm() { return; } - //need to assign custom data type and subtype to the template - $this->assign('customDataType', 'Case'); - + // Add the activity custom data to the form CRM_Custom_Form_CustomData::buildQuickForm($this); + // we don't want to show button on top of custom form $this->assign('noPreCustomButton', TRUE); diff --git a/templates/CRM/Case/Form/Activity.tpl b/templates/CRM/Case/Form/Activity.tpl index aa8d78cb5c69..fff7efa83410 100644 --- a/templates/CRM/Case/Form/Activity.tpl +++ b/templates/CRM/Case/Form/Activity.tpl @@ -161,7 +161,7 @@ {/if} -
+ {include file="CRM/common/customDataBlock.tpl"} {if NOT $activityTypeFile} @@ -268,29 +268,19 @@
{include file="CRM/common/formButtons.tpl" location="bottom"}
{if $action eq 1 or $action eq 2} - {*include custom data js file*} - {include file="CRM/common/customData.tpl"} {literal} {/literal} {/if} diff --git a/templates/CRM/Case/Form/Case.tpl b/templates/CRM/Case/Form/Case.tpl index 08d2d004ed55..fb000fbe7938 100644 --- a/templates/CRM/Case/Form/Case.tpl +++ b/templates/CRM/Case/Form/Case.tpl @@ -115,7 +115,7 @@ -
+ {include file="CRM/common/customDataBlock.tpl"} @@ -124,23 +124,6 @@ {/if} -{if $action eq 1} - {*include custom data js file*} - {include file="CRM/common/customData.tpl"} - {literal} - - {/literal} -{/if} -
{include file="CRM/common/formButtons.tpl" location="bottom"}
From 269e6449c530b1cc687fe9d5cb142f5ec6c810aa Mon Sep 17 00:00:00 2001 From: "Matthew Wire (MJW Consulting)" Date: Mon, 7 Jan 2019 17:53:14 +0000 Subject: [PATCH 3/9] Convert activity form to standard customData template --- templates/CRM/Activity/Form/Activity.tpl | 32 +++++++++--------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/templates/CRM/Activity/Form/Activity.tpl b/templates/CRM/Activity/Form/Activity.tpl index ebf945ceaff9..fd2f4a3c75dd 100644 --- a/templates/CRM/Activity/Form/Activity.tpl +++ b/templates/CRM/Activity/Form/Activity.tpl @@ -280,31 +280,23 @@ {if $action eq 1 or $action eq 2 or $context eq 'search' or $context eq 'smog'} - {*include custom data js file*} - {include file="CRM/common/customData.tpl"} {literal} {/literal} + + {include file="CRM/common/customDataBlock.tpl"} {/if} {* end of form block*} From 51a9987b84b13235281e8473f99a5253255ea684 Mon Sep 17 00:00:00 2001 From: "Matthew Wire (MJW Consulting)" Date: Mon, 7 Jan 2019 17:54:22 +0000 Subject: [PATCH 4/9] Convert contribution form to standard customData template --- templates/CRM/Contribute/Form/Contribution.tpl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/templates/CRM/Contribute/Form/Contribution.tpl b/templates/CRM/Contribute/Form/Contribution.tpl index 9496227acb9e..f412e28fe352 100644 --- a/templates/CRM/Contribute/Form/Contribution.tpl +++ b/templates/CRM/Contribute/Form/Contribution.tpl @@ -342,11 +342,9 @@ {if !$payNow} -
+ {include file="CRM/common/customDataBlock.tpl"} {/if} - {include file="CRM/Custom/Form/Edit.tpl"} - {literal} - {/literal} + {include file="CRM/common/customDataBlock.tpl"}
{include file="CRM/common/formButtons.tpl" location="bottom"}
From f7f57fd6454016d14bd4791ea0ed8bd38e4aa125 Mon Sep 17 00:00:00 2001 From: "Matthew Wire (MJW Consulting)" Date: Mon, 7 Jan 2019 17:55:10 +0000 Subject: [PATCH 6/9] Convert Manage Event Info form to standard customData template --- .../CRM/Event/Form/ManageEvent/EventInfo.tpl | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/templates/CRM/Event/Form/ManageEvent/EventInfo.tpl b/templates/CRM/Event/Form/ManageEvent/EventInfo.tpl index c414ca59cbcf..212ecb31e2db 100644 --- a/templates/CRM/Event/Form/ManageEvent/EventInfo.tpl +++ b/templates/CRM/Event/Form/ManageEvent/EventInfo.tpl @@ -146,22 +146,7 @@   -
- {*include custom data js file*} - {include file="CRM/common/customData.tpl"} - {literal} - - {/literal} + {include file="CRM/common/customDataBlock.tpl"}
{include file="CRM/common/formButtons.tpl" location="bottom"}
From c9aa8a77cedcf1484ff00ccebeb441d9903fd61e Mon Sep 17 00:00:00 2001 From: "Matthew Wire (MJW Consulting)" Date: Mon, 7 Jan 2019 17:55:27 +0000 Subject: [PATCH 7/9] Convert Grant form to standard customData template --- templates/CRM/Grant/Form/Grant.tpl | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/templates/CRM/Grant/Form/Grant.tpl b/templates/CRM/Grant/Form/Grant.tpl index 7509533fd864..a3385f6929ed 100644 --- a/templates/CRM/Grant/Form/Grant.tpl +++ b/templates/CRM/Grant/Form/Grant.tpl @@ -97,27 +97,11 @@ -
- {*include custom data js file*} - {include file="CRM/common/customData.tpl"} + {include file="CRM/common/customDataBlock.tpl"} -{literal} - -{/literal} - -
- {include file="CRM/Form/attachment.tpl"} -
+
+ {include file="CRM/Form/attachment.tpl"} +
{/if}
{include file="CRM/common/formButtons.tpl" location="bottom"}
From 62e185a92e6d9e7c0b3cf5385a267140d848f32e Mon Sep 17 00:00:00 2001 From: "Matthew Wire (MJW Consulting)" Date: Mon, 7 Jan 2019 17:55:53 +0000 Subject: [PATCH 8/9] Convert Membership/Membership Renewal forms to standard customData template --- templates/CRM/Member/Form/Membership.tpl | 4 ++-- templates/CRM/Member/Form/MembershipRenewal.tpl | 10 +--------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/templates/CRM/Member/Form/Membership.tpl b/templates/CRM/Member/Form/Membership.tpl index 09de10b7976d..c8d2cd54394d 100644 --- a/templates/CRM/Member/Form/Membership.tpl +++ b/templates/CRM/Member/Form/Membership.tpl @@ -614,7 +614,7 @@ var fname = '#priceset'; if ( !priceSetId ) { cj('#membership_type_id_1').val(0); - CRM.buildCustomData(customDataType, null ); + CRM.buildCustomData(customDataType, null); // hide price set fields. cj( fname ).hide( ); @@ -797,7 +797,7 @@ subTypeNames = null; } - CRM.buildCustomData( customDataType, subTypeNames ); + CRM.buildCustomData(customDataType, subTypeNames); } function enableAmountSection( setContributionType ) { diff --git a/templates/CRM/Member/Form/MembershipRenewal.tpl b/templates/CRM/Member/Form/MembershipRenewal.tpl index 7bc1994cabaf..81013ec4445c 100644 --- a/templates/CRM/Member/Form/MembershipRenewal.tpl +++ b/templates/CRM/Member/Form/MembershipRenewal.tpl @@ -136,9 +136,7 @@ {/if} -
- {*include custom data js file*} - {include file="CRM/common/customData.tpl"} + {include file="CRM/common/customDataBlock.tpl"}
{include file="CRM/common/formButtons.tpl" location="bottom"}
@@ -189,12 +187,6 @@ CRM.$(function($) { $('#membershipOrgType').hide(); $('#changeNumTerms').hide(); - {/literal} - CRM.buildCustomData('{$customDataType}'); - {if $customDataSubType} - CRM.buildCustomData('{$customDataType}', {$customDataSubType}); - {/if} - {literal} }); function checkPayment() { From 2c024dc655533d8f607fd3d39dea3c739b46789b Mon Sep 17 00:00:00 2001 From: "Matthew Wire (MJW Consulting)" Date: Fri, 11 Jan 2019 18:55:07 +0000 Subject: [PATCH 9/9] Don't call getEntitySubTypeId if a subType is not defined --- CRM/Custom/Form/CustomData.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CRM/Custom/Form/CustomData.php b/CRM/Custom/Form/CustomData.php index f4528ceac3e0..532a11ef8181 100644 --- a/CRM/Custom/Form/CustomData.php +++ b/CRM/Custom/Form/CustomData.php @@ -55,7 +55,13 @@ class CRM_Custom_Form_CustomData { public static function addToForm(&$form, $subType = NULL, $subName = NULL, $groupCount = 1) { $entityName = $form->getDefaultEntity(); $entityID = $form->getEntityId(); - $entitySubType = $form->getEntitySubTypeId($subType); + // FIXME: If the form has been converted to use entityFormTrait then getEntitySubTypeId() will exist. + // However, if it is only partially converted (ie. we've switched customdata to use CRM_Custom_Form_CustomData) + // it won't, so we check if we have a subtype before calling the function. + $entitySubType = NULL; + if ($subType) { + $entitySubType = $form->getEntitySubTypeId($subType); + } // when custom data is included in this page if (!empty($_POST['hidden_custom'])) {