Convert Survey/Petition to standard customData template
authorMatthew Wire (MJW Consulting) <mjw@mjwconsult.co.uk>
Mon, 7 Jan 2019 17:50:09 +0000 (17:50 +0000)
committerMatthew Wire (MJW Consulting) <mjw@mjwconsult.co.uk>
Mon, 7 Jan 2019 22:11:51 +0000 (22:11 +0000)
CRM/Campaign/Form/Petition.php
CRM/Campaign/Form/Survey.php
CRM/Campaign/Form/Survey/Main.php
templates/CRM/Campaign/Form/Campaign.tpl
templates/CRM/Campaign/Form/Petition.tpl
templates/CRM/Campaign/Form/Survey/Main.tpl
templates/CRM/Custom/Form/Edit.tpl [deleted file]

index 4d66cebf8b137c249f912cd6ae7199ed61ce86a5..b94e55f14e2d73ec8f5bf375d93e339491d4dcc4 100644 (file)
@@ -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);
 
index 1839334282cb167127e407e99ba217459fabb213..981514751aba2bd8e05f6547e34a678d989d82f0 100644 (file)
@@ -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
index 80ecd28fc7e5b058483289b159dfb0293cb00e10..8bacc32bdd1313de1308e2c4f035412065858986 100644 (file)
@@ -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;
 
index ce8ed37f6a13c1cc377e2c5b970e4daaf0c15b9a..d8969857ceec7f69a7c327502497f3fbd815a1f4 100644 (file)
   </tr>
   </table>
 
-  <div id="customData"></div>
+  {include file="CRM/common/customDataBlock.tpl"}
 
 {/if}
 <div class="crm-submit-buttons">
      {include file="CRM/common/formButtons.tpl" location="bottom"}
 </div>
 </div>
-
-{* include custom data js *}
-{include file="CRM/common/customData.tpl"}
-
-{literal}
-<script type="text/javascript">
-  CRM.$(function($) {
-    {/literal}{if $customDataSubType}
-      CRM.buildCustomData( '{$customDataType}', {$customDataSubType} );
-    {else}
-      CRM.buildCustomData( '{$customDataType}' );
-    {/if}
-    {literal}
-  });
-</script>
-{/literal}
index 1c6ea28f05995801daec8af002002cf14ce590ad..be46a7a505640a343da490d0200bcdb811ab17c5 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}
+    {include file="CRM/common/customDataBlock.tpl"}
   {/if}
   <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
 </div>
index 7e2245216d86221bafdb33d8cea40916c7e00025..fc73733dbe49b099c3dc414e1cab30bb7b377a51 100644 (file)
    </tr>
    <tr class="crm-campaign-form-block-custom_data">
        <td colspan="2">
-           <div id="customData"></div>
+         {include file="CRM/common/customDataBlock.tpl"}
        </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>
 
     });
 </script>
 {/literal}
-{literal}
-  <script type="text/javascript">
-    CRM.$(function($) {
-      {/literal}
-        CRM.buildCustomData( 'Survey' );
-      {literal}
-    });
-  </script>
-{/literal}
diff --git a/templates/CRM/Custom/Form/Edit.tpl b/templates/CRM/Custom/Form/Edit.tpl
deleted file mode 100644 (file)
index 84e41a4..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-{* Edit custom data on Edit entity forms *}
-{* Requires <div id="customData"></div> on the form *}
-{*include custom data js file*}
-{include file="CRM/common/customData.tpl"}
-{literal}
-<script type="text/javascript">
-  CRM.$(function($) {
-    {/literal}
-    CRM.buildCustomData( '{$customDataType}' );
-    {if $customDataSubType}
-    CRM.buildCustomData( '{$customDataType}', {$customDataSubType} );
-    {/if}
-    {literal}
-  });
-</script>
-{/literal}
\ No newline at end of file