// by default - place content below existing content
const SUMMARY_BELOW = 1;
- // pace hook content above
+ // place hook content above
const SUMMARY_ABOVE = 2;
- // create your own summarys
+ // create your own summaries
const SUMMARY_REPLACE = 3;
static $_nullObject = NULL;
*/
private $commonCiviModules = array();
+ /**
+ * @var CRM_Utils_Cache_Interface
+ */
+ protected $cache;
+
/**
* Constructor and getter for the singleton instance.
*
return self::$_singleton;
}
+ public function __construct() {
+ $this->cache = CRM_Utils_Cache::create(array(
+ 'name' => 'hooks',
+ 'type' => array('ArrayCache'),
+ 'prefetch' => 1,
+ ));
+ }
+
/**
* Invoke hooks.
*
// to reproduce the issue are pretty intricate.
$result = array();
- if ($civiModules !== NULL) {
- foreach ($civiModules as $module) {
- $fnName = "{$module}_{$fnSuffix}";
- if (function_exists($fnName)) {
- $fResult = array();
- 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:
- CRM_Core_Error::fatal(ts('Invalid hook invocation'));
- break;
- }
-
- if (!empty($fResult) &&
- is_array($fResult)
- ) {
- $result = array_merge($result, $fResult);
+ $fnNames = $this->cache->get($fnSuffix);
+ if (!is_array($fnNames)) {
+ $fnNames = array();
+ 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 = array();
+ 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:
+ CRM_Core_Error::fatal(ts('Invalid hook invocation'));
+ break;
+ }
+
+ if (!empty($fResult) &&
+ is_array($fResult)
+ ) {
+ $result = array_merge($result, $fResult);
}
}
* the selector object. Allows you access to the context of the search
*
* @return mixed
- * modify the header and values object to pass the data u need
+ * modify the header and values object to pass the data you need
*/
public static function searchColumns($objectName, &$headers, &$rows, &$selector) {
return self::singleton()->invoke(4, $objectName, $headers, $rows, $selector,
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;
- //CRM_Core_LegacyErrorHandler::handleException($event);
+ // $event = new stdClass();
+ // $event->exception = $exception;
+ // CRM_Core_LegacyErrorHandler::handleException($event);
// == 4.5+ ==
$event = new \Civi\Core\Event\UnhandledExceptionEvent($exception, self::$_nullObject);
);
}
+ /**
+ * Modify the CiviCRM container - add new services, parameters, extensions, etc.
+ *
+ * @code
+ * use Symfony\Component\Config\Resource\FileResource;
+ * use Symfony\Component\DependencyInjection\Definition;
+ *
+ * function mymodule_civicrm_container($container) {
+ * $container->addResource(new FileResource(__FILE__));
+ * $container->setDefinition('mysvc', new Definition('My\Class', array()));
+ * }
+ * @endcode
+ *
+ * Tip: The container configuration will be compiled/cached. The default cache
+ * behavior is aggressive. When you first implement the hook, be sure to
+ * flush the cache. Additionally, you should relax caching during development.
+ * In `civicrm.settings.php`, set define('CIVICRM_CONTAINER_CACHE', 'auto').
+ *
+ * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
+ * @see http://symfony.com/doc/current/components/dependency_injection/index.html
+ */
+ public static function container(\Symfony\Component\DependencyInjection\ContainerBuilder $container) {
+ self::singleton()->invoke(1, $container, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_container');
+ }
+
/**
* @param array <CRM_Core_FileSearchInterface> $fileSearches
* @return mixed
/**
* This hook is called when a query string of the CSV Batch export is generated.
+ *
+ * @param string $query
+ *
+ * @return mixed
*/
public static function batchQuery(&$query) {
return self::singleton()->invoke(1, $query, self::$_nullObject,
/**
* This hook is called when the entries of the CSV Batch export are mapped.
+ *
+ * @param array $results
+ * @param array $items
+ *
+ * @return mixed
*/
public static function batchItems(&$results, &$items) {
return self::singleton()->invoke(2, $results, $items,