From a8387f1974e9ee56c29c704c33a74ceeb66c1bff Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 9 Jul 2013 21:17:16 -0700 Subject: [PATCH] CRM-12865 - Emit hooks for profile forms ---------------------------------------- * CRM-12865: Define hook/CSS/region names for profile forms http://issues.civicrm.org/jira/browse/CRM-12865 --- CRM/Profile/Form.php | 26 +++++++++++++++++-- CRM/Profile/Page/Dynamic.php | 1 + CRM/Utils/Hook.php | 50 ++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 2 deletions(-) diff --git a/CRM/Profile/Form.php b/CRM/Profile/Form.php index e96653dbbe..e9f8c52d21 100644 --- a/CRM/Profile/Form.php +++ b/CRM/Profile/Form.php @@ -66,6 +66,13 @@ class CRM_Profile_Form extends CRM_Core_Form { */ protected $_gid; + /** + * The group id that we are editing + * + * @var string + */ + protected $_ufGroupName = 'unknown'; + /** * The group id that we are passing in url * @@ -257,7 +264,6 @@ class CRM_Profile_Form extends CRM_Core_Form { $this->_isContactActivityProfile = CRM_Core_BAO_UFField::checkContactActivityProfileType($this->_gid); //get values for ufGroupName, captch and dupe update. - $this->assign('ufGroupName', 'unknown'); // override later (if possible) if ($this->_gid) { $dao = new CRM_Core_DAO_UFGroup(); $dao->id = $this->_gid; @@ -265,11 +271,12 @@ class CRM_Profile_Form extends CRM_Core_Form { $this->_isUpdateDupe = $dao->is_update_dupe; $this->_isAddCaptcha = $dao->add_captcha; if (!empty($dao->name)) { - $this->assign('ufGroupName', $dao->name); + $this->_ufGroupName = $dao->name; } } $dao->free(); } + $this->assign('ufGroupName', $this->_ufGroupName); $gids = empty($this->_profileIds) ? $this->_gid : $this->_profileIds; @@ -577,6 +584,18 @@ class CRM_Profile_Form extends CRM_Core_Form { * @access public */ public function buildQuickForm() { + switch ($this->_mode) { + case self::MODE_CREATE: + case self::MODE_EDIT: + case self::MODE_REGISTER: + CRM_Utils_Hook::buildProfile($this->_ufGroupName); + break; + case self::MODE_SEARCH: + CRM_Utils_Hook::searchProfile($this->_ufGroupName); + break; + default: + } + //lets have single status message, CRM-4363 $return = FALSE; $statusMessage = NULL; @@ -872,6 +891,8 @@ class CRM_Profile_Form extends CRM_Core_Form { * @static */ static function formRule($fields, $files, $form) { + CRM_Utils_Hook::validateProfile($form->_ufGroupName); + $errors = array(); // if no values, return if (empty($fields)) { @@ -1070,6 +1091,7 @@ class CRM_Profile_Form extends CRM_Core_Form { return; } } + CRM_Utils_Hook::processProfile($this->_ufGroupName); if (CRM_Utils_Array::value('image_URL', $params)) { CRM_Contact_BAO_Contact::processImageParams($params); } diff --git a/CRM/Profile/Page/Dynamic.php b/CRM/Profile/Page/Dynamic.php index 3847e71b05..4d755f287b 100644 --- a/CRM/Profile/Page/Dynamic.php +++ b/CRM/Profile/Page/Dynamic.php @@ -334,6 +334,7 @@ class CRM_Profile_Page_Dynamic extends CRM_Core_Page { $name = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'name'); $this->assign('ufGroupName', $name); + CRM_Utils_Hook::viewProfile($name); if (strtolower($name) == 'summary_overlay') { $template->assign('overlayProfile', TRUE); diff --git a/CRM/Utils/Hook.php b/CRM/Utils/Hook.php index 1235e8b8ac..12d92b1f93 100644 --- a/CRM/Utils/Hook.php +++ b/CRM/Utils/Hook.php @@ -1235,4 +1235,54 @@ abstract class CRM_Utils_Hook { return self::singleton()->invoke(1, $entityTypes, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_entityTypes' ); } + + /** + * This hook is called while preparing a profile form + * + * @param string $name + * @return void + */ + static function buildProfile($name) { + return self::singleton()->invoke(1, $name, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_buildProfile'); + } + + /** + * This hook is called while validating a profile form submission + * + * @param string $name + * @return void + */ + static function validateProfile($name) { + return self::singleton()->invoke(1, $name, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_validateProfile'); + } + + /** + * This hook is called processing a valid profile form submission + * + * @param string $name + * @return void + */ + static function processProfile($name) { + return self::singleton()->invoke(1, $name, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_processProfile'); + } + + /** + * This hook is called while preparing a read-only profile screen + * + * @param string $name + * @return void + */ + static function viewProfile($name) { + return self::singleton()->invoke(1, $name, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_viewProfile'); + } + + /** + * This hook is called while preparing a list of contacts (based on a profile) + * + * @param string $name + * @return void + */ + static function searchProfile($name) { + return self::singleton()->invoke(1, $name, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_searchProfile'); + } } -- 2.25.1