CRM-17614 show survey custom fields in petition and survey UI
authorAndrew Hunt <andrew@agh5.aghstrategies.com>
Mon, 29 Feb 2016 04:43:23 +0000 (23:43 -0500)
committerAndrew Hunt <andrew@agh5.aghstrategies.com>
Mon, 29 Feb 2016 04:43:23 +0000 (23:43 -0500)
----------------------------------------
* CRM-17614: Survey Custom Fields in Petition UI
  https://issues.civicrm.org/jira/browse/CRM-17614

CRM/Campaign/Form/Petition.php
CRM/Campaign/Form/Survey.php
templates/CRM/Campaign/Form/Petition.tpl
templates/CRM/Campaign/Form/Survey/Main.tpl

index 6931a7917fb10d2b607b4f4693769ba6ed16dd37..44fbbe2f3158671729e40b4263be3b386d33c8b5 100644 (file)
@@ -66,8 +66,11 @@ class CRM_Campaign_Form_Petition extends CRM_Core_Form {
 
     // when custom data is included in this page
     if (!empty($_POST['hidden_custom'])) {
-      CRM_Custom_Form_CustomData::preProcess($this);
+      $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);
     }
 
     $session = CRM_Core_Session::singleton();
@@ -318,6 +321,12 @@ 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'
+    );
+
     $surveyId = CRM_Campaign_BAO_Survey::create($params);
 
     // also update the ProfileModule tables
index 7ebc9887f0d1b188b1da8cdb89d10f22902ff21a..2f7f2894e4a8c89c483c8309404fb159b0817476 100644 (file)
@@ -78,6 +78,15 @@ 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', '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);
+    }
+
     // CRM-11480, CRM-11682
     // Preload libraries required by the "Questions" tab
     CRM_UF_Page_ProfileEditor::registerProfileScripts();
index 78501501505887dcabfe49bbf8365eb762e9def9..98f4860510adc2cf9794d5e4d0bedd0677dd1ad5 100644 (file)
         </td>
       </tr>
     </table>
+    <div id="customData"></div>
+    {*include custom data js file*}
+    {include file="CRM/common/customData.tpl"}
+    {literal}
+      <script type="text/javascript">
+        CRM.$(function($) {
+          {/literal}
+          CRM.buildCustomData( 'Survey' );
+          {literal}
+        });
+      </script>
+    {/literal}
   {/if}
   <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
 </div>
index 0856d1858da2a737d6cc7217574ff7c35076ad9d..ed581701c6df9dd2ade67348ae6ebdf2dff1487c 100644 (file)
        </td>
    </tr>
   </table>
+  <div id="customData"></div>
+  {*include custom data js file*}
+  {include file="CRM/common/customData.tpl"}
+  {literal}
+    <script type="text/javascript">
+      CRM.$(function($) {
+        {/literal}
+        CRM.buildCustomData( 'Survey' );
+        {literal}
+      });
+    </script>
+  {/literal}
 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
 </div>