// 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 {
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
*/
$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)) {
*/
static protected $_session;
+ /**
+ * What to return to the client if in ajax mode (snippet=json)
+ *
+ * @var array
+ */
+ public $ajaxResponse = array();
+
/**
* class constructor
*
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 {
);
}
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;
// 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
_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;
},
<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}
<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}