3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * Redefine the display action.
32 * @copyright CiviCRM LLC (c) 2004-2014
36 class CRM_Core_QuickForm_Action_Display
extends CRM_Core_QuickForm_Action
{
39 * the template to display the required "red" asterick
42 static $_requiredTemplate = NULL;
45 * the template to display error messages inline with the form element
48 static $_errorTemplate = NULL;
53 * @param object $stateMachine reference to state machine object
55 * @return \CRM_Core_QuickForm_Action_Display
58 function __construct(&$stateMachine) {
59 parent
::__construct($stateMachine);
63 * Processes the request.
65 * @param object $page CRM_Core_Form the current form-page
66 * @param string $actionName Current action name, as one Action object can serve multiple actions
71 function perform(&$page, $actionName) {
72 $pageName = $page->getAttribute('id');
74 // If the original action was 'display' and we have values in container then we load them
75 // BTW, if the page was invalid, we should later call validate() to get the errors
76 list(, $oldName) = $page->controller
->getActionName();
77 if ('display' == $oldName) {
78 // If the controller is "modal" we should not allow direct access to a page
79 // unless all previous pages are valid (see also bug #2323)
80 if ($page->controller
->isModal() && !$page->controller
->isValid($page->getAttribute('id'))) {
81 $target = &$page->controller
->getPage($page->controller
->findInvalid());
82 return $target->handle('jump');
84 $data = &$page->controller
->container();
85 if (!empty($data['values'][$pageName])) {
86 $page->loadValues($data['values'][$pageName]);
87 $validate = FALSE === $data['valid'][$pageName];
91 // set "common" defaults and constants
92 $page->controller
->applyDefaults($pageName);
93 $page->isFormBuilt() or $page->buildForm();
94 // if we had errors we should show them again
95 if (isset($validate) && $validate) {
98 //will this work generally as TRUE (i.e., return output)
99 //was default, i.e., FALSE
100 return $this->renderForm($page);
104 * render the page using a custom templating
107 * @param object $page the CRM_Core_Form page
109 * @internal param bool $ret should we echo or return output
114 function renderForm(&$page) {
115 $this->_setRenderTemplates($page);
116 $template = CRM_Core_Smarty
::singleton();
117 $form = $page->toSmarty();
119 // Deprecated - use snippet=6 instead of json=1
120 $json = CRM_Utils_Request
::retrieve('json', 'Boolean', CRM_Core_DAO
::$_nullObject);
122 CRM_Utils_JSON
::output($form);
125 $template->assign('form', $form);
126 $template->assign('isForm', 1);
128 $controller = &$page->controller
;
129 // Stop here if we are in embedded mode. Exception: displaying form errors via ajax
130 if ($controller->getEmbedded() && !(!empty($form['errors']) && $controller->_QFResponseType
== 'json')) {
134 $template->assign('action', $page->getAction());
136 $pageTemplateFile = $page->getHookedTemplateFileName();
137 $template->assign('tplFile', $pageTemplateFile);
139 $content = $template->fetch($controller->getTemplateFile());
141 if (!defined('CIVICRM_UF_HEAD') && $region = CRM_Core_Region
::instance('html-header', FALSE)) {
142 CRM_Utils_System
::addHTMLHead($region->render(''));
144 CRM_Utils_System
::appendTPLFile($pageTemplateFile,
146 $page->overrideExtraTemplateFileName()
149 //its time to call the hook.
150 CRM_Utils_Hook
::alterContent($content, 'form', $pageTemplateFile, $page);
152 $print = $controller->getPrint();
157 $html = CRM_Utils_System
::theme($content, $print);
160 if ($controller->_QFResponseType
== 'json') {
161 $response = array('content' => $html);
162 if (!empty($page->ajaxResponse
)) {
163 $response +
= $page->ajaxResponse
;
165 if (!empty($form['errors'])) {
166 $response['status'] = 'form_error';
167 $response['errors'] = $form['errors'];
169 CRM_Core_Page_AJAX
::returnJsonResponse($response);
173 if ($print == CRM_Core_Smarty
::PRINT_PDF
) {
174 CRM_Utils_PDF_Utils
::html2pdf(
176 "{$page->_name}.pdf",
178 array('paper_size' => 'a3', 'orientation' => 'landscape')
184 CRM_Utils_System
::civiExit();
191 * set the various rendering templates
193 * @param object $page the CRM_Core_Form page
198 function _setRenderTemplates(&$page) {
199 if (self
::$_requiredTemplate === NULL) {
200 $this->initializeTemplates();
203 $renderer = &$page->getRenderer();
205 $renderer->setRequiredTemplate(self
::$_requiredTemplate);
206 $renderer->setErrorTemplate(self
::$_errorTemplate);
210 * initialize the various templates
212 * @internal param object $page the CRM_Core_Form page
217 function initializeTemplates() {
218 if (self
::$_requiredTemplate !== NULL) {
222 $config = CRM_Core_Config
::singleton();
224 $templateDir = $config->templateDir
;
225 if (is_array($templateDir)) {
226 $templateDir = array_pop($templateDir);
229 self
::$_requiredTemplate = file_get_contents($templateDir . '/CRM/Form/label.tpl');
230 self
::$_errorTemplate = file_get_contents($templateDir . '/CRM/Form/error.tpl');