Skip to content

hook_civicrm_angularModules

Summary

This hook generates a list of AngularJS modules and allows you to register additional AngularJS modules.

Extensions generated with civix implement this hook by default to automatically scan the extension's ang directory for files ending in .ang.php.

Availability

Hook added in CiviCRM 4.5+. Some features only available in CiviCRM 5.32+.

Definition

hook_civicrm_angularModules(&$angularModules)

Parameters

  • &$angularModules - an array containing a list of all Angular modules. The key for each item is the name of the module. The value for each item is an array with the following key/value pairs:

    • 'ext' =>(string) - The name of the CiviCRM extension which has the source-code.
    • 'js' =>(array) - List of Javascript files. May use the wildcard (*). Relative to the extension.
    • 'css' =>(array) - List of CSS files. May use the wildcard (*). Relative to the extension.
    • 'partials' =>(array) - List of HTML folders. Relative to the extension.
    • 'settings' => (array) - DEPRECATED Runtime data to export from PHP to JS.
    • 'settingsFactory' =>(callable) - Callback function to supply runtime data to export from PHP to JS.
      • Returned values are mapped to the JS global (Ex: returning ["foo"=>"bar"] from the callback would be available as CRM.myModule.foo.
      • CiviCRM 5.32+
    • 'permissions' =>(array) - List of permissions to be exported to the client-side.
      • Permission data to be made available to the javascript CRM.checkPerm() function, to make JS UIs degrade gracefully for less-permissioned users.
      • Default: [].
    • 'requires' =>(array) - List of AngularJS modules required by this module.
      • Default: [].
      • CiviCRM 4.7.21+
    • 'basePages' =>(array) - Unconditionally load this module onto the given Angular pages.
      • If omitted, the default is ['civicrm/a']. This provides backward compatibility with behavior since v4.6+.
      • For a utility that should only be loaded on-demand, use [].
      • For a utility that should be loaded in all pages use, [*].
      • CiviCRM 4.7.21+

Returns

  • null

Example

function mymod_civicrm_angularModules(&$angularModules) {
  $angularModules['myAngularModule'] = [
    'ext' => 'org.example.mymod',
    'js' => ['js/myAngularModule.js'],
  ];
  $angularModules['myBigAngularModule'] = [
    'ext' => 'org.example.mymod',
    'requires' => ['ngRoute', 'crmUi', 'myAngularModule'],
    'basePages' => ['civicrm/a'],
    'js' => ['ang/myBigAngularModule.js', 'ang/myBigAngularModule/*.js'],
    'css' => ['css/myAngularModule.css'],
    'partials' => ['partials/myBigAngularModule'],
    'permissions' => ['administer CiviCRM'],
    'settingsCallback' => ['\Civi\Example\Utils', 'getBigAngularData'],
  ];
}