From 8aac22c8e3af407d73b9c10db94a593f6a045581 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 12 Aug 2013 10:55:15 +1200 Subject: [PATCH] CRM-13201 add hook to alter tpl file in use --- CRM/Contact/Page/View/UserDashBoard.php | 2 +- CRM/Core/Form.php | 10 ++++++++++ CRM/Core/Page.php | 12 +++++++++++- CRM/Core/QuickForm/Action/Display.php | 2 +- CRM/Core/Selector/Controller.php | 2 +- CRM/Financial/BAO/ExportFormat.php | 2 +- CRM/Financial/BAO/ExportFormat/IIF.php | 2 +- CRM/Profile/Page/Dynamic.php | 2 +- CRM/Profile/Page/Listings.php | 2 +- CRM/Report/Form.php | 2 +- CRM/Utils/Hook.php | 17 +++++++++++++++++ 11 files changed, 46 insertions(+), 9 deletions(-) diff --git a/CRM/Contact/Page/View/UserDashBoard.php b/CRM/Contact/Page/View/UserDashBoard.php index f158dc97bf..af6c5d0a08 100644 --- a/CRM/Contact/Page/View/UserDashBoard.php +++ b/CRM/Contact/Page/View/UserDashBoard.php @@ -138,7 +138,7 @@ class CRM_Contact_Page_View_UserDashBoard extends CRM_Core_Page { ) { $userDashboard = $component->getUserDashboardObject(); - $dashboardElements[] = array('templatePath' => $userDashboard->getTemplateFileName(), + $dashboardElements[] = array('templatePath' => $userDashboard->getHookedTemplateFileName(), 'sectionTitle' => $elem['title'], 'weight' => $elem['weight'], ); diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index f0d60b7c76..9a7efa08b0 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -599,6 +599,16 @@ class CRM_Core_Form extends HTML_QuickForm_Page { return $tplname; } + /** + * A wrapper for getTemplateFileName that includes calling the hook to + * prevent us from having to copy & paste the logic of calling the hook + */ + function getHookedTemplateFileName() { + $pageTemplateFile = $this->getTemplateFileName(); + CRM_Utils_Hook::alterTemplateFile(get_class($this), $this, 'page', $pageTemplateFile); + return $pageTemplateFile; + } + /** * Default extra tpl file basically just replaces .tpl with .extra.tpl * i.e. we dont override diff --git a/CRM/Core/Page.php b/CRM/Core/Page.php index 3776ee4cbc..ccc14e12f7 100644 --- a/CRM/Core/Page.php +++ b/CRM/Core/Page.php @@ -155,7 +155,7 @@ class CRM_Core_Page { self::$_template->assign('mode', $this->_mode); - $pageTemplateFile = $this->getTemplateFileName(); + $pageTemplateFile = $this->getHookedTemplateFileName(); self::$_template->assign('tplFile', $pageTemplateFile); // invoke the pagRun hook, CRM-3906 @@ -297,6 +297,16 @@ class CRM_Core_Page { ) . '.tpl'; } + /** + * A wrapper for getTemplateFileName that includes calling the hook to + * prevent us from having to copy & paste the logic of calling the hook + */ + function getHookedTemplateFileName() { + $pageTemplateFile = $this->getTemplateFileName(); + CRM_Utils_Hook::alterTemplateFile(get_class($this), $this, 'page', $pageTemplateFile); + return $pageTemplateFile; + } + /** * Default extra tpl file basically just replaces .tpl with .extra.tpl * i.e. we dont override diff --git a/CRM/Core/QuickForm/Action/Display.php b/CRM/Core/QuickForm/Action/Display.php index 13e13a8ac0..2ba06a06f8 100644 --- a/CRM/Core/QuickForm/Action/Display.php +++ b/CRM/Core/QuickForm/Action/Display.php @@ -132,7 +132,7 @@ class CRM_Core_QuickForm_Action_Display extends CRM_Core_QuickForm_Action { $template->assign('action', $page->getAction()); - $pageTemplateFile = $page->getTemplateFileName(); + $pageTemplateFile = $page->getHookedTemplateFileName(); $template->assign('tplFile', $pageTemplateFile); $content = $template->fetch($controller->getTemplateFile()); diff --git a/CRM/Core/Selector/Controller.php b/CRM/Core/Selector/Controller.php index f84b18626c..6fb24c3464 100644 --- a/CRM/Core/Selector/Controller.php +++ b/CRM/Core/Selector/Controller.php @@ -470,7 +470,7 @@ class CRM_Core_Selector_Controller { return; } - self::$_template->assign('tplFile', $this->_object->getTemplateFileName()); + self::$_template->assign('tplFile', $this->_object->getHookedTemplateFileName()); if ($this->_print) { $content = self::$_template->fetch('CRM/common/print.tpl'); } diff --git a/CRM/Financial/BAO/ExportFormat.php b/CRM/Financial/BAO/ExportFormat.php index 399261954c..23431eb83b 100644 --- a/CRM/Financial/BAO/ExportFormat.php +++ b/CRM/Financial/BAO/ExportFormat.php @@ -73,7 +73,7 @@ class CRM_Financial_BAO_ExportFormat { break; case 'iif': - $tplFile = $this->getTemplateFileName(); + $tplFile = $this->getHookedTemplateFileName((); $out = self::getTemplate()->fetch($tplFile); $fileName = $this->putFile($out); self::createActivityExport($this->_batchIds, $fileName); diff --git a/CRM/Financial/BAO/ExportFormat/IIF.php b/CRM/Financial/BAO/ExportFormat/IIF.php index 9427549c55..06950eaa76 100644 --- a/CRM/Financial/BAO/ExportFormat/IIF.php +++ b/CRM/Financial/BAO/ExportFormat/IIF.php @@ -302,7 +302,7 @@ class CRM_Financial_BAO_ExportFormat_IIF extends CRM_Financial_BAO_ExportFormat return 'iif'; } - function getTemplateFileName() { + function getHookedTemplateFileName(() { return 'CRM/Financial/ExportFormat/IIF.tpl'; } diff --git a/CRM/Profile/Page/Dynamic.php b/CRM/Profile/Page/Dynamic.php index 4d755f287b..eda0ae60d6 100644 --- a/CRM/Profile/Page/Dynamic.php +++ b/CRM/Profile/Page/Dynamic.php @@ -371,7 +371,7 @@ class CRM_Profile_Page_Dynamic extends CRM_Core_Page { // invoke the pagRun hook, CRM-3906 CRM_Utils_Hook::pageRun($this); - return trim($template->fetch($this->getTemplateFileName())); + return trim($template->fetch($this->getHookedTemplateFileName())); } function checkTemplateFileExists($suffix = '') { diff --git a/CRM/Profile/Page/Listings.php b/CRM/Profile/Page/Listings.php index 3f2b4a447a..a7b18e592d 100644 --- a/CRM/Profile/Page/Listings.php +++ b/CRM/Profile/Page/Listings.php @@ -322,7 +322,7 @@ class CRM_Profile_Page_Listings extends CRM_Core_Page { } // also get the search tpl name - $this->assign('searchTPL', $formController->getTemplateFileName()); + $this->assign('searchTPL', $formController->getHookedTemplateFileName()); $this->assign('search', $this->_search); diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index 23b2bd6f42..a0cc7671aa 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -2522,7 +2522,7 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND * Although this function is super-short it is useful to keep separate so it can be over-ridden by report classes. */ function compileContent(){ - $templateFile = $this->getTemplateFileName(); + $templateFile = $this->getHookedTemplateFileName(); return $this->_formValues['report_header'] . CRM_Core_Form::$_template->fetch($templateFile) . $this->_formValues['report_footer']; } diff --git a/CRM/Utils/Hook.php b/CRM/Utils/Hook.php index 85f7e9b859..afd7e2619a 100644 --- a/CRM/Utils/Hook.php +++ b/CRM/Utils/Hook.php @@ -1056,6 +1056,23 @@ abstract class CRM_Utils_Hook { ); } + /** + * This hooks allows alteration of the tpl file used to generate content. It differs from the + * altercontent hook as the content has already been rendered through the tpl at that point + * + * @param $formName previously generated content + * @param $form reference to the form object + * @param $context context of content - page or form + * @param $tplName reference the file name of the tpl + * + * @access public + */ + static function alterTemplateFile($formName, &$form, $context, &$tplName) { + return self::singleton()->invoke(4, $formName, $form, $context, $tplName, + self::$_nullObject, + 'civicrm_alterTemplateFile' + ); + } /** * This hook collects the trigger definition from all components * -- 2.25.1