CRM-15789 - Move htmlAttributes helper to utils class
[civicrm-core.git] / CRM / Utils / Hook.php
index fa932a9b260d7e9d966cad6de5b24c5885279f10..ad995572aff8900657e2f8430b9954a463267e5f 100644 (file)
@@ -23,7 +23,7 @@
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
@@ -32,7 +32,6 @@
  * $Id: $
  *
  */
-
 abstract class CRM_Utils_Hook {
 
   // Allowed values for dashboard hook content placement
@@ -57,7 +56,6 @@ abstract class CRM_Utils_Hook {
    * pattern and cache the instance in this variable
    *
    * @var object
-   * @static
    */
   static private $_singleton = NULL;
 
@@ -111,7 +109,7 @@ abstract class CRM_Utils_Hook {
    *
    * @return mixed
    */
-  abstract function invoke(
+  public abstract function invoke(
     $numParams,
     &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6,
     $fnSuffix
@@ -130,7 +128,7 @@ abstract class CRM_Utils_Hook {
    *
    * @return array|bool
    */
-  function commonInvoke(
+  public function commonInvoke(
     $numParams,
     &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6,
     $fnSuffix, $fnPrefix
@@ -181,7 +179,7 @@ abstract class CRM_Utils_Hook {
    *
    * @return array|bool
    */
-  function runHooks(
+  public function runHooks(
     $civiModules, $fnSuffix, $numParams,
     &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6
   ) {
@@ -231,7 +229,8 @@ abstract class CRM_Utils_Hook {
           }
 
           if (!empty($fResult) &&
-            is_array($fResult)) {
+            is_array($fResult)
+          ) {
             $result = array_merge($result, $fResult);
           }
         }
@@ -249,9 +248,9 @@ abstract class CRM_Utils_Hook {
     foreach ($civiModules as $civiModule) {
       if (!file_exists($civiModule['filePath'])) {
         CRM_Core_Session::setStatus(
-          ts( 'Error loading module file (%1). Please restore the file or disable the module.',
-            array(1 => $civiModule['filePath']) ),
-          ts( 'Warning'), 'error');
+          ts('Error loading module file (%1). Please restore the file or disable the module.',
+            array(1 => $civiModule['filePath'])),
+          ts('Warning'), 'error');
         continue;
       }
       include_once $civiModule['filePath'];
@@ -272,13 +271,15 @@ abstract class CRM_Utils_Hook {
    * @param array $params
    *   The parameters used for object creation / editing.
    *
-   * @return null the return value is ignored
+   * @return null
+   *   the return value is ignored
    */
   public static function pre($op, $objectName, $id, &$params) {
     $event = new \Civi\Core\Event\PreEvent($op, $objectName, $id, $params);
     \Civi\Core\Container::singleton()->get('dispatcher')->dispatch("hook_civicrm_pre", $event);
     \Civi\Core\Container::singleton()->get('dispatcher')->dispatch("hook_civicrm_pre::$objectName", $event);
-    return self::singleton()->invoke(4, $op, $objectName, $id, $params, self::$_nullObject, self::$_nullObject, 'civicrm_pre');
+    return self::singleton()
+      ->invoke(4, $op, $objectName, $id, $params, self::$_nullObject, self::$_nullObject, 'civicrm_pre');
   }
 
   /**
@@ -293,14 +294,16 @@ abstract class CRM_Utils_Hook {
    * @param object $objectRef
    *   The reference to the object if available.
    *
-   * @return mixed             based on op. pre-hooks return a boolean or
+   * @return mixed
+   *   based on op. pre-hooks return a boolean or
    *                           an error message which aborts the operation
    */
   public static function post($op, $objectName, $objectId, &$objectRef) {
     $event = new \Civi\Core\Event\PostEvent($op, $objectName, $objectId, $objectRef);
     \Civi\Core\Container::singleton()->get('dispatcher')->dispatch("hook_civicrm_post", $event);
     \Civi\Core\Container::singleton()->get('dispatcher')->dispatch("hook_civicrm_post::$objectName", $event);
-    return self::singleton()->invoke(4, $op, $objectName, $objectId, $objectRef, self::$_nullObject, self::$_nullObject, 'civicrm_post');
+    return self::singleton()
+      ->invoke(4, $op, $objectName, $objectId, $objectRef, self::$_nullObject, self::$_nullObject, 'civicrm_post');
   }
 
   /**
@@ -320,7 +323,8 @@ abstract class CRM_Utils_Hook {
    * @param array $values
    *   (optional) the values to fill the links.
    *
-   * @return null  the return value is ignored
+   * @return null
+   *   the return value is ignored
    */
   public static function links($op, $objectName, &$objectId, &$links, &$mask = NULL, &$values = array()) {
     return self::singleton()->invoke(6, $op, $objectName, $objectId, $links, $mask, $values, 'civicrm_links');
@@ -334,10 +338,12 @@ abstract class CRM_Utils_Hook {
    * @param CRM_Core_Form $form
    *   Reference to the form object.
    *
-   * @return null the return value is ignored
+   * @return null
+   *   the return value is ignored
    */
   public static function preProcess($formName, &$form) {
-    return self::singleton()->invoke(2, $formName, $form, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_preProcess');
+    return self::singleton()
+      ->invoke(2, $formName, $form, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_preProcess');
   }
 
   /**
@@ -349,10 +355,14 @@ abstract class CRM_Utils_Hook {
    * @param CRM_Core_Form $form
    *   Reference to the form object.
    *
-   * @return null the return value is ignored
+   * @return null
+   *   the return value is ignored
    */
   public static function buildForm($formName, &$form) {
-    return self::singleton()->invoke(2, $formName, $form, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_buildForm');
+    return self::singleton()->invoke(2, $formName, $form,
+      self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
+      'civicrm_buildForm'
+    );
   }
 
   /**
@@ -364,10 +374,14 @@ abstract class CRM_Utils_Hook {
    * @param CRM_Core_Form $form
    *   Reference to the form object.
    *
-   * @return null the return value is ignored
+   * @return null
+   *   the return value is ignored
    */
   public static function postProcess($formName, &$form) {
-    return self::singleton()->invoke(2, $formName, $form, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_postProcess');
+    return self::singleton()->invoke(2, $formName, $form,
+      self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
+      'civicrm_postProcess'
+    );
   }
 
   /**
@@ -380,11 +394,13 @@ abstract class CRM_Utils_Hook {
    * @param array &$files the FILES parameters as sent in by POST
    * @param array &$form the form object
    *
-   * @return mixed             formRule hooks return a boolean or
+   * @return mixed
+   *   formRule hooks return a boolean or
    *                           an array of error messages which display a QF Error
    */
   public static function validate($formName, &$fields, &$files, &$form) {
-    return self::singleton()->invoke(4, $formName, $fields, $files, $form, self::$_nullObject, self::$_nullObject, 'civicrm_validate');
+    return self::singleton()
+      ->invoke(4, $formName, $fields, $files, $form, self::$_nullObject, self::$_nullObject, 'civicrm_validate');
   }
 
   /**
@@ -398,11 +414,13 @@ abstract class CRM_Utils_Hook {
    * @param array &$form the form object
    * @param array &$errors the array of errors.
    *
-   * @return mixed             formRule hooks return a boolean or
+   * @return mixed
+   *   formRule hooks return a boolean or
    *                           an array of error messages which display a QF Error
    */
   public static function validateForm($formName, &$fields, &$files, &$form, &$errors) {
-    return self::singleton()->invoke(5, $formName, $fields, $files, $form, $errors, self::$_nullObject, 'civicrm_validateForm');
+    return self::singleton()
+      ->invoke(5, $formName, $fields, $files, $form, $errors, self::$_nullObject, 'civicrm_validateForm');
   }
 
   /**
@@ -417,10 +435,12 @@ abstract class CRM_Utils_Hook {
    * @param array $params
    *   The parameters that were sent into the calling function.
    *
-   * @return null the return value is ignored
+   * @return null
+   *   the return value is ignored
    */
   public static function custom($op, $groupID, $entityID, &$params) {
-    return self::singleton()->invoke(4, $op, $groupID, $entityID, $params, self::$_nullObject, self::$_nullObject, 'civicrm_custom');
+    return self::singleton()
+      ->invoke(4, $op, $groupID, $entityID, $params, self::$_nullObject, self::$_nullObject, 'civicrm_custom');
   }
 
   /**
@@ -438,10 +458,12 @@ abstract class CRM_Utils_Hook {
    * @param string $where
    *   The currrent where clause.
    *
-   * @return null the return value is ignored
+   * @return null
+   *   the return value is ignored
    */
   public static function aclWhereClause($type, &$tables, &$whereTables, &$contactID, &$where) {
-    return self::singleton()->invoke(5, $type, $tables, $whereTables, $contactID, $where, self::$_nullObject, 'civicrm_aclWhereClause');
+    return self::singleton()
+      ->invoke(5, $type, $tables, $whereTables, $contactID, $where, self::$_nullObject, 'civicrm_aclWhereClause');
   }
 
   /**
@@ -459,10 +481,12 @@ abstract class CRM_Utils_Hook {
    * @param array $currentGroups
    *   The set of objects that are currently permissioned for this contact.
    *
-   * @return null the return value is ignored
+   * @return null
+   *   the return value is ignored
    */
   public static function aclGroup($type, $contactID, $tableName, &$allGroups, &$currentGroups) {
-    return self::singleton()->invoke(5, $type, $contactID, $tableName, $allGroups, $currentGroups, self::$_nullObject, 'civicrm_aclGroup');
+    return self::singleton()
+      ->invoke(5, $type, $contactID, $tableName, $allGroups, $currentGroups, self::$_nullObject, 'civicrm_aclGroup');
   }
 
   /**
@@ -471,7 +495,8 @@ abstract class CRM_Utils_Hook {
    * @param array $files
    *   The current set of files to process.
    *
-   * @return null the return value is ignored
+   * @return null
+   *   the return value is ignored
    */
   public static function xmlMenu(&$files) {
     return self::singleton()->invoke(1, $files,
@@ -486,7 +511,8 @@ abstract class CRM_Utils_Hook {
    * @param array $entities
    *   List of pending entities.
    *
-   * @return null the return value is ignored
+   * @return null
+   *   the return value is ignored
    */
   public static function managed(&$entities) {
     return self::singleton()->invoke(1, $entities,
@@ -504,7 +530,8 @@ abstract class CRM_Utils_Hook {
    *   (output parameter) where should the hook content be displayed.
    * relative to the activity list
    *
-   * @return string the html snippet to include in the dashboard
+   * @return string
+   *   the html snippet to include in the dashboard
    */
   public static function dashboard($contactID, &$contentPlacement = self::DASHBOARD_BELOW) {
     $retval = self::singleton()->invoke(2, $contactID, $contentPlacement,
@@ -545,7 +572,7 @@ abstract class CRM_Utils_Hook {
    * @param CRM_Core_DAO $dao
    *   The item for which we want a reference count.
    * @param array $refCounts
-   *   Each item in the array is an array with keys:.
+   *   Each item in the array is an Array with keys:
    *   - name: string, eg "sql:civicrm_email:contact_id"
    *   - type: string, eg "sql"
    *   - count: int, eg "5" if there are 5 email addresses that refer to $dao
@@ -657,14 +684,15 @@ abstract class CRM_Utils_Hook {
    *
    * @return null
    */
-  static function tokenValues(
+  public static function tokenValues(
     &$details,
     $contactIDs,
     $jobID = NULL,
     $tokens = array(),
     $className = NULL
   ) {
-    return self::singleton()->invoke(5, $details, $contactIDs, $jobID, $tokens, $className, self::$_nullObject, 'civicrm_tokenValues');
+    return self::singleton()
+      ->invoke(5, $details, $contactIDs, $jobID, $tokens, $className, self::$_nullObject, 'civicrm_tokenValues');
   }
 
   /**
@@ -720,7 +748,8 @@ abstract class CRM_Utils_Hook {
    * @return mixed
    */
   public static function unsubscribeGroups($op, $mailingId, $contactId, &$groups, &$baseGroups) {
-    return self::singleton()->invoke(5, $op, $mailingId, $contactId, $groups, $baseGroups, self::$_nullObject, 'civicrm_unsubscribeGroups');
+    return self::singleton()
+      ->invoke(5, $op, $mailingId, $contactId, $groups, $baseGroups, self::$_nullObject, 'civicrm_unsubscribeGroups');
   }
 
   /**
@@ -897,7 +926,7 @@ abstract class CRM_Utils_Hook {
    *
    * @return mixed
    */
-  static function alterPaymentProcessorParams(
+  public static function alterPaymentProcessorParams(
     $paymentObj,
     &$rawParams,
     &$cookedParams
@@ -913,7 +942,7 @@ abstract class CRM_Utils_Hook {
    *
    * @param array $params
    *   Array fields include: groupName, from, toName, toEmail, subject, cc, bcc, text, html,
-   * returnPath, replyTo, headers, attachments (array)
+   *   returnPath, replyTo, headers, attachments (array)
    * @param string $context
    *   The context in which the hook is being invoked, eg 'civimail'.
    *
@@ -957,8 +986,9 @@ abstract class CRM_Utils_Hook {
    * @param int $caseID
    *   The case ID.
    *
-   * @return array of data to be displayed, where the key is a unique id to be used for styling (div id's)
-   * and the value is an array with keys 'label' and 'value' specifying label/value pairs
+   * @return array
+   *   Array of data to be displayed, where the key is a unique id to be used for styling (div id's)
+   *   and the value is an array with keys 'label' and 'value' specifying label/value pairs
    */
   public static function caseSummary($caseID) {
     return self::singleton()->invoke(1, $caseID,
@@ -975,7 +1005,8 @@ abstract class CRM_Utils_Hook {
    * @return mixed
    */
   public static function caseTypes(&$caseTypes) {
-    return self::singleton()->invoke(1, $caseTypes, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_caseTypes');
+    return self::singleton()
+      ->invoke(1, $caseTypes, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_caseTypes');
   }
 
   /**
@@ -1130,7 +1161,8 @@ abstract class CRM_Utils_Hook {
    * @return mixed
    */
   public static function emailProcessor($type, &$params, $mail, &$result, $action = NULL) {
-    return self::singleton()->invoke(5, $type, $params, $mail, $result, $action, self::$_nullObject, 'civicrm_emailProcessor');
+    return self::singleton()
+      ->invoke(5, $type, $params, $mail, $result, $action, self::$_nullObject, 'civicrm_emailProcessor');
   }
 
   /**
@@ -1226,11 +1258,11 @@ abstract class CRM_Utils_Hook {
    *                           activity, campaign, case, contact, contribution, event, grant, membership, and pledge
    * @param array &$headers the list of column headers, an associative array with keys: ( name, sort, order )
    * @param array &$rows the list of values, an associate array with fields that are displayed for that component
-   * @param $selector
+   * @param array $selector
+   *   the selector object. Allows you access to the context of the search
    *
-   * @internal param array $seletor the selector object. Allows you access to the context of the search
-   *
-   * @return void  modify the header and values object to pass the data u need
+   * @return void
+   *   modify the header and values object to pass the data u need
    */
   public static function searchColumns($objectName, &$headers, &$rows, &$selector) {
     return self::singleton()->invoke(4, $objectName, $headers, $rows, $selector,
@@ -1507,9 +1539,9 @@ abstract class CRM_Utils_Hook {
    */
   public static function alterSettingsFolders(&$settingsFolders) {
     return self::singleton()->invoke(1, $settingsFolders,
-        self::$_nullObject, self::$_nullObject,
-        self::$_nullObject, self::$_nullObject, self::$_nullObject,
-        'civicrm_alterSettingsFolders'
+      self::$_nullObject, self::$_nullObject,
+      self::$_nullObject, self::$_nullObject, self::$_nullObject,
+      'civicrm_alterSettingsFolders'
     );
   }
 
@@ -1526,9 +1558,9 @@ abstract class CRM_Utils_Hook {
    */
   public static function alterSettingsMetaData(&$settingsMetaData, $domainID, $profile) {
     return self::singleton()->invoke(3, $settingsMetaData,
-        $domainID, $profile,
-        self::$_nullObject, self::$_nullObject, self::$_nullObject,
-        'civicrm_alterSettingsMetaData'
+      $domainID, $profile,
+      self::$_nullObject, self::$_nullObject, self::$_nullObject,
+      'civicrm_alterSettingsMetaData'
     );
   }
 
@@ -1545,8 +1577,8 @@ abstract class CRM_Utils_Hook {
   public static function apiWrappers(&$wrappers, $apiRequest) {
     return self::singleton()
       ->invoke(2, $wrappers, $apiRequest, self::$_nullObject, self::$_nullObject, self::$_nullObject,
-      self::$_nullObject, 'civicrm_apiWrappers'
-    );
+        self::$_nullObject, 'civicrm_apiWrappers'
+      );
   }
 
   /**
@@ -1587,8 +1619,9 @@ abstract class CRM_Utils_Hook {
    * @param mixed $request
    *   Reserved for future use.
    */
-  static function unhandledException($exception, $request = NULL) {
-    self::singleton()->invoke(2, $exception, $request, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_unhandled_exception');
+  public static function unhandledException($exception, $request = NULL) {
+    self::singleton()
+      ->invoke(2, $exception, $request, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_unhandled_exception');
     // == 4.4 ==
     //$event = new stdClass();
     //$event->exception = $exception;
@@ -1684,10 +1717,12 @@ abstract class CRM_Utils_Hook {
    * @param array $participant
    *   Array of participant values.
    *
-   * @return null the return value is ignored
+   * @return null
+   *   the return value is ignored
    */
   public static function alterBadge($labelName, &$label, &$format, &$participant) {
-    return self::singleton()->invoke(4, $labelName, $label, $format, $participant, self::$_nullObject, self::$_nullObject, 'civicrm_alterBadge');
+    return self::singleton()
+      ->invoke(4, $labelName, $label, $format, $participant, self::$_nullObject, self::$_nullObject, 'civicrm_alterBadge');
   }
 
 
@@ -1736,7 +1771,8 @@ abstract class CRM_Utils_Hook {
    * @return mixed
    */
   public static function queryObjects(&$queryObjects, $type = 'Contact') {
-    return self::singleton()->invoke(2, $queryObjects, $type, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_queryObjects');
+    return self::singleton()
+      ->invoke(2, $queryObjects, $type, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_queryObjects');
   }
 
   /**
@@ -1750,7 +1786,8 @@ abstract class CRM_Utils_Hook {
    * @return mixed
    */
   public static function dashboard_defaults($availableDashlets, &$defaultDashlets) {
-    return self::singleton()->invoke(2, $availableDashlets, $defaultDashlets, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_dashboard_defaults');
+    return self::singleton()
+      ->invoke(2, $availableDashlets, $defaultDashlets, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_dashboard_defaults');
   }
 
   /**
@@ -1765,7 +1802,8 @@ abstract class CRM_Utils_Hook {
    * @return void
    */
   public static function pre_case_merge($mainContactId, $mainCaseId = NULL, $otherContactId = NULL, $otherCaseId = NULL, $changeClient = FALSE) {
-    return self::singleton()->invoke(5, $mainContactId, $mainCaseId, $otherContactId, $otherCaseId, $changeClient, self::$_nullObject, 'civicrm_pre_case_merge');
+    return self::singleton()
+      ->invoke(5, $mainContactId, $mainCaseId, $otherContactId, $otherCaseId, $changeClient, self::$_nullObject, 'civicrm_pre_case_merge');
   }
 
   /**
@@ -1780,7 +1818,8 @@ abstract class CRM_Utils_Hook {
    * @return void
    */
   public static function post_case_merge($mainContactId, $mainCaseId = NULL, $otherContactId = NULL, $otherCaseId = NULL, $changeClient = FALSE) {
-    return self::singleton()->invoke(5, $mainContactId, $mainCaseId, $otherContactId, $otherCaseId, $changeClient, self::$_nullObject, 'civicrm_post_case_merge');
+    return self::singleton()
+      ->invoke(5, $mainContactId, $mainCaseId, $otherContactId, $otherCaseId, $changeClient, self::$_nullObject, 'civicrm_post_case_merge');
   }
 
   /**
@@ -1808,7 +1847,8 @@ abstract class CRM_Utils_Hook {
    *
    * @param array $angularModules
    *   List of modules.
-   * @return null the return value is ignored
+   * @return null
+   *   the return value is ignored
    *
    * @code
    * function mymod_civicrm_angularModules(&$angularModules) {
@@ -1850,10 +1890,10 @@ abstract class CRM_Utils_Hook {
    * @param CRM_Core_DAO $bao
    * @param array $link
    *   To define the link, add these keys to $link:.
-   *  - title: string
-   *  - path: string
-   *  - query: array
-   *  - url: string (used in lieu of "path"/"query")
+   *   - title: string
+   *   - path: string
+   *   - query: array
+   *   - url: string (used in lieu of "path"/"query")
    *      Note: if making "url" CRM_Utils_System::url(), set $htmlize=false
    * @return mixed
    */
@@ -1865,7 +1905,7 @@ abstract class CRM_Utils_Hook {
   }
 
   /**
-   * @param array<CRM_Core_FileSearchInterface> $fileSearches
+   * @param array <CRM_Core_FileSearchInterface> $fileSearches
    * @return mixed
    */
   public static function fileSearches(&$fileSearches) {
@@ -1874,4 +1914,5 @@ abstract class CRM_Utils_Hook {
       'civicrm_fileSearches'
     );
   }
+
 }