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] 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 4d66cebf8b..b94e55f14e 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 @@ class CRM_Campaign_Form_Petition extends CRM_Core_Form { } } - // 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 @@ class CRM_Campaign_Form_Petition extends CRM_Core_Form { $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 @@ WHERE $whereClause $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 1839334282..981514751a 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 @@ class CRM_Campaign_Form_Survey extends CRM_Core_Form { $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 80ecd28fc7..8bacc32bdd 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 @@ class CRM_Campaign_Form_Survey_Main extends CRM_Campaign_Form_Survey { 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 @@ class CRM_Campaign_Form_Survey_Main extends CRM_Campaign_Form_Survey { $this->assign('action', $this->_action); $this->assign('surveyId', $this->_surveyId); - // for custom data - $this->assign('entityID', $this->_surveyId); } /** @@ -195,10 +183,8 @@ class CRM_Campaign_Form_Survey_Main extends CRM_Campaign_Form_Survey { $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 ce8ed37f6a..d8969857ce 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 1c6ea28f05..be46a7a505 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 7e2245216d..fc73733dbe 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 84e41a4a3c..0000000000 --- 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 -- 2.25.1