CRM-12865 - Emit hooks for profile forms
authorTim Otten <totten@civicrm.org>
Wed, 10 Jul 2013 04:17:16 +0000 (21:17 -0700)
committerTim Otten <totten@civicrm.org>
Wed, 10 Jul 2013 04:18:35 +0000 (21:18 -0700)
----------------------------------------
* CRM-12865: Define hook/CSS/region names for profile forms
  http://issues.civicrm.org/jira/browse/CRM-12865

CRM/Profile/Form.php
CRM/Profile/Page/Dynamic.php
CRM/Utils/Hook.php

index e96653dbbefe35486ff71d071ad936177be8aad6..e9f8c52d21ba606fbab9fd5f1125193223feeea3 100644 (file)
@@ -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);
     }
index 3847e71b056e20eccb3b338e57638eeab261f204..4d755f287b1a92974a96a84f545f6d6eb4079c34 100644 (file)
@@ -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);
index 1235e8b8ac3574818722ca33bc09e8d273c12053..12d92b1f930409682ee8a21a3c2529ccfcdd05e9 100644 (file)
@@ -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');
+  }
 }