userHookClass */ public static function singleton($fresh = FALSE) { if (self::$_singleton == NULL || $fresh) { $config = CRM_Core_Config::singleton(); $class = $config->userHookClass; self::$_singleton = new $class(); } return self::$_singleton; } /** * CRM_Utils_Hook constructor. * * @throws \CRM_Core_Exception */ public function __construct() { $this->cache = CRM_Utils_Cache::create([ 'name' => 'hooks', 'type' => ['ArrayCache'], 'prefetch' => 1, ]); } /** * Invoke a hook through the UF/CMS hook system and the extension-hook * system. * * @param int $numParams * Number of parameters to pass to the hook. * @param mixed $arg1 * Parameter to be passed to the hook. * @param mixed $arg2 * Parameter to be passed to the hook. * @param mixed $arg3 * Parameter to be passed to the hook. * @param mixed $arg4 * Parameter to be passed to the hook. * @param mixed $arg5 * Parameter to be passed to the hook. * @param mixed $arg6 * Parameter to be passed to the hook. * @param string $fnSuffix * Function suffix, this is effectively the hook name. * * @return mixed */ abstract public function invokeViaUF( $numParams, &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6, $fnSuffix ); /** * Invoke a hook. * * This is a transitional adapter. It supports the legacy syntax * but also accepts enough information to support Symfony Event * dispatching. * * @param array|int $names * (Recommended) Array of parameter names, in order. * Using an array is recommended because it enables full * event-broadcasting behaviors. * (Legacy) Number of parameters to pass to the hook. * This is provided for transitional purposes. * @param mixed $arg1 * @param mixed $arg2 * @param mixed $arg3 * @param mixed $arg4 * @param mixed $arg5 * @param mixed $arg6 * @param mixed $fnSuffix * @return mixed */ public function invoke( $names, &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6, $fnSuffix ) { if (!\Civi\Core\Container::isContainerBooted()) { $prebootHooks = ['civicrm_container', 'civicrm_entityTypes']; // 'civicrm_config' ? if (in_array($fnSuffix, $prebootHooks)) { $count = is_array($names) ? count($names) : $names; return $this->invokeViaUF($count, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $fnSuffix); } else { // TODO: Emit a warning, eg // error_log("Warning: hook_$fnSuffix fired prematurely. Dropped."); return; } } if (!is_array($names)) { // We were called with the old contract wherein $names is actually an int. // Symfony dispatcher requires some kind of name. // TODO: Emit a warning, eg // error_log("Warning: hook_$fnSuffix does not give names for its parameters. It will present odd names to any Symfony event listeners."); $compatNames = ['arg1', 'arg2', 'arg3', 'arg4', 'arg5', 'arg6']; $names = array_slice($compatNames, 0, (int) $names); } $event = \Civi\Core\Event\GenericHookEvent::createOrdered( $names, array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6) ); \Civi::dispatcher()->dispatch('hook_' . $fnSuffix, $event); return $event->getReturnValues(); } /** * @param array $numParams * @param $arg1 * @param $arg2 * @param $arg3 * @param $arg4 * @param $arg5 * @param $arg6 * @param $fnSuffix * @param $fnPrefix * * @return array|bool */ public function commonInvoke( $numParams, &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6, $fnSuffix, $fnPrefix ) { $this->commonBuildModuleList($fnPrefix); return $this->runHooks($this->commonCiviModules, $fnSuffix, $numParams, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6 ); } /** * Build the list of modules to be processed for hooks. * * @param string $fnPrefix */ public function commonBuildModuleList($fnPrefix) { if (!$this->commonIncluded) { // include external file $this->commonIncluded = TRUE; $config = CRM_Core_Config::singleton(); if (!empty($config->customPHPPathDir)) { $civicrmHooksFile = CRM_Utils_File::addTrailingSlash($config->customPHPPathDir) . 'civicrmHooks.php'; if (file_exists($civicrmHooksFile)) { @include_once $civicrmHooksFile; } } if (!empty($fnPrefix)) { $this->commonCiviModules[$fnPrefix] = $fnPrefix; } $this->requireCiviModules($this->commonCiviModules); } } /** * Run hooks. * * @param array $civiModules * @param string $fnSuffix * @param int $numParams * @param mixed $arg1 * @param mixed $arg2 * @param mixed $arg3 * @param mixed $arg4 * @param mixed $arg5 * @param mixed $arg6 * * @return array|bool * @throws \CRM_Core_Exception */ public function runHooks( $civiModules, $fnSuffix, $numParams, &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6 ) { // $civiModules is *not* passed by reference because runHooks // must be reentrant. PHP is finicky about running // multiple loops over the same variable. The circumstances // to reproduce the issue are pretty intricate. $result = []; $fnNames = $this->cache->get($fnSuffix); if (!is_array($fnNames)) { $fnNames = []; if ($civiModules !== NULL) { foreach ($civiModules as $module) { $fnName = "{$module}_{$fnSuffix}"; if (function_exists($fnName)) { $fnNames[] = $fnName; } } $this->cache->set($fnSuffix, $fnNames); } } foreach ($fnNames as $fnName) { $fResult = []; switch ($numParams) { case 0: $fResult = $fnName(); break; case 1: $fResult = $fnName($arg1); break; case 2: $fResult = $fnName($arg1, $arg2); break; case 3: $fResult = $fnName($arg1, $arg2, $arg3); break; case 4: $fResult = $fnName($arg1, $arg2, $arg3, $arg4); break; case 5: $fResult = $fnName($arg1, $arg2, $arg3, $arg4, $arg5); break; case 6: $fResult = $fnName($arg1, $arg2, $arg3, $arg4, $arg5, $arg6); break; default: throw new CRM_Core_Exception(ts('Invalid hook invocation')); } if (!empty($fResult) && is_array($fResult) ) { $result = array_merge($result, $fResult); } } return empty($result) ? TRUE : $result; } /** * @param $moduleList */ public function requireCiviModules(&$moduleList) { $civiModules = CRM_Core_PseudoConstant::getModuleExtensions(); 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.', [1 => $civiModule['filePath']]), ts('Warning'), 'error'); continue; } include_once $civiModule['filePath']; $moduleList[$civiModule['prefix']] = $civiModule['prefix']; } } /** * This hook is called before a db write on some core objects. * This hook does not allow the abort of the operation * * @param string $op * The type of operation being performed. * @param string $objectName * The name of the object. * @param int $id * The object id if available. * @param array $params * The parameters used for object creation / editing. * * @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::dispatcher()->dispatch('hook_civicrm_pre', $event); return $event->getReturnValues(); } /** * This hook is called after a db write on some core objects. * * @param string $op * The type of operation being performed. * @param string $objectName * The name of the object. * @param int $objectId * The unique identifier for the object. * @param object $objectRef * The reference to the object if available. * * @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 = NULL) { $event = new \Civi\Core\Event\PostEvent($op, $objectName, $objectId, $objectRef); \Civi::dispatcher()->dispatch('hook_civicrm_post', $event); return $event->getReturnValues(); } /** * This hook is equivalent to post(), except that it is guaranteed to run * outside of any SQL transaction. The objectRef is not modifiable. * * This hook is defined for two cases: * * 1. If the original action runs within a transaction, then the hook fires * after the transaction commits. * 2. If the original action runs outside a transaction, then the data was * committed immediately, and we can run the hook immediately. * * @param string $op * The type of operation being performed. * @param string $objectName * The name of the object. * @param int $objectId * The unique identifier for the object. * @param object $objectRef * The reference to the object if available. * * @return mixed * based on op. pre-hooks return a boolean or * an error message which aborts the operation */ public static function postCommit($op, $objectName, $objectId, $objectRef = NULL) { $event = new \Civi\Core\Event\PostEvent($op, $objectName, $objectId, $objectRef); \Civi::dispatcher()->dispatch('hook_civicrm_postCommit', $event); return $event->getReturnValues(); } /** * This hook retrieves links from other modules and injects it into. * the view contact tabs * * @param string $op * The type of operation being performed. * @param string $objectName * The name of the object. * @param int $objectId * The unique identifier for the object. * @param array $links * (optional) the links array (introduced in v3.2). * @param int $mask * (optional) the bitmask to show/hide links. * @param array $values * (optional) the values to fill the links. * * @return null * the return value is ignored */ public static function links($op, $objectName, &$objectId, &$links, &$mask = NULL, &$values = []) { return self::singleton()->invoke(['op', 'objectName', 'objectId', 'links', 'mask', 'values'], $op, $objectName, $objectId, $links, $mask, $values, 'civicrm_links'); } /** * This hook is invoked during the CiviCRM form preProcess phase. * * @param string $formName * The name of the form. * @param CRM_Core_Form $form * Reference to the form object. * * @return null * the return value is ignored */ public static function preProcess($formName, &$form) { return self::singleton() ->invoke(['formName', 'form'], $formName, $form, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_preProcess'); } /** * This hook is invoked when building a CiviCRM form. This hook should also * be used to set the default values of a form element * * @param string $formName * The name of the form. * @param CRM_Core_Form $form * Reference to the form object. * * @return null * the return value is ignored */ public static function buildForm($formName, &$form) { return self::singleton()->invoke(['formName', 'form'], $formName, $form, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_buildForm' ); } /** * This hook is invoked when a CiviCRM form is submitted. If the module has injected * any form elements, this hook should save the values in the database * * @param string $formName * The name of the form. * @param CRM_Core_Form $form * Reference to the form object. * * @return null * the return value is ignored */ public static function postProcess($formName, &$form) { return self::singleton()->invoke(['formName', 'form'], $formName, $form, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_postProcess' ); } /** * This hook is invoked during all CiviCRM form validation. An array of errors * detected is returned. Else we assume validation succeeded. * * @param string $formName * The name of the form. * @param array &$fields the POST parameters as filtered by QF * @param array &$files the FILES parameters as sent in by POST * @param array &$form the form object * @param array &$errors the array of errors. * * @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(['formName', 'fields', 'files', 'form', 'errors'], $formName, $fields, $files, $form, $errors, self::$_nullObject, 'civicrm_validateForm'); } /** * This hook is called after a db write on a custom table. * * @param string $op * The type of operation being performed. * @param string $groupID * The custom group ID. * @param object $entityID * The entityID of the row in the custom table. * @param array $params * The parameters that were sent into the calling function. * * @return null * the return value is ignored */ public static function custom($op, $groupID, $entityID, &$params) { return self::singleton() ->invoke(['op', 'groupID', 'entityID', 'params'], $op, $groupID, $entityID, $params, self::$_nullObject, self::$_nullObject, 'civicrm_custom'); } /** * This hook is called when composing the ACL where clause to restrict * visibility of contacts to the logged in user * * @param int $type * The type of permission needed. * @param array $tables * (reference ) add the tables that are needed for the select clause. * @param array $whereTables * (reference ) add the tables that are needed for the where clause. * @param int $contactID * The contactID for whom the check is made. * @param string $where * The currrent where clause. * * @return null * the return value is ignored */ public static function aclWhereClause($type, &$tables, &$whereTables, &$contactID, &$where) { return self::singleton() ->invoke(['type', 'tables', 'whereTables', 'contactID', 'where'], $type, $tables, $whereTables, $contactID, $where, self::$_nullObject, 'civicrm_aclWhereClause'); } /** * This hook is called when composing the ACL where clause to restrict * visibility of contacts to the logged in user * * @param int $type * The type of permission needed. * @param int $contactID * The contactID for whom the check is made. * @param string $tableName * The tableName which is being permissioned. * @param array $allGroups * The set of all the objects for the above table. * @param array $currentGroups * The set of objects that are currently permissioned for this contact. * * @return null * the return value is ignored */ public static function aclGroup($type, $contactID, $tableName, &$allGroups, &$currentGroups) { return self::singleton() ->invoke(['type', 'contactID', 'tableName', 'allGroups', 'currentGroups'], $type, $contactID, $tableName, $allGroups, $currentGroups, self::$_nullObject, 'civicrm_aclGroup'); } /** * @param string|CRM_Core_DAO $entity * @param array $clauses * @return mixed */ public static function selectWhereClause($entity, &$clauses) { $entityName = is_object($entity) ? _civicrm_api_get_entity_name_from_dao($entity) : $entity; return self::singleton()->invoke(['entity', 'clauses'], $entityName, $clauses, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_selectWhereClause' ); } /** * This hook is called when building the menu table. * * @param array $files * The current set of files to process. * * @return null * the return value is ignored */ public static function xmlMenu(&$files) { return self::singleton()->invoke(['files'], $files, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_xmlMenu' ); } /** * (Experimental) This hook is called when build the menu table. * * @param array $items * List of records to include in menu table. * @return null * the return value is ignored */ public static function alterMenu(&$items) { return self::singleton()->invoke(['items'], $items, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_alterMenu' ); } /** * A theme is a set of CSS files which are loaded on CiviCRM pages. To register a new * theme, add it to the $themes array. Use these properties: * * - ext: string (required) * The full name of the extension which defines the theme. * Ex: "org.civicrm.themes.greenwich". * - title: string (required) * Visible title. * - help: string (optional) * Description of the theme's appearance. * - url_callback: mixed (optional) * A function ($themes, $themeKey, $cssExt, $cssFile) which returns the URL(s) for a CSS resource. * Returns either an array of URLs or PASSTHRU. * Ex: \Civi\Core\Themes\Resolvers::simple (default) * Ex: \Civi\Core\Themes\Resolvers::none * - prefix: string (optional) * A prefix within the extension folder to prepend to the file name. * - search_order: array (optional) * A list of themes to search. * Generally, the last theme should be "*fallback*" (Civi\Core\Themes::FALLBACK). * - excludes: array (optional) * A list of files (eg "civicrm:css/bootstrap.css" or "$ext:$file") which should never * be returned (they are excluded from display). * * @param array $themes * List of themes, keyed by name. * @return null * the return value is ignored */ public static function themes(&$themes) { return self::singleton()->invoke(1, $themes, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_themes' ); } /** * The activeTheme hook determines which theme is active. * * @param string $theme * The identifier for the theme. Alterable. * Ex: 'greenwich'. * @param array $context * Information about the current page-request. Includes some mix of: * - page: the relative path of the current Civi page (Ex: 'civicrm/dashboard'). * - themes: an instance of the Civi\Core\Themes service. * @return null * the return value is ignored */ public static function activeTheme(&$theme, $context) { return self::singleton()->invoke(array('theme', 'context'), $theme, $context, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_activeTheme' ); } /** * This hook is called for declaring managed entities via API. * * @param array $entities * List of pending entities. Each entity is an array with keys: * + 'module': string; for module-extensions, this is the fully-qualifed name (e.g. "com.example.mymodule"); for CMS modules, the name is prefixed by the CMS (e.g. "drupal.mymodule") * + 'name': string, a symbolic name which can be used to track this entity (Note: Each module creates its own namespace) * + 'entity': string, an entity-type supported by the CiviCRM API (Note: this currently must be an entity which supports the 'is_active' property) * + 'params': array, the entity data as supported by the CiviCRM API * + 'update' (v4.5+): string, a policy which describes when to update records * - 'always' (default): always update the managed-entity record; changes in $entities will override any local changes (eg by the site-admin) * - 'never': never update the managed-entity record; changes made locally (eg by the site-admin) will override changes in $entities * + 'cleanup' (v4.5+): string, a policy which describes whether to cleanup the record when it becomes orphaned (ie when $entities no longer references the record) * - 'always' (default): always delete orphaned records * - 'never': never delete orphaned records * - 'unused': only delete orphaned records if there are no other references to it in the DB. (This is determined by calling the API's "getrefcount" action.) * * @return null * the return value is ignored */ public static function managed(&$entities) { return self::singleton()->invoke(['entities'], $entities, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_managed' ); } /** * This hook is called when rendering the dashboard (q=civicrm/dashboard) * * @param int $contactID * The contactID for whom the dashboard is being rendered. * @param int $contentPlacement * (output parameter) where should the hook content be displayed. * relative to the activity list * * @return string * the html snippet to include in the dashboard */ public static function dashboard($contactID, &$contentPlacement = self::DASHBOARD_BELOW) { $retval = self::singleton()->invoke(['contactID', 'contentPlacement'], $contactID, $contentPlacement, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_dashboard' ); /* * Note we need this seemingly unnecessary code because in the event that the implementation * of the hook declares the second parameter but doesn't set it, then it comes back unset even * though we have a default value in this function's declaration above. */ if (!isset($contentPlacement)) { $contentPlacement = self::DASHBOARD_BELOW; } return $retval; } /** * This hook is called before storing recently viewed items. * * @param array $recentArray * An array of recently viewed or processed items, for in place modification. * * @return array */ public static function recent(&$recentArray) { return self::singleton()->invoke(['recentArray'], $recentArray, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_recent' ); } /** * Determine how many other records refer to a given record. * * @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: * - 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 * * @return mixed * Return is not really intended to be used. */ public static function referenceCounts($dao, &$refCounts) { return self::singleton()->invoke(['dao', 'refCounts'], $dao, $refCounts, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_referenceCounts' ); } /** * This hook is called when building the amount structure for a Contribution or Event Page. * * @param int $pageType * Is this a contribution or event page. * @param CRM_Core_Form $form * Reference to the form object. * @param array $amount * The amount structure to be displayed. * * @return null */ public static function buildAmount($pageType, &$form, &$amount) { return self::singleton()->invoke(['pageType', 'form', 'amount'], $pageType, $form, $amount, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_buildAmount'); } /** * This hook is called when building the state list for a particular country. * * @param array $countryID * The country id whose states are being selected. * @param $states * * @return null */ public static function buildStateProvinceForCountry($countryID, &$states) { return self::singleton()->invoke(['countryID', 'states'], $countryID, $states, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_buildStateProvinceForCountry' ); } /** * This hook is called when rendering the tabs for a contact (q=civicrm/contact/view)c * * @param array $tabs * The array of tabs that will be displayed. * @param int $contactID * The contactID for whom the dashboard is being rendered. * * @return null * @deprecated Use tabset() instead. */ public static function tabs(&$tabs, $contactID) { return self::singleton()->invoke(['tabs', 'contactID'], $tabs, $contactID, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_tabs' ); } /** * This hook is called when rendering the tabs used for events and potentially * contribution pages, etc. * * @param string $tabsetName * Name of the screen or visual element. * @param array $tabs * Tabs that will be displayed. * @param array $context * Extra data about the screen or context in which the tab is used. * * @return null */ public static function tabset($tabsetName, &$tabs, $context) { return self::singleton()->invoke(['tabsetName', 'tabs', 'context'], $tabsetName, $tabs, $context, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_tabset' ); } /** * This hook is called when sending an email / printing labels * * @param array $tokens * The list of tokens that can be used for the contact. * * @return null */ public static function tokens(&$tokens) { return self::singleton()->invoke(['tokens'], $tokens, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_tokens' ); } /** * This hook allows modification of the admin panels * * @param array $panels * Associated array of admin panels * * @return mixed */ public static function alterAdminPanel(&$panels) { return self::singleton()->invoke(array('panels'), $panels, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_alterAdminPanel' ); } /** * This hook is called when sending an email / printing labels to get the values for all the * tokens returned by the 'tokens' hook * * @param array $details * The array to store the token values indexed by contactIDs. * @param array $contactIDs * An array of contactIDs. * @param int $jobID * The jobID if this is associated with a CiviMail mailing. * @param array $tokens * The list of tokens associated with the content. * @param string $className * The top level className from where the hook is invoked. * * @return null */ public static function tokenValues( &$details, $contactIDs, $jobID = NULL, $tokens = [], $className = NULL ) { return self::singleton() ->invoke(['details', 'contactIDs', 'jobID', 'tokens', 'className'], $details, $contactIDs, $jobID, $tokens, $className, self::$_nullObject, 'civicrm_tokenValues'); } /** * This hook is called before a CiviCRM Page is rendered. You can use this hook to insert smarty variables * in a template * * @param object $page * The page that will be rendered. * * @return null */ public static function pageRun(&$page) { return self::singleton()->invoke(['page'], $page, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_pageRun' ); } /** * This hook is called after a copy of an object has been made. The current objects are * Event, Contribution Page and UFGroup * * @param string $objectName * Name of the object. * @param object $object * Reference to the copy. * * @return null */ public static function copy($objectName, &$object) { return self::singleton()->invoke(['objectName', 'object'], $objectName, $object, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_copy' ); } /** * This hook is called when a contact unsubscribes from a mailing. It allows modules * to override what the contacts are removed from. * * @param string $op * Ignored for now * @param int $mailingId * The id of the mailing to unsub from * @param int $contactId * The id of the contact who is unsubscribing * @param array|int $groups * Groups the contact will be removed from. * @param array|int $baseGroups * Base groups (used in smart mailings) the contact will be removed from. * * * @return mixed */ public static function unsubscribeGroups($op, $mailingId, $contactId, &$groups, &$baseGroups) { return self::singleton() ->invoke(['op', 'mailingId', 'contactId', 'groups', 'baseGroups'], $op, $mailingId, $contactId, $groups, $baseGroups, self::$_nullObject, 'civicrm_unsubscribeGroups'); } /** * This hook is called when CiviCRM needs to edit/display a custom field with options * * @deprecated in favor of hook_civicrm_fieldOptions * * @param int $customFieldID * The custom field ID. * @param array $options * The current set of options for that custom field. * You can add/remove existing options. * Important: This array may contain meta-data about the field that is needed elsewhere, so it is important * to be careful to not overwrite the array. * Only add/edit/remove the specific field options you intend to affect. * @param bool $detailedFormat * If true, the options are in an ID => array ( 'id' => ID, 'label' => label, 'value' => value ) format * @param array $selectAttributes * Contain select attribute(s) if any. * * @return mixed */ public static function customFieldOptions($customFieldID, &$options, $detailedFormat = FALSE, $selectAttributes = []) { // Weird: $selectAttributes is inputted but not outputted. return self::singleton()->invoke(['customFieldID', 'options', 'detailedFormat'], $customFieldID, $options, $detailedFormat, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_customFieldOptions' ); } /** * Hook for modifying field options * * @param string $entity * @param string $field * @param array $options * @param array $params * * @return mixed */ public static function fieldOptions($entity, $field, &$options, $params) { return self::singleton()->invoke(['entity', 'field', 'options', 'params'], $entity, $field, $options, $params, self::$_nullObject, self::$_nullObject, 'civicrm_fieldOptions' ); } /** * * This hook is called to display the list of actions allowed after doing a search. * This allows the module developer to inject additional actions or to remove existing actions. * * @param string $objectType * The object type for this search. * - activity, campaign, case, contact, contribution, event, grant, membership, and pledge are supported. * @param array $tasks * The current set of tasks for that custom field. * You can add/remove existing tasks. * Each task needs to have a title (eg 'title' => ts( 'Group - add contacts')) and a class * (eg 'class' => 'CRM_Contact_Form_Task_AddToGroup'). * Optional result (boolean) may also be provided. Class can be an array of classes (not sure what that does :( ). * The key for new Task(s) should not conflict with the keys for core tasks of that $objectType, which can be * found in CRM/$objectType/Task.php. * * @return mixed */ public static function searchTasks($objectType, &$tasks) { return self::singleton()->invoke(['objectType', 'tasks'], $objectType, $tasks, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_searchTasks' ); } /** * @param mixed $form * @param array $params * * @return mixed */ public static function eventDiscount(&$form, &$params) { return self::singleton()->invoke(['form', 'params'], $form, $params, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_eventDiscount' ); } /** * This hook is called when composing a mailing. You can include / exclude other groups as needed. * * @param mixed $form * The form object for which groups / mailings being displayed * @param array $groups * The list of groups being included / excluded * @param array $mailings * The list of mailings being included / excluded * * @return mixed */ public static function mailingGroups(&$form, &$groups, &$mailings) { return self::singleton()->invoke(['form', 'groups', 'mailings'], $form, $groups, $mailings, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_mailingGroups' ); } /** * (Experimental) Modify the list of template-types used for CiviMail composition. * * @param array $types * Sequentially indexed list of template types. Each type specifies: * - name: string * - editorUrl: string, Angular template URL * - weight: int, priority when picking a default value for new mailings * @return mixed */ public static function mailingTemplateTypes(&$types) { return self::singleton()->invoke(['types'], $types, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_mailingTemplateTypes' ); } /** * This hook is called when composing the array of membershipTypes and their cost during a membership registration * (new or renewal). * Note the hook is called on initial page load and also reloaded after submit (PRG pattern). * You can use it to alter the membership types when first loaded, or after submission * (for example if you want to gather data in the form and use it to alter the fees). * * @param mixed $form * The form object that is presenting the page * @param array $membershipTypes * The array of membership types and their amount * * @return mixed */ public static function membershipTypeValues(&$form, &$membershipTypes) { return self::singleton()->invoke(['form', 'membershipTypes'], $form, $membershipTypes, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_membershipTypeValues' ); } /** * This hook is called when rendering the contact summary. * * @param int $contactID * The contactID for whom the summary is being rendered * @param mixed $content * @param int $contentPlacement * Specifies where the hook content should be displayed relative to the * existing content * * @return string * The html snippet to include in the contact summary */ public static function summary($contactID, &$content, &$contentPlacement = self::SUMMARY_BELOW) { return self::singleton()->invoke(['contactID', 'content', 'contentPlacement'], $contactID, $content, $contentPlacement, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_summary' ); } /** * Use this hook to populate the list of contacts returned by Contact Reference custom fields. * By default, Contact Reference fields will search on and return all CiviCRM contacts. * If you want to limit the contacts returned to a specific group, or some other criteria * - you can override that behavior by providing a SQL query that returns some subset of your contacts. * The hook is called when the query is executed to get the list of contacts to display. * * @param mixed $query * - the query that will be executed (input and output parameter);. * It's important to realize that the ACL clause is built prior to this hook being fired, * so your query will ignore any ACL rules that may be defined. * Your query must return two columns: * the contact 'data' to display in the autocomplete dropdown (usually contact.sort_name - aliased as 'data') * the contact IDs * @param string $queryText * The name string to execute the query against (this is the value being typed in by the user). * @param string $context * The context in which this ajax call is being made (for example: 'customfield', 'caseview'). * @param int $id * The id of the object for which the call is being made. * For custom fields, it will be the custom field id * * @return mixed */ public static function contactListQuery(&$query, $queryText, $context, $id) { return self::singleton()->invoke(['query', 'queryText', 'context', 'id'], $query, $queryText, $context, $id, self::$_nullObject, self::$_nullObject, 'civicrm_contactListQuery' ); } /** * Hook definition for altering payment parameters before talking to a payment processor back end. * * Definition will look like this: * * function hook_civicrm_alterPaymentProcessorParams( * $paymentObj, * &$rawParams, * &$cookedParams * ); * * @param CRM_Core_Payment $paymentObj * Instance of payment class of the payment processor invoked (e.g., 'CRM_Core_Payment_Dummy') * See discussion in CRM-16224 as to whether $paymentObj should be passed by reference. * @param array &$rawParams * array of params as passed to to the processor * @param array &$cookedParams * params after the processor code has translated them into its own key/value pairs * * @return mixed * This return is not really intended to be used. */ public static function alterPaymentProcessorParams( $paymentObj, &$rawParams, &$cookedParams ) { return self::singleton()->invoke(['paymentObj', 'rawParams', 'cookedParams'], $paymentObj, $rawParams, $cookedParams, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_alterPaymentProcessorParams' ); } /** * This hook is called when an email is about to be sent by CiviCRM. * * @param array $params * Array fields include: groupName, from, toName, toEmail, subject, cc, bcc, text, html, * returnPath, replyTo, headers, attachments (array) * @param string $context * The context in which the hook is being invoked, eg 'civimail'. * * @return mixed */ public static function alterMailParams(&$params, $context = NULL) { return self::singleton()->invoke(['params', 'context'], $params, $context, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_alterMailParams' ); } /** * This hook is called when membership status is being calculated. * * @param array $membershipStatus * Membership status details as determined - alter if required. * @param array $arguments * Arguments passed in to calculate date. * - 'start_date' * - 'end_date' * - 'status_date' * - 'join_date' * - 'exclude_is_admin' * - 'membership_type_id' * @param array $membership * Membership details from the calling function. * * @return mixed */ public static function alterCalculatedMembershipStatus(&$membershipStatus, $arguments, $membership) { return self::singleton()->invoke(['membershipStatus', 'arguments', 'membership'], $membershipStatus, $arguments, $membership, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_alterCalculatedMembershipStatus' ); } /** * This hook is called after getting the content of the mail and before tokenizing it. * * @param array $content * Array fields include: html, text, subject * * @return mixed */ public static function alterMailContent(&$content) { return self::singleton()->invoke(['content'], $content, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_alterMailContent' ); } /** * This hook is called when rendering the Manage Case screen. * * @param int $caseID * The case ID. * * @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(['caseID'], $caseID, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_caseSummary' ); } /** * This hook is called when locating CiviCase types. * * @param array $caseTypes * * @return mixed */ public static function caseTypes(&$caseTypes) { return self::singleton() ->invoke(['caseTypes'], $caseTypes, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_caseTypes'); } /** * This hook is called soon after the CRM_Core_Config object has ben initialized. * You can use this hook to modify the config object and hence behavior of CiviCRM dynamically. * * @param CRM_Core_Config|array $config * The config object * * @return mixed */ public static function config(&$config) { return self::singleton()->invoke(['config'], $config, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_config' ); } /** * This hooks allows to change option values. * * @deprecated in favor of hook_civicrm_fieldOptions * * @param array $options * Associated array of option values / id * @param string $groupName * Option group name * * @return mixed */ public static function optionValues(&$options, $groupName) { return self::singleton()->invoke(['options', 'groupName'], $options, $groupName, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_optionValues' ); } /** * This hook allows modification of the navigation menu. * * @param array $params * Associated array of navigation menu entry to Modify/Add * * @return mixed */ public static function navigationMenu(&$params) { return self::singleton()->invoke(['params'], $params, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_navigationMenu' ); } /** * This hook allows modification of the data used to perform merging of duplicates. * * @param string $type * The type of data being passed (cidRefs|eidRefs|relTables|sqls). * @param array $data * The data, as described in $type. * @param int $mainId * Contact_id of the contact that survives the merge. * @param int $otherId * Contact_id of the contact that will be absorbed and deleted. * @param array $tables * When $type is "sqls", an array of tables as it may have been handed to the calling function. * * @return mixed */ public static function merge($type, &$data, $mainId = NULL, $otherId = NULL, $tables = NULL) { return self::singleton()->invoke(['type', 'data', 'mainId', 'otherId', 'tables'], $type, $data, $mainId, $otherId, $tables, self::$_nullObject, 'civicrm_merge'); } /** * This hook allows modification of the data calculated for merging locations. * * @param array $blocksDAO * Array of location DAO to be saved. These are arrays in 2 keys 'update' & 'delete'. * @param int $mainId * Contact_id of the contact that survives the merge. * @param int $otherId * Contact_id of the contact that will be absorbed and deleted. * @param array $migrationInfo * Calculated migration info, informational only. * * @return mixed */ public static function alterLocationMergeData(&$blocksDAO, $mainId, $otherId, $migrationInfo) { return self::singleton()->invoke(['blocksDAO', 'mainId', 'otherId', 'migrationInfo'], $blocksDAO, $mainId, $otherId, $migrationInfo, self::$_nullObject, self::$_nullObject, 'civicrm_alterLocationMergeData'); } /** * This hook provides a way to override the default privacy behavior for notes. * * @param array &$noteValues * Associative array of values for this note * * @return mixed */ public static function notePrivacy(&$noteValues) { return self::singleton()->invoke(['noteValues'], $noteValues, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_notePrivacy' ); } /** * This hook is called before record is exported as CSV. * * @param string $exportTempTable * Name of the temporary export table used during export. * @param array $headerRows * Header rows for output. * @param array $sqlColumns * SQL columns. * @param int $exportMode * Export mode ( contact, contribution, etc...). * @param string $componentTable * Name of temporary table * @param array $ids * Array of object's ids * * @return mixed */ public static function export(&$exportTempTable, &$headerRows, &$sqlColumns, $exportMode, $componentTable, $ids) { return self::singleton()->invoke(['exportTempTable', 'headerRows', 'sqlColumns', 'exportMode', 'componentTable', 'ids'], $exportTempTable, $headerRows, $sqlColumns, $exportMode, $componentTable, $ids, 'civicrm_export' ); } /** * This hook allows modification of the queries constructed from dupe rules. * * @param string $obj * Object of rulegroup class. * @param string $type * Type of queries e.g table / threshold. * @param array $query * Set of queries. * * @return mixed */ public static function dupeQuery($obj, $type, &$query) { return self::singleton()->invoke(['obj', 'type', 'query'], $obj, $type, $query, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_dupeQuery' ); } /** * Check for duplicate contacts * * @param array $dedupeParams * Array of params for finding duplicates: [ * '{parameters returned by CRM_Dedupe_Finder::formatParams} * 'check_permission' => TRUE/FALSE; * 'contact_type' => $contactType; * 'rule' = $rule; * 'rule_group_id' => $ruleGroupID; * 'excludedContactIDs' => $excludedContactIDs; * @param array $dedupeResults * Array of results ['handled' => TRUE/FALSE, 'ids' => array of IDs of duplicate contacts] * @param array $contextParams * The context if relevant, eg. ['event_id' => X] * * @return mixed */ public static function findDuplicates($dedupeParams, &$dedupeResults, $contextParams) { return self::singleton() ->invoke(['dedupeParams', 'dedupeResults', 'contextParams'], $dedupeParams, $dedupeResults, $contextParams, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_findDuplicates'); } /** * This hook is called AFTER EACH email has been processed by the script bin/EmailProcessor.php * * @param string $type * Type of mail processed: 'activity' OR 'mailing'. * @param array &$params the params that were sent to the CiviCRM API function * @param object $mail * The mail object which is an ezcMail class. * @param array &$result the result returned by the api call * @param string $action * (optional ) the requested action to be performed if the types was 'mailing'. * * @return mixed */ public static function emailProcessor($type, &$params, $mail, &$result, $action = NULL) { return self::singleton() ->invoke(['type', 'params', 'mail', 'result', 'action'], $type, $params, $mail, $result, $action, self::$_nullObject, 'civicrm_emailProcessor'); } /** * This hook is called after a row has been processed and the * record (and associated records imported * * @param string $object * Object being imported (for now Contact only, later Contribution, Activity,. * Participant and Member) * @param string $usage * Hook usage/location (for now process only, later mapping and others). * @param string $objectRef * Import record object. * @param array $params * Array with various key values: currently. * contactID - contact id * importID - row id in temp table * importTempTable - name of tempTable * fieldHeaders - field headers * fields - import fields * * @return mixed */ public static function import($object, $usage, &$objectRef, &$params) { return self::singleton()->invoke(['object', 'usage', 'objectRef', 'params'], $object, $usage, $objectRef, $params, self::$_nullObject, self::$_nullObject, 'civicrm_import' ); } /** * This hook is called when API permissions are checked (cf. civicrm_api3_api_check_permission() * in api/v3/utils.php and _civicrm_api3_permissions() in CRM/Core/DAO/permissions.php). * * @param string $entity * The API entity (like contact). * @param string $action * The API action (like get). * @param array &$params the API parameters * @param array &$permissions the associative permissions array (probably to be altered by this hook) * * @return mixed */ public static function alterAPIPermissions($entity, $action, &$params, &$permissions) { return self::singleton()->invoke(['entity', 'action', 'params', 'permissions'], $entity, $action, $params, $permissions, self::$_nullObject, self::$_nullObject, 'civicrm_alterAPIPermissions' ); } /** * @param CRM_Core_DAO $dao * * @return mixed */ public static function postSave(&$dao) { $hookName = 'civicrm_postSave_' . $dao->getTableName(); return self::singleton()->invoke(['dao'], $dao, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, $hookName ); } /** * This hook allows user to customize context menu Actions on contact summary page. * * @param array $actions * Array of all Actions in contextmenu. * @param int $contactID * ContactID for the summary page. * * @return mixed */ public static function summaryActions(&$actions, $contactID = NULL) { return self::singleton()->invoke(['actions', 'contactID'], $actions, $contactID, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_summaryActions' ); } /** * This hook is called from CRM_Core_Selector_Controller through which all searches in civicrm go. * This enables us hook implementors to modify both the headers and the rows * * The BIGGEST drawback with this hook is that you may need to modify the result template to include your * fields. The result files are CRM/{Contact,Contribute,Member,Event...}/Form/Selector.tpl * * However, if you use the same number of columns, you can overwrite the existing columns with the values that * you want displayed. This is a hackish, but avoids template modification. * * @param string $objectName * The component name that we are doing the search. * 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 array $selector * the selector object. Allows you access to the context of the search * * @return mixed * modify the header and values object to pass the data you need */ public static function searchColumns($objectName, &$headers, &$rows, &$selector) { return self::singleton()->invoke(['objectName', 'headers', 'rows', 'selector'], $objectName, $headers, $rows, $selector, self::$_nullObject, self::$_nullObject, 'civicrm_searchColumns' ); } /** * This hook is called when uf groups are being built for a module. * * @param string $moduleName * Module name. * @param array $ufGroups * Array of ufgroups for a module. * * @return null */ public static function buildUFGroupsForModule($moduleName, &$ufGroups) { return self::singleton()->invoke(['moduleName', 'ufGroups'], $moduleName, $ufGroups, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_buildUFGroupsForModule' ); } /** * This hook is called when we are determining the contactID for a specific * email address * * @param string $email * The email address. * @param int $contactID * The contactID that matches this email address, IF it exists. * @param array $result * (reference) has two fields. * contactID - the new (or same) contactID * action - 3 possible values: * CRM_Utils_Mail_Incoming::EMAILPROCESSOR_CREATE_INDIVIDUAL - create a new contact record * CRM_Utils_Mail_Incoming::EMAILPROCESSOR_OVERRIDE - use the new contactID * CRM_Utils_Mail_Incoming::EMAILPROCESSOR_IGNORE - skip this email address * * @return null */ public static function emailProcessorContact($email, $contactID, &$result) { return self::singleton()->invoke(['email', 'contactID', 'result'], $email, $contactID, $result, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_emailProcessorContact' ); } /** * Hook definition for altering the generation of Mailing Labels. * * @param array $args * An array of the args in the order defined for the tcpdf multiCell api call. * with the variable names below converted into string keys (ie $w become 'w' * as the first key for $args) * float $w Width of cells. If 0, they extend up to the right margin of the page. * float $h Cell minimum height. The cell extends automatically if needed. * string $txt String to print * mixed $border Indicates if borders must be drawn around the cell block. The value can * be either a number: