CRM-10693 - change PRINT_JSON constant from '6' to 'json' for readability
authorColeman Watts <coleman@civicrm.org>
Fri, 29 Nov 2013 17:54:08 +0000 (09:54 -0800)
committerColeman Watts <coleman@civicrm.org>
Fri, 29 Nov 2013 18:32:17 +0000 (10:32 -0800)
CRM/Core/Controller.php
CRM/Core/Form.php
CRM/Core/Page.php
CRM/Core/Smarty.php
js/Common.js
templates/CRM/Form/body.tpl
templates/CRM/common/snippet.tpl

index 21a4ac461b3686fa30c2a2e9eee793b5096a610c..1c9b09ddd231eef16c40ff299ae6119a81b0b73c 100644 (file)
@@ -240,8 +240,9 @@ class CRM_Core_Controller extends HTML_QuickForm_Controller {
         // also used for the various tabs via TabHeader
         $this->_print = CRM_Core_Smarty::PRINT_NOFORM;
       }
-      elseif ($snippet == 6) {
-        $this->_print = CRM_Core_Smarty::PRINT_NOFORM;
+      // Respond with JSON if in AJAX context (also support legacy value '6')
+      elseif (in_array($snippet, array(CRM_Core_Smarty::PRINT_JSON, 6))) {
+        $this->_print = CRM_Core_Smarty::PRINT_JSON;
         $this->_QFResponseType = 'json';
       }
       else {
index a4a38ff5571ffdfe029f222f96f6ca2d2a5bc7d1..5c84c5027e82b185c63110d08a0f21d387656c30 100644 (file)
@@ -99,7 +99,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
   static protected $_template;
 
   /**
-   * What to return to the client if in ajax mode (snippet=6)
+   * What to return to the client if in ajax mode (snippet=json)
    *
    * @var array
    */
@@ -270,8 +270,8 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
     $this->postProcess();
     $this->postProcessHook();
 
-    // Respond with JSON if in AJAX context
-    if (!empty($_REQUEST['snippet']) && $_REQUEST['snippet'] == CRM_Core_Smarty::PRINT_JSON) {
+    // Respond with JSON if in AJAX context (also support legacy value '6')
+    if (!empty($_REQUEST['snippet']) && in_array($_REQUEST['snippet'], array(CRM_Core_Smarty::PRINT_JSON, 6))) {
       $this->ajaxResponse['buttonName'] = str_replace('_qf_' . $this->getAttribute('id') . '_', '', $this->controller->getButtonName());
       $this->ajaxResponse['action'] = $this->_action;
       if (isset($this->_id) || isset($this->id)) {
index a30dcb3c00401eb8b7d65abb796a15908843e393..4ac7d41c09e3ce249aa238c9424e7bf8b2324127 100644 (file)
@@ -104,6 +104,13 @@ class CRM_Core_Page {
    */
   static protected $_session;
 
+  /**
+   * What to return to the client if in ajax mode (snippet=json)
+   *
+   * @var array
+   */
+  public $ajaxResponse = array();
+
   /**
    * class constructor
    *
@@ -132,7 +139,8 @@ class CRM_Core_Page {
       elseif ($_REQUEST['snippet'] == 5) {
         $this->_print = CRM_Core_Smarty::PRINT_NOFORM;
       }
-      elseif ($_REQUEST['snippet'] == CRM_Core_Smarty::PRINT_JSON) {
+      // Support 'json' as well as legacy value '6'
+      elseif (in_array($_REQUEST['snippet'], array(CRM_Core_Smarty::PRINT_JSON, 6))) {
         $this->_print = CRM_Core_Smarty::PRINT_JSON;
       }
       else {
@@ -189,7 +197,8 @@ class CRM_Core_Page {
         );
       }
       elseif ($this->_print == CRM_Core_Smarty::PRINT_JSON) {
-        CRM_Core_Page_AJAX::returnJsonResponse($content);
+        $this->ajaxResponse['content'] = $content;
+        CRM_Core_Page_AJAX::returnJsonResponse($this->ajaxResponse);
       }
       else {
         echo $content;
index c88b450ee937fe51542cfac61377e2a3740aabab..20f151203285e1da7caf81cf653f35c83a57de6e 100644 (file)
@@ -59,8 +59,10 @@ class CRM_Core_Smarty extends Smarty {
     // this prints a complete form and also generates a qfKey, can we replace this with
     // snippet = 2?? Does the constant _NOFFORM do anything?
     PRINT_QFKEY = 5,
-    // this sends the output back in json
-    PRINT_JSON = 6;
+    // Note: added in v 4.3 with the value '6'
+    // Value changed in 4.5 to 'json' for better readability
+    // @see CRM_Core_Page_AJAX::returnJsonResponse
+    PRINT_JSON = 'json';
 
   /**
    * We only need one instance of this object. So we use the singleton
index 68fdb87bdbdd820fa33df76d912bbc238b0ed28b..073064e55c0515054f60ea16a50913c202d19fbe 100644 (file)
@@ -841,7 +841,7 @@ CRM.validate = CRM.validate || {
     _formatUrl: function(url) {
       // Add snippet argument to url
       if (url.search(/[&?]snippet=/) < 0) {
-        url += (url.indexOf('?') < 0 ? '?' : '&') + 'snippet=6';
+        url += (url.indexOf('?') < 0 ? '?' : '&') + 'snippet=json';
       }
       return url;
     },
index 01ef1b845de2992e91b0a325ae8020a0097fb8e6..927feb22d8172d30549193c8c91052081f2d7145 100644 (file)
@@ -33,7 +33,7 @@
   <div>{$form.hidden}</div>
 {/if}
 
-{if $snippet neq 6 and !$suppressForm and count($form.errors) gt 0}
+{if $snippet neq 'json' and !$suppressForm and count($form.errors) gt 0}
    <div class="messages crm-error">
        <div class="icon red-icon alert-icon"></div>
      {ts}Please correct the following errors in the form fields below:{/ts}
index 5ec59a3807052475d3a415fdaa9746e328ac327c..657b845d3cd382f3ae474a5bfd1b8e92f5d85b3c 100644 (file)
@@ -40,7 +40,7 @@
     <div class="crm-container-snippet" bgColor="white">
 
     {* Display Status messages unless we are outputting json. *}
-    {if $smarty.get.snippet neq 6}
+    {if $smarty.get.snippet neq 'json'}
       {include file="CRM/common/status.tpl"}
     {/if}