3 require_once 'afform.civix.php';
4 use CRM_Afform_ExtensionUtil
as E
;
6 function _afform_fields() {
7 return ['name', 'title', 'description', 'requires', 'layout', 'server_route', 'client_route'];
11 * Filter the content of $params to only have supported afform fields.
13 * @param array $params
16 function _afform_fields_filter($params) {
18 foreach (_afform_fields() as $field) {
19 if (isset($params[$field])) {
20 $result[$field] = $params[$field];
27 * Implements hook_civicrm_config().
29 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_config
31 function afform_civicrm_config(&$config) {
32 _afform_civix_civicrm_config($config);
36 * Implements hook_civicrm_xmlMenu().
38 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_xmlMenu
40 function afform_civicrm_xmlMenu(&$files) {
41 _afform_civix_civicrm_xmlMenu($files);
45 * Implements hook_civicrm_install().
47 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install
49 function afform_civicrm_install() {
50 _afform_civix_civicrm_install();
54 * Implements hook_civicrm_postInstall().
56 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_postInstall
58 function afform_civicrm_postInstall() {
59 _afform_civix_civicrm_postInstall();
63 * Implements hook_civicrm_uninstall().
65 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_uninstall
67 function afform_civicrm_uninstall() {
68 _afform_civix_civicrm_uninstall();
72 * Implements hook_civicrm_enable().
74 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_enable
76 function afform_civicrm_enable() {
77 _afform_civix_civicrm_enable();
81 * Implements hook_civicrm_disable().
83 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_disable
85 function afform_civicrm_disable() {
86 _afform_civix_civicrm_disable();
90 * Implements hook_civicrm_upgrade().
92 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_upgrade
94 function afform_civicrm_upgrade($op, CRM_Queue_Queue
$queue = NULL) {
95 return _afform_civix_civicrm_upgrade($op, $queue);
99 * Implements hook_civicrm_managed().
101 * Generate a list of entities to create/deactivate/delete when this module
102 * is installed, disabled, uninstalled.
104 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_managed
106 function afform_civicrm_managed(&$entities) {
107 _afform_civix_civicrm_managed($entities);
111 * Implements hook_civicrm_caseTypes().
113 * Generate a list of case-types.
115 * Note: This hook only runs in CiviCRM 4.4+.
117 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_caseTypes
119 function afform_civicrm_caseTypes(&$caseTypes) {
120 _afform_civix_civicrm_caseTypes($caseTypes);
124 * Implements hook_civicrm_angularModules().
126 * Generate a list of Angular modules.
128 * Note: This hook only runs in CiviCRM 4.5+. It may
129 * use features only available in v4.6+.
131 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_angularModules
133 function afform_civicrm_angularModules(&$angularModules) {
134 _afform_civix_civicrm_angularModules($angularModules);
136 $scanner = new CRM_Afform_AfformScanner();
137 $names = array_keys($scanner->findFilePaths());
138 foreach ($names as $name) {
139 $meta = $scanner->getMeta($name);
140 $angularModules[_afform_angular_module_name($name)] = [
141 'ext' => E
::LONG_NAME
,
142 'js' => ['assetBuilder://afform.js?name=' . urlencode($name)],
143 'requires' => $meta['requires'],
147 // FIXME: The HTML layout template is embedded in the JS asset.
148 // This works at runtime for basic usage, but it bypasses
149 // the hook_alterAngular infrastructure, and I'm not sure translation works.
150 // We should update core so that 'partials' can be specified more dynamically.
155 * Implements hook_civicrm_alterSettingsFolders().
157 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_alterSettingsFolders
159 function afform_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
160 _afform_civix_civicrm_alterSettingsFolders($metaDataFolders);
164 * Implements hook_civicrm_entityTypes().
166 * Declare entity types provided by this module.
168 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_entityTypes
170 function afform_civicrm_entityTypes(&$entityTypes) {
171 _afform_civix_civicrm_entityTypes($entityTypes);
174 // --- Functions below this ship commented out. Uncomment as required. ---
177 * Implements hook_civicrm_buildAsset().
179 function afform_civicrm_buildAsset($asset, $params, &$mimeType, &$content) {
180 if ($asset !== 'afform.js') {
184 if (empty($params['name'])) {
185 throw new RuntimeException("Missing required parameter: afform.js?name=NAME");
188 $name = $params['name'];
189 $meta = civicrm_api3('Afform', 'getsingle', ['name' => $name]);
190 $scanner = new CRM_Afform_AfformScanner();
192 $smarty = CRM_Core_Smarty
::singleton();
193 $smarty->assign('afform', [
194 'camel' => _afform_angular_module_name($name),
196 'layout' => file_get_contents($scanner->findFilePath($name, 'layout.html'))
198 $mimeType = 'text/javascript';
199 $content = $smarty->fetch('afform/FormAsDirective.tpl');
203 * Implements hook_civicrm_alterMenu().
205 function afform_civicrm_alterMenu(&$items) {
206 $scanner = new CRM_Afform_AfformScanner();
207 foreach ($scanner->getMetas() as $name => $meta) {
208 if (!empty($meta['server_route'])) {
209 $items[$meta['server_route']] = [
210 'page_callback' => 'CRM_Afform_Page_AfformBase',
211 'page_arguments' => 'afform=' . urlencode($name),
212 'title' => CRM_Utils_Array
::value('title', $meta, ''),
213 'access_arguments' => [['access CiviCRM'], 'and'] // FIXME
220 * @param string $name
222 * @param string $format
225 * Ex: 'FooBar' or 'foo-bar'.
227 function _afform_angular_module_name($name, $format = 'camel') {
230 return 'afform' . strtoupper($name{0}) . substr($name, 1);
233 $camel = _afform_angular_module_name($name, 'camel');
234 return strtolower(implode('-', array_filter(preg_split('/(?=[A-Z])/', $camel))));
237 throw new \
Exception("Unrecognized format");
242 * Implements hook_civicrm_preProcess().
244 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_preProcess
246 function afform_civicrm_preProcess($formName, &$form) {
251 * Implements hook_civicrm_navigationMenu().
253 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_navigationMenu
255 function afform_civicrm_navigationMenu(&$menu) {
256 _afform_civix_insert_navigation_menu($menu, 'Mailings', array(
257 'label' => E::ts('New subliminal message'),
258 'name' => 'mailing_subliminal_message',
259 'url' => 'civicrm/mailing/subliminal',
260 'permission' => 'access CiviMail',
264 _afform_civix_navigationMenu($menu);